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 (the parts you'll actually use)¶
| Parameter | Direction | Type | Notes |
|---|---|---|---|
DATUM |
IMPORTING | D |
Internal 8-digit date (TYPE D) |
DATUM_EXTERN |
EXPORTING | STRING |
Formatted date string in the user's locale |
Example¶
DATA: lv_date_ext TYPE string.
" Convert today's date for use in a message
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
datum = sy-datum
IMPORTING
datum_extern = lv_date_ext.
MESSAGE |Report run on { lv_date_ext }| TYPE 'S'.
" Typical pattern: 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
datum = ls_order-audat
IMPORTING
datum_extern = lv_ext_dat.
ENDIF.
WRITE: / 'Order date:', lv_ext_dat.
Common pitfalls¶
Initial date produces a locale-formatted zero date
Passing an initial TYPE D field ('00000000') does not raise an exception — it returns '00.00.0000' or the locale equivalent. Check IF datum IS NOT INITIAL before calling the FM if a blank output is preferable to a zero-formatted string.
Output length varies by locale
The exported string is 10 characters for most locales but can differ. Never declare a fixed-length CHAR10 variable for the result and then pad or truncate it — use TYPE string to be safe.
- Always use this FM (or an equivalent inline cast) before concatenating a date into a message string. Direct concatenation of a
TYPE Dfield produces the rawYYYYMMDDdigits, which confuses end users. - The conversion respects
SY-UNAME's personal settings at runtime — results differ between users if their date formats differ. - For ALV output, set
EDIT_MASKor rely on the DDIC type on the field catalog column rather than pre-converting, so ALV can handle sorting correctly.
See also¶
CONVERT_DATE_TO_INTERNAL— reverse conversion: user input → internal TYPE D