Conversion Rules for Elementary Data Types  

There are eight predefined ABAP data types. There are 64 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.

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 at the right-hand end.

D

The character field should 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.

T

The character field should contain a 6-character time in HHMMSS format.

X

Since the character field should 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 padded with zeros or truncated on the right.

 

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 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 days since 01.01.0001.

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.

 

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 should 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.

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).

 

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 padded 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.

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).

 

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 first 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 padded with zeros on the left.

I

P

The packed field is transported right-justified. If the target field is too short, an overflow occurs.

T

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

X

The packed field is rounded if necessary and then converted to a hexadecimal number. Negative numbers are represented by the two's complement. If the target field is too short, the number is truncated on the left.

 

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.

T

Transport without conversion.

X

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

 

Source Type Hexadecimal

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 padded 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.

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.