Skip to content

CONVERT_DATE_TO_INTERNAL

Convert a user-formatted date string to ABAP's internal format (YYYYMMDD).

Purpose

The reverse of CONVERT_DATE_TO_EXTERNAL. Takes whatever date string the user typed or a source system produced — formatted according to the user's locale settings — and returns a clean TYPE D value. Use this when reading date input from free-text screen fields, flat files, or BAPIs that return locale-formatted date strings. An invalid string sets RETURNCODE to a non-zero value; no exception is raised, so you must check it explicitly.

Signature (the parts you'll actually use)

Parameter Direction Type Notes
DATUM_EXTERN IMPORTING STRING User-formatted date string to convert
DATUM EXPORTING D Internal date (TYPE D, YYYYMMDD)
ERROR_INFO EXPORTING STRING Human-readable error description on failure
RETURNCODE EXPORTING C ' ' = success; non-blank = conversion failed

Example

DATA: lv_input    TYPE string,
      lv_datum    TYPE d,
      lv_errinfo  TYPE string,
      lv_rc       TYPE c LENGTH 1.

" Value typed by the user in a free-text input field
lv_input = p_date.   " e.g. '15.01.2024' for a German-locale user

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
  EXPORTING
    datum_extern             = lv_input
  IMPORTING
    datum                    = lv_datum
    error_info               = lv_errinfo
    returncode               = lv_rc.

IF lv_rc <> ' '.
  MESSAGE |Invalid date: { lv_errinfo }| TYPE 'E'.
  RETURN.
ENDIF.

" lv_datum is now safe to use in SELECT WHERE conditions
SELECT * FROM vbak INTO TABLE @DATA(lt_orders)
  WHERE audat = @lv_datum.

Common pitfalls

Always check RETURNCODE before using DATUM

An unparseable date string does not dump — it silently returns an initial (zero) TYPE D value and sets RETURNCODE. If you skip the check and store or compare the zero date, you will get incorrect query results with no error visible to the user.

Two-digit year handling

If the input string contains a two-digit year (allowed in some locale formats), the FM interprets it relative to the system threshold parameter TWODIGIT_YEAR_SWAP — typically 2000. Do not rely on this behaviour for batch imports; always enforce four-digit years in file specifications.

  • The FM interprets DATUM_EXTERN according to SY-UNAME's date format setting. Passing a hardcoded 'DD.MM.YYYY'-formatted string when the current user's locale expects 'MM/DD/YYYY' will fail or silently produce the wrong date.
  • For screen field input, prefer using a TYPE D parameter directly on the selection screen — ABAP handles the locale conversion automatically for PARAMETERS/SELECT-OPTIONS of type D.
  • Do not pass the raw SY-DATUM (already internal format) to this FM — it will be misinterpreted as a locale string.

See also

Comments