Getting UNIX/Epoch timestamp from the UI client is not reliable. Timestamps are generated based on the time set on the device. It is much better to let the ABAP application server create timestamps. To my knowledge, it is not possible to to generate a UNIX/Epoch timestamp in any SAP delivered method or function.

This little static method generates a timestamp that equals number of milliseconds since 01.01.1970.

class zcl_epoch definition
  public
  final
  create public .

  public section.

    class-methods get_time
      returning
        value(value) type numc13 .
  protected section.
  private section.
endclass.

class zcl_epoch implementation.

* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_EPOCH=>GET_TIME
* +-------------------------------------------------------------------------------------------------+
* | [<-()] VALUE                          TYPE        NUMC13
* +--------------------------------------------------------------------------------------</SIGNATURE>
  method get_time.

    data time type tzntstmpl.
    data str1 type string.
    data str2 type string.
    data tstmp1 type p.
    data tstmp2 type p.
    data secs type tzntstmpl.

    get time stamp field time.

    tstmp1 = time.
    tstmp2 = '19700101000000'.

    try.
        secs = cl_abap_tstmp=>subtract(
          tstmp1 = tstmp1
          tstmp2 = tstmp2
        ).
      catch cx_parameter_invalid_range .
      catch cx_parameter_invalid_type .
    endtry.

    str1 = secs.
    str2 = time.
    value = str1(10) && str2+15(3).

  endmethod.
endclass.
To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply