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
全站熱搜
留言列表