Skip to Content
Author's profile photo Nilesh Suryavanshi

Logical Ways To Determining Time Zone For Time Date Conversion(TM)

Many a time we as TM developer come across scenarios where we would have to do time conversions and for precise time conversion Time Zone is a very important entity.
we do either of the 2:

  1. Assume the time zone to be fetched from Location ID    OR
  2. Assume the time zone to be Sy-Zonlo.

Assuming anything is always a problem which can lead to a defect UAT or an incident in the production system as the Expected resultant time would be different for different users.

This Blog will help  you to identify when and which time zone we should/could use for Time conversion while coding in SAP TM which could help us in a precise conversion of time or timestamp values.

There are 3 scenarios for how a Time zone should/could be fetched and used are listed below, can be handled logically on the settings maintained for Particular UI.

  1. Time zone to be fetched from Location ID
  2. Time zone to be fetched from Sy-Zonlo
  3. Time zone to be fetched with respect to User.

Initially, we have to Fetch UI Display Settings using the following code.

 Data: ls_dispsett TYPE /scmtms/s_ui_dispsett, "UI display Settings
           ls_dispsett = /scmtms/cl_ui_dispsett=>get_user_settings ().

Method GET_USER_SETTINGS of Class /SCMTMS/CL_UI_DISPSETT will fetch the Display settings detail.

Structure Variable LS_DISPSETT will hold the display settings for the current user returned by the standard method.

(Note: This variable will hold other display related parameters as well which can be explored as it’s not part of this document)

  • Time zone to be fetched from Location ID

To identify if the Zone to be fetched is by using the Location ID we will require checking the “LOC_SPEC_TZONE” field of the Structure Variable LS_DISPSETTIf the condition satisfies we can use method LOC_KEY_GET_TIMEZONE of helper class /SCMTMS/CL_COMMON_HELPER to get the Zone

The following code can be referred as a sample for this scenario:

*   Location Specific Time Zone
IF ls_dispsett-loc_spec_tzone = /scmtms/if_ui_cmn_c=>sc_loc_spec_tzone-consider.
“ timezone is determined from stop location
          CALL METHOD /scmtms/cl_common_helper=>loc_key_get_timezone
            EXPORTING
              iv_loc_key  = ls_stop_data_k-log_loc_uuid
            RECEIVING
                rv_timezone = lv_tz.
Endif.
  • Time zone to be fetched from Sy-Zonlo

To identify if the Zone to be fetched is by using the system variable SY-ZONLO we will require checking one of the two cases:

  1. PREF_TIMEZONE field of the Structure Variable LS_DISPSETT has value blank/space
  2. PREF_TIMEZONE field of the Structure Variable LS_DISPSETThas value X and INDIV_TIMEZONE filed is blank/initial.

The following code can be referred as a sample for this scenario:

*System Time Zone
IF ls_dispsett-pref_timezone = /scmtms/if_ui_cmn_c=>sc_pref_tzone-user “Sapce
          OR
  ( ls_dispsett-pref_timezone = /scmtms/if_ui_cmn_c=>sc_pref_tzone-individual “X 
            AND
      ls_dispsett-indiv_timezone IS INITIAL ).
              lv_tz = sy-zonlo.
ENDIF.
  • Time zone to be fetched with respect to User

To identify if the Zone to be fetched is the Zone preferred by User i.e User specific, we will require checking 1 condition i.e.

If PREF_TIMEZONE field of the Structure Variable LS_DISPSETT has value X and INDIV_TIMEZONE field is not blank/initial.

 

The following code can be referred as a sample for this scenario:

* Preferred Time Zone: Individual
IF ls_dispsett-pref_timezone = /scmtms/if_ui_cmn_c=>sc_pref_tzone-individual
    AND ls_dispsett-indiv_timezone IS NOT INITIAL.
 lv_tz = ls_dispsett-indiv_timezone. “User maintained Time zone
ENDIF.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.