ABAP Convert Date Format

  Define Data

Over View

The one thing you should be careful about when creating an ABAP program is the conversion of internal format and external format.
If you don’t include these transformations, you may store the wrong value in the database, or you may not be able to retrieve it,
Or it may cause a short dump.
Use the appropriate function module to convert and then use the value.
This section describes how to convert the date.

Sample code: Internal format-> External format

DATA: v_external_date(12)   TYPE c.
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
  EXPORTING
    date_internal = sy-datum         
  IMPORTING
    date_external = v_external_date.

When executed on 20170818, the value returns to 2017/08/18 is converted.

Sample code: External format->Internal format

DATA: v_internal_date       TYPE d.
v_external_date = '2017/08/18'.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
  EXPORTING
    date_external = v_external_date
  IMPORTING
    date_internal = v_internal_date.

in this example, 20170818 is returned.

Please see here for the definition method of Type
Please see here for how to define Data