Inverted Dates
In some cases (for example, when sorting dates in descending order), it is useful to convert a date from format D to an inverted date by using the keyword CONVERT.
CONVERT DATE <d1> INTO INVERTED-DATE <d2>.
Afterwards, you can convert the inverted data back into a normal date using the statement
CONVERT INVERTED-DATE <d1> INTO DATE <d2>.
These statements convert the field <d1> from the formats DATE or INVERTED-DATE to the formats INVERTED-DATE or DATE and assign it to the field <d2>.
For the conversion, ABAP forms the nine's complement.
DATA: ODATE TYPE D VALUE '19955011',
IDATE LIKE ODATE.
DATA FIELD(8).
FIELD = ODATE. WRITE / FIELD.
CONVERT DATE ODATE INTO INVERTED-DATE IDATE.
FIELD = IDATE. WRITE / FIELD.
CONVERT INVERTED-DATE IDATE INTO DATE ODATE.
FIELD = ODATE. WRITE / FIELD.
Output:
80049488
19955011
19955011
|