sapdev logo background
sapdev logo sapdev logo
Comments

ABAP CONVERT DATE Statement syntax, information and example SAP source code



Return to Statement index



CONVERT - INVERTED-DATE

Short Reference

ABAP Syntax(Obsolete) CONVERT { {DATE dat1 INTO INVERTED-DATE dat2}

| {INVERTED-DATE dat1 INTO DATE dat2} }.

What does it do? These variants of the CONVERT statement are not permitted in classes. They convert the numbers in a character-like data object in dat1 into their complement on nine (the difference to the number nine) and assign the result to the data object dat2 . The data objects dat1 and dat2 must have a flat character-like data type with length 8. The same data object can be specified for dat2 as for dat1 .

Latest notes: These forms of the CONVERT statement are not allowed in classes. They were previously used for sorting by date fields in internal tables and extracts for changing the sort direction. These have now been replaced by the ASCENDING
and DESCENDING additions of the SORT
statement. If necessary, the complement on nine can be formed using the following TRANSLATE statement:
dat2 = dat1.
TRANSLATE dat2 USING '09182736455463728190'.
Do not mistake the variant of the statement CONVERT DATE shown here with the statement CONVERT DATE ... INTO TIME STAMP used for creating time stamps.

Example ABAP Coding The following program section sorts the internal table sflight_tab in descending order by the fldate column.
DATA sflight_tab TYPE TABLE OF sflight.

FIELD-SYMBOLS <(><<)>sflight_wa> TYPE sflight.

SELECT * FROM sflight INTO TABLE sflight_tab.

LOOP AT sflight_tab ASSIGNING <(><<)>sflight_wa>.
CONVERT DATE <(><<)>sflight_wa>-fldate
INTO INVERTED-DATE <(><<)>sflight_wa>-fldate.
ENDLOOP.

SORT sflight_tab BY fldate.

LOOP AT sflight_tab ASSIGNING <(><<)>sflight_wa>.
CONVERT INVERTED-DATE <(><<)>sflight_wa>-fldate
INTO DATE <(><<)>sflight_wa>-fldate.
ENDLOOP.
The last nine lines can be replaced by a single line:
SORT sflight_tab BY fldate DESCENDING.



Runtime Exceptions
Non-catchable Exceptions

Reason for error: Conversion not possible due to invalid field length
Runtime error: CONVERT_ILLEGAL_CONVERSION
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




CONVERT
CONVERT_DATE_TIME-STAMP




comments powered by Disqus