SAP内时间戳和日期时间的转换

REPORT  z_barry_test.
 
TABLES: t001w,adrc .
DATA: date LIKE sy-datum,
      time LIKE sy-uzeit,
      tstamp LIKE tzonref-tstamps.
 
SELECT SINGLE * FROM t001w WHERE werks = '0001'.
IF sy-subrc = 0.
  SELECT SINGLE * FROM adrc WHERE addrnumber = t001w-adrnr . "time_zone
  PERFORM date_to_timestamp USING '20080808' '080808' adrc-time_zone
              CHANGING tstamp.
  WRITE tstamp.
ENDIF.
IF NOT tstamp IS INITIAL.
  PERFORM timestamp_to_date USING tstamp adrc-time_zone
              CHANGING date time.
  WRITE / : date,time .
ENDIF.
 
*&---------------------------------------------------------------------*
*&      Form  date_to_timestamp
*&---------------------------------------------------------------------*
*       日期+时间+时区  转变为 时间戳
*----------------------------------------------------------------------*
FORM date_to_timestamp USING i_date LIKE sy-datum
                             i_time LIKE sy-uzeit
                             i_tzone LIKE  tzonref-tzone
                        CHANGING o_tstamp LIKE tzonref-tstamps  .
  CONVERT DATE i_date TIME i_time INTO TIME STAMP o_tstamp TIME ZONE i_tzone.
  CASE sy-subrc.
    WHEN 8.
      MESSAGE e000(oo) WITH '时区错'.
    WHEN 12.
      MESSAGE e000(oo) WITH '时间戳错误'.
    WHEN OTHERS.
  ENDCASE.
ENDFORM.                    "date_to_timestamp
 
*&---------------------------------------------------------------------*
*&      Form  TIMESTAMP_TO_DATE
*&---------------------------------------------------------------------*
*       时间戳+时区 转变为 日期和时间
*----------------------------------------------------------------------*
FORM timestamp_to_date USING   i_tstamp LIKE tzonref-tstamps
                               i_tzone LIKE  tzonref-tzone
                       CHANGING o_date LIKE  sy-datum
                                o_time LIKE  sy-uzeit.
  DATA: w_tzone LIKE tzonref-tzone.
  w_tzone = i_tzone.
  CONVERT TIME STAMP i_tstamp TIME ZONE w_tzone INTO DATE o_date TIME o_time.
  CASE sy-subrc.
    WHEN 8.
      MESSAGE e000(oo) WITH '时区错'.
    WHEN 12.
      MESSAGE e000(oo) WITH '时间戳错误'.
    WHEN OTHERS.
  ENDCASE.
ENDFORM.                    "TIMESTAMP_TO_DATE

你可能感兴趣的:(SAP内时间戳和日期时间的转换)