Conversion Rules for Elementary Data Types 

There are ten predefined ABAP data types. There are 100 possible type combinations between these elementary data types. ABAP supports automatic type conversion and length adjustment for all of them except type D (date) and type T (time) fields which cannot be converted into each other.

The following conversion tables define the rules for converting elementary data types for all possible combinations of source and target fields.

C D F I N P STRING T X XSTRING

 

Source Type Character

Conversion table for source type C

Target

Conversion

C

The target field is filled from left to right. If it is too long, it is filled with blanks from the right. If it is too short, the contents are truncated from the right.

D

The character field must contain an 8-character date in the format YYYYMMDD .

F

The contents of the source field must be a valid representation of a type F field as described in Literals.

N

Only the digits in the source field are copied. The field is right-justified and filled with trailing zeros.

I, P

The source field must contain the representation of a decimal number, that is, a sequence of digits with an optional sign and no more than one decimal point. The source field can contain blanks. If the target field is too short, an overflow may occur. This may cause the system to terminate the program.

STRING

The occupied length of the source field is copied. All trailing spaces are truncated.

T

The character field must contain a six-character time in HHMMSS format.

X

Since the character field must contain a hexadecimal string, the only valid characters are 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. This string is packed as a hexadecimal number, transported left-justified, and filled with zeros or truncated on the right.

XSTRING

As for fields of type X, except that the target field is not filled with zeros.

 

Source Type Date

Conversion table for source type D

Target

Conversion

C

The date is transported left-justified without conversion.

D

Transport without conversion.

F

The date is converted into a packed number. The packed number is then converted into a floating point number (see corresponding table).

N

The date is transported left-justified without conversion and, if necessary, filled with zeros on the right.

I, P

The date is converted to the number of days since 01.01.0001.

STRING

The date is converted to a character field, which is then converted to a character string.

T

Not supported. Results in an error message during the syntax check or in a runtime error.

X

The date is converted to the number of days since 01.01.0001 in hexadecimal format.

XSTRING

As for fields of type X, except that only significant bytes are copied.

 

Source Type Floating Point Number

Conversion table for source type F

Target

Conversion

C

The floating point number is converted to the <mantissa>E<exponent> format and transported to the character field. The value of the mantissa lies between 1 and 10 unless the number is zero. The exponent is always signed. If the target field is too short, the mantissa is rounded. The length of the character field must be at least 6 bytes.

D

The source field is converted into a packed number. The packed number is then converted into a date field (see corresponding table).

F

Transport without conversion.

N

The source field is converted into a packed number. The packed number is then converted into a numeric text field (see corresponding table).

I, P

The floating point number is converted to an integer or fixed point value and, if necessary, rounded.

STRING

As for fields of type C, except that the maximum number of places is used for the mantissa (maximum precision). Despite this, different signs or exponents can lead to different string lengths.

T

The source field is converted into a packed number. The packed number is then converted into a time field (see corresponding table).

X

The source field is converted into a packed number. The packed number is then converted into a hexadecimal number (see corresponding table).

XSTRING

As for fields of type X, except that leading zeros are not copied.

 

Source Type Integer

Type I is always treated in the same way as type P without decimal places. Wherever type P is mentioned, the same applies to type I fields.

 

Source Type Numeric Text

Conversion table for source type N

Target

Conversion

C

The numeric field is treated like a character field. Leading zeros are retained.

D

The numeric field is converted into a character field. The character field is then converted into a date field (see corresponding table).

F

The numeric field is converted into a packed number. The packed number is then converted into a floating point number (see corresponding table).

N

The numeric field is transported right-justified and filled with zeros or truncated on the left.

I, P

The numeric field is interpreted as a number, and transferred to the target field, where it is right-justified, and adopts a plus sign. If the target field is too short, the program may be terminated.

STRING

As for fields of type C. The length of the character string matches the length of the numeric text.

T

The numeric field is converted into a character field. The character field is then converted into a time field (see corresponding table).

X

The numeric field is converted into a packed number. The packed number is then converted into a hexadecimal number (see corresponding table).

XSTRING

As for fields of type X, except that leading zeros are not copied.

 

Source Type Packed Number

If the program attribute Fixed point arithmetic is set, the system rounds type P fields according to the number of decimal places or fills them out with zeros.

Conversion table for source type P

Target

Conversion

C

The packed field is transported right-justified to the character field, if required with a decimal point. The last position is reserved for the sign. Leading zeros appear as blanks. If the target field is too short, the sign is omitted for positive numbers. If this is still not sufficient, the field is truncated on the left. ABAP indicates the truncation with an asterisk (*). If you want the leading zeros to appear in the character field, use UNPACK instead of MOVE.

D

The packed field value represents the number of days since 01.01.0001 and is converted to a date in YYYYMMDD format.

F

The packed field is accepted and transported as a floating point number.

N

The packed field is rounded if necessary, unpacked, and then transported right-justified. The sign is omitted. If required, the target field is filled with zeros on the left.

I, P

A packed field is converted to type I. The resulting four bytes are placed into the target field right-justified. If the target field is too short, an overflow occurs. If the target field is longer, it is filled with zeros on the left.

STRING

As for fields of type C, except that leading zeros are not generated.

T

The packed field value represents the number of seconds since midnight and is converted to a time in HHMMSS format.

X

A packed field is converted to type I. The resulting four bytes are placed into the target field right-justified and in big-endian format. If the target field is too short, it is truncated from the left. If the target field is longer than 4, it is filled with zeros on the left. Negative numbers are represented by the two's complement (= bit complement +1).

XSTRING

As for fields of type X, except that leading zeros are not generated.

 

Source Type String

Conversion table for source type STRING

Target

Conversion

C

The target field is filled from left to right. If it is longer than the string, it is filled with trailing spaces. If it is too short, the contents are truncated from the right.

D

The string must contain an 8-character date in the format YYYYMMDD .

F

The contents of the string must be a valid representation of a type F field as described in Literals.

N

Only digits in the string are copied. The field is right-justified and filled with trailing zeros. If the target field is too short, it is truncated from the left.

I, P

The string must contain the representation of a decimal number, that is, a sequence of digits with an optional sign and no more than one decimal point. The source field can contain blanks. If the target field is too short, an overflow may occur. This may cause the system to terminate the program.

STRING

The source string is copied to the target string unconverted.

T

The string must contain a six-character time in HHMMSS format.

X

Since the character field must contain a hexadecimal-character string, the only valid characters are 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. This character string is packed as a hexadecimal number, transported left-justified, and filled with zeros or truncated on the right.

XSTRING

As for target fields of type X, except that the field is not filled with zeros.

 

Source Type Time

Conversion table for source type T

Target

Conversion

C

The source field is transported left-justified without conversion.

D

Not supported. Results in an error message during the syntax check or in a runtime error.

F

The source field is converted into a packed number. The packed number is then converted into a floating point number (see corresponding table).

N

The date is converted into a character field. The character field is then converted into a numeric text field (see corresponding table).

I, P

The date is converted to the number of seconds since midnight.

STRING

The time is converted to a character field, which is then converted to a character string.

T

The date is transported left-justified without conversion and, if necessary, filled with zeros on the right.

X

The date is converted to the number of seconds since midnight in hexadecimal format.

XSTRING

As for fields of type X, except that only significant bytes are copied.

 

Source Type Hexadecimal Field

Conversion table for source type X

Target

Conversion

C

The value in the hexadecimal field is converted to a hexadecimal character string, transported left-justified to the target field, and filled with zeros.

D

The source field value represents the number of days since 01.01.0001 and is converted to a date in YYYYMMDD format.

F

The source field is converted into a packed number. The packed number is then converted into a floating point number (see corresponding table).

N

The source field is converted into a packed number. The packed number is then converted into a numeric text field (see corresponding table).

I, P

The value of the source field is interpreted as a hexadecimal number. It is converted to a packed decimal number and transported right-justified to the target field. If the hexadecimal field is longer than 4 bytes, only the last four bytes are converted. If it is too short, a runtime error may occur.

STRING

As for target fields of type C, except that the field is not filled with zeros. The length of the string is twice the length of the hexadecimal field.

T

The source field value represents the number of seconds since midnight and is converted to a time in HHMMSS format.

X

The value is transported left-justified and filled with X'00' on the right, if necessary.

XSTRING

The hexadecimal field is copied completely – that is, trailing zeros are not truncated.

 

Source Type Byte Sequence

Conversion table for source type XSTRING

Target

Conversion

C

The value in the byte sequence is converted to a hexadecimal character string, transported left-justified to the target field, and filled with zeros.

D

The byte sequence value represents the number of days since 01.01.0001 and is converted to a date in YYYYMMDD format.

F

The content of the byte sequence is converted into a packed number. The packed number is then converted into a floating point number (see corresponding table).

N

The content of the byte sequence is converted into a packed number. The packed number is then converted into a numeric text field (see corresponding table).

I, P

The content of the byte sequence is interpreted as a hexadecimal number. It is converted to a packed decimal number and transported right-justified to the target field. If the byte sequence is longer than 4 bytes, only the last four bytes are converted. If it is too short, a runtime error may occur.

STRING

As for target fields of type C, except that the field is not filled with zeros. The length of the string is twice the length of the byte sequence.

T

The byte sequence value represents the number of seconds since midnight and is converted to a time in HHMMSS format.

X

The byte sequence is transported left-justified and filled with X'00' on the right, if necessary.

XSTRING

The source byte sequence is copied to the target byte sequence unconverted.

 

 

Leaving content frame