SAP內時間戳和日期時間的轉換

作者: Barry.bai  來源: ChinaUnix  發布時間: 2008-10-23 17:07  閱讀: 3526 次  推薦: 0   原文鏈接   [收藏]  

 

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

 

0
0
 
 
 

文章列表

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()