ABAP Keyword Documentation → ABAP - Reference → Assignments → Assignment Rules → Conversion Rules for Elementary Data Objects → Character-Like Source Fields
Source Field Type c
Other versions: 7.31 | 7.40 | 7.54
Numeric Target Fields
Target | Conversion |
---|---|
i , (b , s ) |
The source field must contain a number in mathematical or commercial notation. Exception: A sourcefield that contains only blank characters is interpreted as the number zero. Scientific notation is not allowed, unless it can be interpreted as a mathematical notation.Decimal places are rounded to whole-number values. If the number is in the value range of data types i ,(b , s ), it is converted to the corresponding internalrepresentation of an integral number, otherwise the handleable exception CX_SY_CONVERSION_OVERFLOW is raised. |
p |
The source field must contain a number in mathematical or commercial notation. Exception: A sourcefield that contains only blank characters is interpreted as the number zero. Scientific notation isnot allowed, unless it can be interpreted as a mathematical notation. Decimal places are rounded tothe number of decimal places in the target field. If the number is in the value range of the data typeof the target field, it is converted to the internal representation of a packed number, otherwise the handleable exception CX_SY_CONVERSION_OVERFLOW is raised. |
decfloat16 , decfloat34 |
The source field must contain a number in mathematical,scientific, orcommercial notation.Exception: A source field that contains only blank characters is interpreted as the number zero. Ifthe number of digits is greater than 16 or 34, it is rounded to 16 or 34 places. If the absolute valueof the number is less than 1E-398 or 1E-6176, it is rounded to 0. If the number is in the value rangeof the data types decfloat16 or decfloat34 , itis converted to the internal representation of a decimal floating point number, otherwise the handleable exception CX_SY_CONVERSION_OVERFLOW is raised. If the mantissa of the target field is long enough, thescaling of the source field is preserved. The sign is always preserved, even if the number has the value 0. |
f |
The source field must contain a number in scientific notation, with the first blank after a number ending this number. Exception: A source field that contains only blanks or that starts with blanks not followed by a valid number is interpreted as zero.Mathematical orcommercial notationis not permitted unless it can be interpreted as scientific notation. Exception: Commercial notationwhere the sign on the right is not separated by blanks is valid if the character string starts directly with the digits. If the mantissa contains more than 17 digits, surplus digits are rounded up or down. If the number is in thevalue range of data typef , it is converted to the internal representation of a binary floating pointnumber, otherwise the handleable exception CX_SY_CONVERSION_OVERFLOW is raised. If the decimal number cannot be represented as a binary floating point number, the nearest value is used. |
Note
- The CL_ABAP_DECFLOAT class contains the methods READ_DECFLOAT34 and READ_DECFLOAT16, to convert character strings into floating point numbers. The exceptions of these methods are more significant than those of a normal assignment. Furthermore, the methods return a return value that reveals information about the roundings carried out.
Character-Like Target Fields
Target | Conversion |
---|---|
c |
The characters in the source field are inserted in the target field, left-aligned. Trailing spacesin the source field are not passed. If the target field is longer than the number of characters passed,it is filled with blank characters to the right. If the target field is shorter, it is truncated from the right. |
string |
The characters in the source field are inserted in the target field, left-aligned. Trailing spacesin the source field are not passed. The length of the target field is determined by the number of characters passed. |
n |
The characters in the source field that represent digits are inserted in the target field, right-aligned.Other characters are ignored. If the target field is longer than the number of digits in the sourcefield, it is filled to the left with the character "0". If the target field is shorter, the characters are cut off from the left. |
d |
The same conversion rules apply as to a field of type c of length 8.If the source field does not contain a valid date in the first eight characters, in the format "yyyymmdd", an invalid date is created in the target field. |
t |
The same conversion rules apply as to a field of type c with the length6, with the exception that trailing blanks are passed and if the target field is longer than the number of characters passed, the field is filled to the right with the "0" character. |
Notes
- In ABAP, the trailing blanks in source fields
of type
c
are ignored, by default. An assignment from source typec
to target typet
is an exception to this rule. To assign source fields of typec
to target fields (particularly target fields of typestring
) and respect the trailing blanks, you can use theRESPECTING BLANKS
addition of theCONCATENATE
statement.
- If you truncate on the right when assigning character strings containing non-Unicode double-byte characters, such a character can be split down the middle, which generally results in an invalid character at the right edge. To prevent this, you can use the method CL_SCP_LINEBREAK_UTIL=>STRING_SPLIT_AT_POSITION.
Byte-Type Target Fields
Target | Conversion |
---|---|
x |
The characters in the source field are interpreted as the representation of the value of a half-bytein hexadecimal representation. If the valid characters "0" to "9" and "A" to "F" appear, the correspondinghalf-byte value is passed to the memory of the target field, left-aligned. If the target field is longerthan the number of half-bytes passed, it is filled to the right with hexadecimal 0. If it is too short,the number is truncated to the right. The first invalid character terminates the conversion from the position of this character and the half-bytes not filled up to that point are filled with the hexadecimal 0. |
xstring |
The same conversion rules apply as to a field of type x . Half-bytes arepassed to the target field, and the length of the target field is determined by the number of validcharacters in the source field. If number of valid characters in the source field is odd, the last remaining half-byte in the target field is filled with the hexadecimal 0. |