Hello Everyone!
Recently, I worked on a timestamp conversion issue related to user-specific time zones in SAP. The data stored in the SAP level was correct, but when displayed through an ABAP report, the timestamp appeared incorrect for some users.
After analyzing the issue, I found that the root cause was the conversion routine defined in the domain. This routine automatically converts timestamps based on the user’s logon time zone, which caused mismatches during display.
In this blog, I will show how to resolve this issue by converting all timestamps to UTC before displaying them, ensuring consistent results for every user—regardless of their time zone or domain settings.
Problem Summary
The timestamp stored in the database table (ZDEL_INFO) was correct.
But when displaying the data in a report, the timestamp appeared incorrect for some users.
This happened because the domain of the timestamp field had a conversion routine (e.g., TZNTSTMPS).
As a result, SAP automatically converted timestamps based on each user’s time zone.
Example:
Domain with Conversion Routine:
Table:
Report:
Solution Approach
Read timestamp values from the database.
Convert local timestamp → UTC timestamp using:
cl_kf_helper=>timestamp_local_zone_2_utc
3.Populate the final internal table with the corrected timestamp.
4.Display the data using CL_SALV_TABLE.
By converting timestamps to UTC, the displayed values remain consistent for all users.
*&———————————————————————*
*& Report ZTIMESTAMPS_USERS
*&———————————————————————*
*& Purpose:
*& This report reads delivery data from table ZDEL_INFO,
*& converts local timestamps into UTC based on the user’s time zone,
*& and displays the results using CL_SALV_TABLE.
*&———————————————————————*
REPORT ztimestamps_users.
TABLES: zdel_info.
TYPES: BEGIN OF ty_del,
deliveryno TYPE zdel_info-deliveryno,
material TYPE zdel_info-material,
deldate TYPE zdel_info-deldate,
END OF ty_del.
DATA: lt_final TYPE TABLE OF ty_del,
ls_final TYPE ty_del.
*START-OF-SELECTION.
START-OF-SELECTION.
SELECT * FROM zdel_info
INTO TABLE (lt_del).
LOOP AT lt_del INTO DATA(ls_del).
ls_final-deliveryno = ls_del-deliveryno.
ls_final-material = ls_del-material.
IF ls_del-deldate IS NOT INITIAL.
CALL METHOD cl_kf_helper=>timestamp_local_zone_2_utc
EXPORTING
i_timestamp_local = ls_del-deldate ” Timestamp in user’s local time
i_time_zone = sy-zonlo ” Current user’s time zone
RECEIVING
r_timestamp_utc = DATA(lv_tmstamputc). ” Converted UTC timestamp
ls_final-deldate = lv_tmstamputc.
CLEAR lv_tmstamputc.
ENDIF.
APPEND ls_final TO lt_final.
ENDLOOP.
DATA: o_alv TYPE REF TO cl_salv_table.
cl_salv_table=>factory(
IMPORTING
r_salv_table = o_alv
CHANGING
t_table = lt_final ).
* Display the ALV
o_alv->display( ).
Output:
Explanation of Key Logic
1. timestamp_local_zone_2_utc
This method converts a timestamp from the user’s local time zone (based on SY-ZONLO) to UTC.
2. Why Convert to UTC?
UTC is a universal reference.
Once converted to UTC, the timestamp remains consistent, regardless of:
User logon time zone
System time zone
Conversion routines in the domain
3. Output Using SALV
CL_SALV_TABLE is used for a simple and clean ALV output without advanced configuration.
Conclusion
Handling timestamps in SAP can be challenging, especially when conversion routines and user time zones come into play.
By converting timestamps to UTC before displaying them, we avoid incorrect values and ensure reliable reporting across all users.
It will have been Very Helpful for Real Time users in Project works
this has a process of just like small solution thank you…
Hello Everyone!Recently, I worked on a timestamp conversion issue related to user-specific time zones in SAP. The data stored in the SAP level was correct, but when displayed through an ABAP report, the timestamp appeared incorrect for some users.After analyzing the issue, I found that the root cause was the conversion routine defined in the domain. This routine automatically converts timestamps based on the user’s logon time zone, which caused mismatches during display.In this blog, I will show how to resolve this issue by converting all timestamps to UTC before displaying them, ensuring consistent results for every user—regardless of their time zone or domain settings.Problem SummaryThe timestamp stored in the database table (ZDEL_INFO) was correct.But when displaying the data in a report, the timestamp appeared incorrect for some users.This happened because the domain of the timestamp field had a conversion routine (e.g., TZNTSTMPS).As a result, SAP automatically converted timestamps based on each user’s time zone.Example:Domain with Conversion Routine:Table:Report:Solution ApproachRead timestamp values from the database.Convert local timestamp → UTC timestamp using:cl_kf_helper=>timestamp_local_zone_2_utc3.Populate the final internal table with the corrected timestamp.4.Display the data using CL_SALV_TABLE.By converting timestamps to UTC, the displayed values remain consistent for all users.*&———————————————————————*
*& Report ZTIMESTAMPS_USERS
*&———————————————————————*
*& Purpose:
*& This report reads delivery data from table ZDEL_INFO,
*& converts local timestamps into UTC based on the user’s time zone,
*& and displays the results using CL_SALV_TABLE.
*&———————————————————————*
REPORT ztimestamps_users.
TABLES: zdel_info.
TYPES: BEGIN OF ty_del,
deliveryno TYPE zdel_info-deliveryno,
material TYPE zdel_info-material,
deldate TYPE zdel_info-deldate,
END OF ty_del.
DATA: lt_final TYPE TABLE OF ty_del,
ls_final TYPE ty_del.
*START-OF-SELECTION.
START-OF-SELECTION.
SELECT * FROM zdel_info
INTO TABLE (lt_del).
LOOP AT lt_del INTO DATA(ls_del).
ls_final-deliveryno = ls_del-deliveryno.
ls_final-material = ls_del-material.
IF ls_del-deldate IS NOT INITIAL.
CALL METHOD cl_kf_helper=>timestamp_local_zone_2_utc
EXPORTING
i_timestamp_local = ls_del-deldate ” Timestamp in user’s local time
i_time_zone = sy-zonlo ” Current user’s time zone
RECEIVING
r_timestamp_utc = DATA(lv_tmstamputc). ” Converted UTC timestamp
ls_final-deldate = lv_tmstamputc.
CLEAR lv_tmstamputc.
ENDIF.
APPEND ls_final TO lt_final.
ENDLOOP.
DATA: o_alv TYPE REF TO cl_salv_table.
cl_salv_table=>factory(
IMPORTING
r_salv_table = o_alv
CHANGING
t_table = lt_final ).
* Display the ALV
o_alv->display( ).Output:Explanation of Key Logic1. timestamp_local_zone_2_utcThis method converts a timestamp from the user’s local time zone (based on SY-ZONLO) to UTC.2. Why Convert to UTC?UTC is a universal reference.Once converted to UTC, the timestamp remains consistent, regardless of:User logon time zoneSystem time zoneConversion routines in the domain3. Output Using SALVCL_SALV_TABLE is used for a simple and clean ALV output without advanced configuration.ConclusionHandling timestamps in SAP can be challenging, especially when conversion routines and user time zones come into play.By converting timestamps to UTC before displaying them, we avoid incorrect values and ensure reliable reporting across all users.It will have been Very Helpful for Real Time users in Project worksthis has a process of just like small solution thank you… Read More Technology Blog Posts by Members articles
#SAP
#SAPTechnologyblog