SAP数据库表中的时间是根据系统时区存储的,这里需要将时间转换成用户时区。
首先获取系统时区:
DATA tzone_sy TYPE TZNZONE.
CALL FUNCTION 'GET_SYSTEM_TIMEZONE'
IMPORTING
timezone = tzone_sy
EXCEPTIONS
customizing_missing = 1
OTHERS = 2.
然后获取用户时区:
DATA tzone_ur TYPE TZNZONE.
CALL FUNCTION 'TZON_GET_USER_TIMEZONE'
EXPORTING
if_username = sy-uname
IMPORTING
ef_timezone = tzone_ur
EXCEPTIONS
no_timezone_customizing = 1
no_valid_user = 2
OTHERS = 3.
下面就是转换用到的两个函数了:
DATA: timestamp TYPE timestamp,
locatime TYPE sy-timlo.
LOOP AT gt_list INTO ls_list.
CLEAR: timestamp,locatime.
CALL FUNCTION 'IB_CONVERT_INTO_TIMESTAMP'
EXPORTING
i_datlo = ls_list-ersda
i_timlo = ls_list-erzet
i_tzone = tzone_sy
IMPORTING
e_timestamp = timestamp.
CALL FUNCTION 'IB_CONVERT_FROM_TIMESTAMP'
EXPORTING
i_timestamp = timestamp
i_tzone = tzone_ur
IMPORTING
e_timlo = locatime.
...
...
...
ENDLOOP.
网友评论