Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Assignments →  Assignment and Conversion Rules →  Conversion Rules for Elementary Data Objects →  Date fields, time fields, and time stamp fields as source fields 

Source Field Type d

The conversion rules are designed in such a way that when data objects of the data type d are assigned to character-like data objects they behave as character-like data objects. The latter is the basis for date calculations in arithmetic expressions.

Only dates in the format "yyyymmdd" are valid for data objects of type d. Here, "00010101" is the first valid value. The conversion rules, however, allow the assignment of date fields that contain invalid data. The latter is not recommended.

Other versions: 7.31 | 7.40 | 7.54

Numeric Target Fields

Target Conversion
i, int8, (b, s) If the source field contains a valid date in the format "yyyymmdd",it is used to calculate the number of days since 01.01.0001, and this value is then converted to theinternal representation of the corresponding integer. If the source field contains an invalid date, the target field is assigned the value 0. If thevalue range for the internaldata types b and s is insufficient, the non-handleable exception CX_SY_CONVERSION_OVERFLOW is raised.
p If the source field contains a valid date in the format "yyyymmdd",it is used to calculate the number of days since 01.01.0001, and this value is then converted to theinternal representation of a packed number. If the value range of the target field is too small, thehandleable exception CX_SY_CONVERSION_OVERFLOW is raised. If the source field contains an invalid date, the target field is assigned the value 0.
decfloat16, decfloat34 If the source field contains a valid date in the format "yyyymmdd",it is used to calculate the number of days since 01.01.0001, and this value is then converted to the internal representation of a decimal floating point number with ascaling of 0. If the source field contains an invalid date, the target field is assigned the value 0.
f If the source field contains a valid date in the format "yyyymmdd",it is used to calculate the number of days since 01.01.0001, and this value is then converted to theinternal representation of a binary floating point number. If the source field contains an invalid date, the target field is assigned the value 0.


Notes

  • The conversion of a date into the number of days since 01.01.001 is designed in such a way that the transition from the Julian to Gregorian calendar is respected: 4.10.1582 produces the number 577,736 and 15.10.1582 produces 577,737. Converting the dates of the nonexistent days between 5.10.1582 and 14.10.1582 produces the same result as converting the existing days from 15.10.1582 to 24.10.1582.

  • The assignment of the values "00000000" and "00010101" to a numeric type produces the value 0 in each case. The assignment of the value 0 to a date field produces "00000000". This means that the assignment of the value "00010101" to a numeric type cannot be reversed.

Example

The result of the following conversion has the value 736341. This is the number of days passed since 01.01.0001 until the specified date.

DATA dat TYPE d VALUE '20170111'. 

DATA(result) = CONV i( dat ). 

Character-Like Target Fields

Target Conversion
c Content is handled in the same way as a source field of type c
n The characters in the source field are passed left-justified to the target field. Trailing blanksin the source field are passed. If the target field is longer than the source field, it is padded on the right with the character "0". If the target field is shorter, it is truncated on the right.
string Content is handled in the same way as a source field of type c


Example

The string produced by the conversion is 2017. Four characters 0111 are cut off on the right.

DATA dat TYPE d VALUE '20170111'. 

TYPES n4 TYPE n LENGTH 4. 
DATA(result) = CONV n4( dat ). 

Byte-Like Target Fields

Target Conversion
x The content of the source field is converted first to data type i (seeabove) and then to type x (see conversion table for source field type i, int8,(b, s)).
xstring The content of the source field is converted first to data type i (seeabove) and then to type xstring (see conversion table for source field type i, int8,(b, s)).


Example

The byte chain produced by the conversion is 0B3C55. This is the integer 736341 or the number of days since 01.01.0001.

DATA dat TYPE d VALUE '20170111'. 

DATA(result) = CONV xstring( dat ).

Date/Time Fields as Target Fields

Target Conversion
d The content of the source field is passed unconverted.
t Not supported. Produces a syntax error or runtime error.
utclong Not supported. Produces a syntax error or raises the exception CX_SY_CONVERSION_NOT_SUPPORTED.


Example

The conversion of d to t (not known statically) is not supported and produces the runtime error MOVE_NOT_SUPPORTED.

FIELD-SYMBOLS <fs> TYPE data. 

ASSIGN sy-datum TO <fs>. 
DATA(result) = CONV t( <fs> ).