Tag Archives: SD

ABAP useful info, pages, videos

Creating QR code in ABAP
https://www.youtube.com/watch?v=DQdKnmon8II

System Conversion to SAP S/4HANA (Part 1), #SAP TechEd Lecturehttps://www.youtube.com/watch?v=X78G2n5ttR0

SAP SD – EDI/ALEhttps://www.youtube.com/watch?v=Y0QoXFa_Yo4&list=PLJumA3phskPHjbd-dsViJ1Kg8L7AKZdDT&index=33

Output Configuration and Determination in SAP SD
https://www.erpdb.info/output-configuration-determination-sap-sd/

Convert SAP C4C timestamp / date field to ABAP timestamp, date and time

In SAP C4C the date/time fields are usually coming in the following format
/Date(1681862400000)/

This 1681862400000 number is actually a seconds since fixed date. You can use the following code to convert a string from C4C to ABAP timestamp (data type TIMESTAMP = DEC15).
In variable LV_ABAP_TS is the value in TIMESTAMP format, and in LV_DATE and LV_TIME you have the date and time respectively in ABAP format too.

  lv_c4c_time = '/Date(1681862400000)/'.
  lv_len = strlen( lv_c4c_time ).
  IF lv_len < 8.
    write: / 'error_converting'.
    exit.
  ENDIF.

  IF substring( val = lv_c4c_time off = 0 len = 6 ) EQ '/Date('.
    DATA(lv_last2) = lv_len - 2.
    IF substring( val = lv_c4c_time off = lv_last2 len = 2 ) EQ ')/'.
      lv_last2 = lv_last2 - 6.
      lv_c4c_time = substring( val = iv_c4c_time off = 6 len = lv_last2 ).
    ELSE.
      write: / 'error_converting'.
      exit.
    ENDIF.
  ENDIF.

  CALL METHOD cl_pco_utility=>convert_java_timestamp_to_abap
    EXPORTING
      iv_timestamp = lv_c4c_time
    IMPORTING
      ev_date      = lv_date
      ev_time      = lv_time
      ev_msec      = lv_msec.

  CONVERT DATE lv_date TIME lv_time 
    INTO TIME STAMP lv_abap_ts 
    TIME ZONE 'UTC'.

If you are wondering what’s inside “convert_java_timetamp_to_abap” method:

METHOD convert_java_timestamp_to_abap.
  DATA:
    lv_date        TYPE sy-datum,
    lv_days_i      TYPE i,
    lv_sec_i       TYPE i,
    lv_timestamp   TYPE timestampl,
    lv_timsmsec    TYPE timestampl.
  CONSTANTS:
    lc_day_in_sec TYPE i VALUE 86400.

* IV_TIMESTAMP stores milliseconds since January 1, 1970, 00:00:00 GMT
  lv_timestamp = iv_timestamp / 1000.   "timestamp in seconds
* One day has 86400 seconds: Timestamp in days
  lv_days_i    = lv_timestamp DIV lc_day_in_sec.
  lv_date      = '19700101'.
  ev_date     = lv_date + lv_days_i.
* Rest seconds (timestamp - days)
  lv_sec_i    = lv_timestamp MOD lc_day_in_sec.
  ev_time     = lv_sec_i.
* Rest sec and milli seconds
  lv_timsmsec  = lv_timestamp MOD lc_day_in_sec.
  lv_timsmsec  = lv_timsmsec - lv_sec_i.
  ev_msec      = lv_timsmsec * 1000.

ENDMETHOD.