ABAP DATE and INVERTED-DATE Convert

In this tutorial we are going to learn about the statements and their syntax used for date converts in ABAP programming.

Convert a date to inverted-date, and vice versa.

Syntax

CONVERT DATE <d1> INTO INVERTED-DATE <d2>.

CONVERT INVERTED-DATE <d1> INTO DATE <d2>.

 

Inverted date contains the nines compliment value (difference with 9) of the date. This conversion mainly used for sorting and other purposes. The recent dates have numerically smallest value than the others in inverted form. In the statement both <d1> and <d2> will be date fields with a format YYYYMMDD.

For example:

If the date is 19950511, then after the

CONVERT DATE <d1> INTO INVERTED-DATE <d2> statement, the <d2> will contain the value 80049488.

 

CONVERT INVERTED-DATE statement do the opposite operation that it will convert the inverted date to its original date.

 

Convert Timestamps.

Syntax

CONVERT TIME STAMP <tst> TIME ZONE <tz> INTO DATE <d> TIME <t>.

CONVERT DATE <d> TIME <t> INTO TIME STAMP <tst> TIME ZONE <tz>.

These statements are used for converting a time stamp into its correct date and time format using the specified time zone and vice versa.

Here the time stamp field <tst> must have any of the following data type

  1. data type TIMESTAMP
  2. data type TIMESTAMPL
  3. type p with length 8 with seven decimal places
  4. type p with length 11 with seven decimal places

 

System field sy-subrc values for this statement

  • sy-subrc=0  (Time successfully converted to time stamp)
  • sy-subrc=4  (Successfully converted to time stamp without time offset)
  • sy-subrc=8  (Couldn’t convert due to the time zone not exist in the database table)

sy-subrc=12 (Couldn’t convert because date or time or timestamp contains invalid values)

Also Read : View Other ABAP Keywords & Syntax -> ABAP Transaction codes