SAP ABAP Timestamp Display in ALV: Formatting and Time Zones

Learn how to display SAP ABAP timestamps in ALV with readable date-time text, UTC-to-local conversion, CL_SALV_TABLE, classic ALV field catalogs, sorting, filtering, and debugging tips.

Learn how to display SAP ABAP timestamps in ALV with readable date-time text, UTC-to-local conversion, CL_SALV_TABLE, classic ALV field catalogs, sorting, filtering, and debugging tips.
Photo by Thomas Tastet

A timestamp in SAP ABAP is usually stored in UTC and may be difficult to read directly in an ALV report. A value such as 20201004223429 is useful for sorting and database persistence, but users normally need a display such as 2020-10-04 22:34:29 in their local time zone.

This guide shows practical ways to display timestamps in SAP ALV using modern ABAP, CL_SALV_TABLE, classic ALV field catalogs, UTC conversion, fractional seconds, sorting, filtering, and troubleshooting techniques. The examples keep the original timestamp for technical operations and add a separate display field for presentation.

Timestamp types used in ABAP

  • TIMESTAMP stores a short timestamp without fractional seconds.
  • TIMESTAMPL stores a long timestamp with fractional seconds.
  • Database timestamp fields are commonly persisted in UTC and should not be formatted as local time without conversion.
  • A display string such as CHAR19 is convenient for users but should not replace the original timestamp used for sorting or calculations.

Do not treat a timestamp as an ordinary character string until you have confirmed the data type, precision, and time-zone meaning in the source table.

Convert an ABAP timestamp to date and time

Use the ABAP CONVERT TIME STAMP statement to split a UTC timestamp into a date and a time in a requested time zone.

DATA: lv_timestamp TYPE timestampl,
      lv_date      TYPE d,
      lv_time      TYPE t,
      lv_dst       TYPE abap_bool.

lv_timestamp = '20201004223429.1234567'.

CONVERT TIME STAMP lv_timestamp
        TIME ZONE sy-zonlo
        INTO DATE lv_date
             TIME lv_time
             DAYLIGHT SAVING TIME lv_dst.

WRITE: / lv_date, lv_time, lv_dst.

sy-zonlo uses the user logon time zone. Use an explicit SAP time-zone key when the report must show one business location consistently.

Build a readable timestamp for ALV

A reliable ALV pattern is to keep the technical timestamp and add a text field such as timestamp_text. This avoids relying on an edit mask to transform numeric timestamp data.

TYPES: BEGIN OF ty_alv_row,
         created_at    TYPE timestampl,
         timestamp_text TYPE char19,
         status        TYPE char20,
       END OF ty_alv_row.

DATA: lt_rows      TYPE STANDARD TABLE OF ty_alv_row,
      lv_date      TYPE d,
      lv_time      TYPE t,
      lv_timestamp TYPE timestampl.

LOOP AT lt_rows ASSIGNING FIELD-SYMBOL().
  CONVERT TIME STAMP -created_at
          TIME ZONE sy-zonlo
          INTO DATE lv_date
               TIME lv_time.

  -timestamp_text = | |.
ENDLOOP.

The original created_at remains available for sorting and filtering, while users see the readable timestamp_text.

Complete CL_SALV_TABLE example

The following example reads an application table, converts the timestamp to the current user time zone, and displays the result in a SALV table.

REPORT z_demo_timestamp_alv.

TYPES: BEGIN OF ty_output,
         id             TYPE i,
         created_at     TYPE timestampl,
         timestamp_text TYPE char19,
         status         TYPE char20,
       END OF ty_output.

DATA: lt_output TYPE STANDARD TABLE OF ty_output,
      lo_alv    TYPE REF TO cl_salv_table,
      lv_date   TYPE d,
      lv_time   TYPE t.

SELECT id, created_at, status
  FROM zorders
  INTO CORRESPONDING FIELDS OF TABLE @lt_output
  UP TO 100 ROWS.

LOOP AT lt_output ASSIGNING FIELD-SYMBOL().
  CONVERT TIME STAMP -created_at
          TIME ZONE @sy-zonlo
          INTO DATE lv_date
               TIME lv_time.

  -timestamp_text =
    | |.
ENDLOOP.

cl_salv_table=>factory(
  IMPORTING r_salv_table = lo_alv
  CHANGING  t_table      = lt_output ).

lo_alv->get_functions( )->set_all( abap_true ).
lo_alv->get_columns( )->set_optimize( abap_true ).
lo_alv->get_column( 'CREATED_AT' )->set_visible( abap_false ).
lo_alv->get_column( 'TIMESTAMP_TEXT' )->set_short_text( 'Created at' ).
lo_alv->get_column( 'TIMESTAMP_TEXT' )->set_medium_text( 'Created timestamp' ).
lo_alv->get_column( 'TIMESTAMP_TEXT' )->set_long_text( 'Created timestamp in user time zone' ).
lo_alv->display( ).

The exact CL_SALV_COLUMN reference type can vary by release. When a release requires a more specific column reference, use the type returned by the system editor or the SALV class documentation.

Sort and filter by the real timestamp

Do not sort by the formatted text if the display format may change by locale. Sort by the original timestamp field and show the text field only for presentation.

DATA(lo_sorts) = lo_alv->get_sorts( ).

lo_sorts->add_sort(
  columnname = 'CREATED_AT'
  sequence   = if_salv_c_sort=>sort_up ).

This keeps chronological ordering correct even when two users see different local time zones or date formats.

Display fractional seconds from TIMESTAMPL

If milliseconds or microseconds matter, use a long timestamp display field. Keep the fractional part separate from the date and time formatting so the output is predictable.

DATA: lv_timestamp_text TYPE char30,
      lv_date           TYPE d,
      lv_time           TYPE t,
      lv_fraction       TYPE string.

CONVERT TIME STAMP lv_timestamp
        TIME ZONE sy-zonlo
        INTO DATE lv_date
             TIME lv_time.

lv_fraction = lv_timestamp+15(7).
lv_timestamp_text =
  | .|.

Confirm the actual internal representation in your system before using offsets. Prefer standard conversion APIs or a typed timestamp utility where the application release provides one.

Classic ALV with an LVC field catalog

For CL_GUI_ALV_GRID, provide a display field in the output structure and configure the field catalog explicitly.

DATA: lt_fieldcat TYPE lvc_t_fcat,
      ls_fieldcat TYPE lvc_s_fcat.

CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'TIMESTAMP_TEXT'.
ls_fieldcat-coltext   = 'Created at'.
ls_fieldcat-scrtext_l = 'Created timestamp'.
ls_fieldcat-outputlen = 19.
ls_fieldcat-edit      = abap_false.
APPEND ls_fieldcat TO lt_fieldcat.

CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'CREATED_AT'.
ls_fieldcat-no_out    = abap_true.
APPEND ls_fieldcat TO lt_fieldcat.

For a timestamp that must be editable, validate the user input and convert it back to a timestamp explicitly. A visual edit mask alone does not guarantee a valid UTC value.

Convert date and time into a timestamp

When a selection screen or legacy interface provides separate date and time fields, combine them with an explicit time zone.

DATA: lv_date      TYPE d VALUE '20201004',
      lv_time      TYPE t VALUE '223429',
      lv_timestamp TYPE timestampl,
      lv_timezone  TYPE ttzz-tzone VALUE 'CET'.

CONVERT DATE lv_date TIME lv_time
        INTO TIME STAMP lv_timestamp
        TIME ZONE lv_timezone.

Never assume the application server time zone when the business event belongs to a plant, country, or user. Store the chosen time-zone rule with the business context when it affects auditability.

Convert a timestamp back to date and time

DATA: lv_date TYPE d,
      lv_time TYPE t,
      lv_dst  TYPE abap_bool.

CONVERT TIME STAMP lv_timestamp
        TIME ZONE 'UTC'
        INTO DATE lv_date
             TIME lv_time
             DAYLIGHT SAVING TIME lv_dst.

WRITE: / |UTC date: |,
       / |UTC time: |,
       / |DST active: |.

Use UTC when you are inspecting persisted technical values. Use sy-zonlo or a business time zone for the user-facing ALV.

Common timestamp ALV problems

Timestamp shows as an unreadable number

Check the DDIC type and create a separate character display field. Do not blindly apply an edit mask to a packed or timestamp value.

Timestamp is correct but one hour off

The conversion probably used the wrong time zone or ignored daylight-saving rules. Compare conversion results with UTC, sy-zonlo, and the intended business time zone.

ALV sorting is wrong

Sort by the original timestamp, not by a locale-formatted text field. Hide the technical field only after configuring the sort.

Fractional seconds disappear

The output field or formatting expression is too short. Use TIMESTAMPL and allocate enough display length for the fractional portion.

Timestamp is blank or initial

Check for an initial timestamp before conversion. An invalid or initial value should be displayed as blank or as a clear status, not converted without validation.

IF -created_at IS INITIAL.
  CLEAR -timestamp_text.
ELSE.
  CONVERT TIME STAMP -created_at
          TIME ZONE sy-zonlo
          INTO DATE lv_date
               TIME lv_time.
  -timestamp_text =
    | |.
ENDIF.

Developer checklist for timestamp ALV

  1. Identify whether the source is TIMESTAMP, TIMESTAMPL, a database timestamp, or character data.
  2. Confirm whether the stored value is UTC.
  3. Choose the user or business time zone explicitly.
  4. Convert with CONVERT TIME STAMP rather than string slicing alone.
  5. Keep the original timestamp for sorting and filtering.
  6. Add a separate display field for readable date-time text.
  7. Handle initial values and conversion errors.
  8. Test daylight-saving transitions and timestamps around midnight.
  9. Test the ALV with users in different time zones.
  10. Verify that fractional seconds are preserved when the business process requires them.

Summary

The safest SAP ABAP ALV design stores the technical timestamp unchanged, converts it with an explicit time zone, and displays a separate formatted field. This gives developers reliable sorting and filtering while giving users a readable local date and time.

Related SAP ABAP topics

2020-11-04abap Off Comments off on SAP ABAP Timestamp Display in ALV: Formatting and Time Zones1518