Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Converting time and date to system date and time

Former Member
0 Kudos

Hello Experts,

I have one report which is display the success and failure deliveries in the day,

the delivery creating time and confirmation time are different so we are getting the wrong result of in other countries

so I want to change the both the time stamps are same.

how can I change it..?

I heard to change the time stamp we can use the function modules any body have any ideas..?

9 REPLIES 9

amadeusgrabmayer
Participant
0 Kudos

Hi,

I'm not 100% sure what you want to change exactly, but for the problem with "wrong" times in different countries you should go for UTC-Timestamps.

This could either be achieved by:

If you then display this Timestamp (i.e. in an ALV), you could use a Field with the Conversion-Exit "TSTLC" so that the timestamp is converted in the local time zone of the current active user.

If this doesn't meet your requirement, please give more detailed information about what exactly you are trying to achieve.

Regards,

Amadeus

0 Kudos

If an order is received before 12.00 am it is shipped on the same day

The problem with my report is that the creation time is saved in system time and the confirmation time is saved in user time.

So the analysis result is not correct because of the time difference between Europe and Australia.

0 Kudos

Then my first recommendation should solve your problem - UTC-Times (http://en.wikipedia.org/wiki/Coordinated_Universal_Time😞

Instead of using the system-variables SY-DATUM, SY-DATLO, etc. create in both cases a UTC-Timestamp with GET TIME STAMP FIELD time_stamp.. And for your report you then can convert the timestamp either by:

  • an implicit conversion-exit (when you have a ALV-output put the timestamp in a field, which has a datatype containing the conversion-exit "TSTLC")
  • an explicit conversion-exit by calling the function-module " CONVERSION_EXIT_TSTLC_OUTPUT"
  • Or by converting the timestamp into a date and a time field by the key words

CONVERT TIME STAMP time_stamp TIME ZONE tz

        INTO [DATE dat]

             [TIME tim] [DAYLIGHT SAVING TIME dst].

If you just want to calculate the length between those timestamps, you don't need any conversion at all - then you can just calculate with the UTC-Timstamps.

Regards,

Amadeus

0 Kudos

If you can't change the creation/confirmation process, I would recommend, that you convert both times into utc, that they are on the same level:

  1. you will need the user-name who confirmed the order to get his timezone
    with the function-module "BAPI_USER_GET_DETAIL", in the exporting structure "LOGONDATA", it is returned in the field "TZONE"
  2. you need the system timezone, which you can get with the function-module "GET_SYSTEM_TIMEZONE"
  3. With this data you can convert the date and time of creation and confirmation into two UTC timestamps with the keywords

CONVERT DATE dat
        [TIME tim [DAYLIGHT SAVING TIME dst]]
        INTO TIME STAMP time_stamp TIME ZONE tz.

http://help.sap.com/abapdocu_702/de/abapconvert_date_time-stamp.htm

Then you are on the same timezone with both and can do your analysis.

Regards,

Amadeus

0 Kudos

In both the cases I am using CONVERT only

* convert LIKP server date/time into local date/time
     CONVERT DATE likp-erdat TIME likp-erzet
            INTO TIME STAMP curstamp TIME ZONE tzone_s.


     CONVERT TIME STAMP curstamp TIME ZONE sy-zonlo
            INTO DATE likp-erdat TIME likp-erzet.



*convert NAST server date/time into local date/time
         CONVERT DATE nast-erdat TIME nast-eruhr
         INTO TIME STAMP curstamp TIME ZONE tzone_s.
         CONVERT TIME STAMP curstamp TIME ZONE sy-zonlo
                INTO DATE nast-erdat TIME nast-eruhr.

0 Kudos

What is the value of "TZONE_S" in both cases?

0 Kudos

I am getting the value from this:

SELECT SINGLE tzonesys FROM ttzcu INTO tzone_s
                     WHERE flagactive = 'X'.

both the cases I ma getting TZONE_S = CET, only..

0 Kudos

This is the my program:

REFRESH w.

   SELECT SINGLE tzonesys FROM ttzcu INTO tzone_s
                     WHERE flagactive = 'X'.

* read deliveries and fill worktable w

   SELECT * FROM likp WHERE erdat IN s_date AND
                             vstel = p_vstel AND
                             vbtyp EQ 'J'.


* convert LIKP server date/time into local date/time
     CONVERT DATE likp-erdat TIME likp-erzet
            INTO TIME STAMP curstamp TIME ZONE tzone_s.
     CONVERT TIME STAMP curstamp TIME ZONE sy-zonlo
            INTO DATE likp-erdat TIME likp-erzet.

     MOVE-CORRESPONDING likp TO w.

     APPEND w.

   ENDSELECT.
*

* NOW LETS CHECK THE DELIVERY NOTEs
* Sort added (necessary in Europe system)
   SORT w BY vbeln erdat erzet.
   LOOP AT w.


* default success to NO
     vbeln = w-vbeln. "WITH LEADING ZERO'S
     success = 'N'.   CLEAR errtxt.
*
     SELECT SINGLE * FROM nast WHERE kappl = 'V2'   AND
                                     objky vbeln  AND
                                     kschl = 'Z53L' AND
                                     aktiv space.

     IF sy-subrc   = 0.

* convert NAST server date/time into local date/time
       CONVERT DATE nast-erdat TIME nast-eruhr
       INTO TIME STAMP curstamp TIME ZONE tzone_s.
       CONVERT TIME STAMP curstamp TIME ZONE sy-zonlo
              INTO DATE nast-erdat TIME nast-eruhr.

* find next working day
       nextwd = w-erdat + 1.
       CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
         EXPORTING
           correct_option      = '+'
           date                = nextwd
           factory_calendar_id = tvst-fabkl
         IMPORTING
           date                = nextwd.

* check time before cut-off time
* same date = success

       IF w-erzet LE p_cuttim AND
       nast-erdat EQ w-erdat.
         success = 'Y'.
       ENDIF.

*    check next working day
       IF w-erzet GT p_cuttim AND
      nast-erdat LE nextwd.
         success = 'Y'.
       ENDIF.

       w2-erdat = w-erdat.
       IF success = 'Y'.
         w2-success = 1.
         w2-failure = 0.
       ELSE.
         w2-success = 0.
         w2-failure = 1.
         errtxt = 'GI too late'.
         IF nextwd GT sy-datum.
           errtxt = 'still time to success'.
         ENDIF.
       ENDIF.
       w2-deliveries = 1.
       COLLECT  w2.

     ELSE" sy-subrc select nast
       w2-erdat = w-erdat.
       w2-success = 0.
       w2-failure = 1.
       w2-deliveries = 1.
       COLLECT  w2.
       errtxt = 'Not printed (no NAST)'.
     ENDIF.

* append failure information

     IF success = 'N'.
       CLEAR failures.
       MOVE-CORRESPONDING w TO failures.
       IF errtxt = 'GI too late'.
         failures-erdat2 = nast-erdat.
         failures-eruhr = nast-eruhr.
       ENDIF.

       failures-text = errtxt.
       APPEND failures.
     ENDIF.

   ENDLOOP.

0 Kudos

That won't work, because that is the system-timezone and you can't be sure, that that is also the users time zone.

I would try this:


DATA: lt_return    TYPE bapiret2_t,

       ls_logondata TYPE bapilogond.

CALL FUNCTION 'BAPI_USER_GET_DETAIL'

   EXPORTING

     username  = likp-ernam

   IMPORTING

     logondata = ls_logondata

   TABLES

     return    = lt_return.

CONVERT DATE likp-erdat TIME likp-erzet

   INTO TIME STAMP curstamp TIME ZONE ls_logondata-tzone.

And the same with NAST-USNAM.

Regards,

Amadeus