CONVERT_DATE_TO_EXTERNAL¶
Convert an internal ABAP date (YYYYMMDD) to the user's display format.
Purpose¶
Transforms the internal 8-digit date representation (e.g. '20240115') into the locale-specific format stored in the user's personal settings — '15.01.2024' for German, '01/15/2024' for US, and so on. Essential before displaying any date in a message, ALV column header, custom screen, or concatenated string. The companion FM CONVERT_DATE_TO_INTERNAL does the reverse.
Signature¶
| Parameter | Direction | Type | Notes |
|---|---|---|---|
DATE_INTERNAL |
IMPORTING | SY-DATUM |
Internal 8-digit date. Default: SY-DATUM. |
DATE_EXTERNAL |
EXPORTING | — | Formatted date string in the user's locale. |
Exceptions¶
| Exception | When raised |
|---|---|
DATE_INTERNAL_IS_INVALID |
The value passed is not a valid internal date. |
Example¶
DATA lv_date_ext TYPE string.
" Convert today's date for use in a message
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
date_internal = sy-datum
IMPORTING
date_external = lv_date_ext
EXCEPTIONS
date_internal_is_invalid = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE 'Invalid date.' TYPE 'E'.
ENDIF.
MESSAGE |Report run on { lv_date_ext }| TYPE 'S'.
" Convert a date from a database record before display
DATA: ls_order TYPE vbak,
lv_ext_dat TYPE string.
SELECT SINGLE * FROM vbak INTO ls_order WHERE vbeln = '0000012345'.
IF ls_order-audat IS NOT INITIAL.
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
date_internal = ls_order-audat
IMPORTING
date_external = lv_ext_dat
EXCEPTIONS
date_internal_is_invalid = 1
OTHERS = 2.
WRITE: / 'Order date:', lv_ext_dat.
ENDIF.
Common pitfalls¶
Initial date does not raise an exception
Passing an initial TYPE D field ('00000000') does not raise DATE_INTERNAL_IS_INVALID — it returns '00.00.0000' or the locale equivalent. Check IF date_internal IS NOT INITIAL before calling if a blank output is preferable.
Output length varies by locale
The exported value is typically 10 characters but can differ by locale. Use TYPE string for DATE_EXTERNAL to be safe — never a fixed CHAR10.
- Always convert before concatenating a date into a message string. Direct concatenation of a
TYPE Dfield produces rawYYYYMMDDdigits. - The conversion respects the running user's personal date format settings — results differ between users.
- For ALV output, rely on the DDIC type on the field catalog column rather than pre-converting, so ALV handles sorting correctly.
See also¶
CONVERT_DATE_TO_INTERNAL— reverse conversion: user input → internal TYPE D