美文网首页
ABAP时间的转换

ABAP时间的转换

作者: JayDragon | 来源:发表于2019-04-23 12:10 被阅读0次

    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.
    

    相关文章

      网友评论

          本文标题:ABAP时间的转换

          本文链接:https://www.haomeiwen.com/subject/jjsygqtx.html