ABAP 随机时间戳解码问题 SOTR_MESS 032

场景:我们这边有个推企业API的接口,因为接口逻辑是必须按主体去推送。当按主体推送的时候就会涉及到批量的问题,为了方便记录传输记录,每次我都会生成一个新的token。

生成token的参数中涉及到一个timestamp,也就是时间戳。这个时间戳是JAVA的时间戳,在使用ABAP生成的时候我做了个转码:代码如下


    data time type tzntstmpl.
    data str1 type string.
    data str2 type string.
    data tstmp1 type p.
    data tstmp2 type p.
    data secs type tzntstmpl.

    TYPES:BEGIN OF TY_DATA,
            TSTMP1 LIKE TSTMP1,
            TSTMP2 LIKE TSTMP1,
            STR1 TYPE STRING,
            STR2 TYPE STRING,
            TIME_13 TYPE STRING,
            MESSAGE TYPE STRING,
          END OF TY_DATA.

    DATA:LS_DATA TYPE TY_DATA.
    DATA:LT_ZAFL_LOG TYPE TABLE OF ZAFL_LOG,
         LS_ZAFL_LOG LIKE LINE OF LT_ZAFL_LOG.

    TRY.
      GET TIME STAMP FIELD TIME.
    CATCH CX_ROOT INTO DATA(LS_ROOT) .
      LS_DATA-MESSAGE = LS_ROOT->GET_LONGTEXT( ).
    ENDTRY.



    tstmp1 = time.
    tstmp2 = '19700101000000'.

    try.
        secs = cl_abap_tstmp=>subtract(
          tstmp1 = tstmp1
          tstmp2 = tstmp2
        ).
      catch cx_parameter_invalid_range .

      catch cx_parameter_invalid_type .

    endtry.

    str1 = secs.
    str2 = time.
    TIME_13 = str1(10) && str2+15(3).

接着,诡异的事情出现了,如果调一次的时候基本没什么问题,但是当批量调的时候就会出现token生成失败的问题。后面做了日志发现

当 GET TIME STAMP FIELD TIME. 生成的TIME 以60结尾的时候,比如"20220812111160",通过cl_abap_tstmp=>subtract去获取时间戳就会有问题,报错是SOTR_MESS 032。

具体原因是在:TSTMP2SECS 的42行做时间戳解析的时候报异常了

在这里插入图片描述

在这里插入图片描述

解决办法:
在异常报错处wait一个非整秒,然后重新执行

    data time type tzntstmpl.
    data str1 type string.
    data str2 type string.
    data tstmp1 type p.
    data tstmp2 type p.
    data secs type tzntstmpl.

    TYPES:BEGIN OF TY_DATA,
            TSTMP1 LIKE TSTMP1,
            TSTMP2 LIKE TSTMP1,
            STR1 TYPE STRING,
            STR2 TYPE STRING,
            TIME_13 TYPE STRING,
            MESSAGE TYPE STRING,
          END OF TY_DATA.

    DATA:LS_DATA TYPE TY_DATA.
    DATA:LT_ZAFL_LOG TYPE TABLE OF ZAFL_LOG,
         LS_ZAFL_LOG LIKE LINE OF LT_ZAFL_LOG.

    TRY.
      GET TIME STAMP FIELD TIME.
    CATCH CX_ROOT INTO DATA(LS_ROOT) .
      LS_DATA-MESSAGE = LS_ROOT->GET_LONGTEXT( ).
    ENDTRY.



    tstmp1 = time.
    tstmp2 = '19700101000000'.

    try.
        secs = cl_abap_tstmp=>subtract(
          tstmp1 = tstmp1
          tstmp2 = tstmp2
        ).
      catch cx_parameter_invalid_range .
          WAIT UP TO '0.18' SECONDS.
          GET TIME STAMP FIELD TIME.
          tstmp1 = time.

          secs = cl_abap_tstmp=>subtract(
            tstmp1 = tstmp1
            tstmp2 = tstmp2
          ).

      catch cx_parameter_invalid_type .
          WAIT UP TO '0.18' SECONDS.
          GET TIME STAMP FIELD TIME.
          tstmp1 = time.

          secs = cl_abap_tstmp=>subtract(
            tstmp1 = tstmp1
            tstmp2 = tstmp2
          ).
    endtry.

    str1 = secs.
    str2 = time.
    TIME_13 = str1(10) && str2+15(3).
posted @ 2022-08-15 11:15  linhuang  阅读(29)  评论(0编辑  收藏  举报  来源