我正在使用yyyymmddhhmmss格式的时间戳字段的DTP过滤器例程进行。我试图将范围声明为({timestamp 3个月前}至{Current Timestamp})。我是ABAP的新手,并且基本上已经设置了代码,因此没有任何语法错误。当我将其分配给" L_TS"时,我目前很难获得正确的时间戳。
*$*$ begin of routine - insert your code only below this line *-*
BREAK-POINT.
DATA: l_idx LIKE sy-tabix,
l_ts TYPE rstimestmp,
l_ts2 TYPE rstimestmp.
READ TABLE l_t_range WITH KEY
fieldname = 'TIMESTAMP'.
l_idx = sy-tabix.
* Capture the Current Date
l_ts = sy-datlo + sy-timlo.
l_ts2 = ( sy-datlo + sy-timlo ) - 93.
IF l_idx <> 0.
* fill the Selection table.
l_t_range-low = l_ts.
l_t_range-sign = 'I'.
l_t_range-option = 'BT'.
l_t_range-high = l_ts2.
MODIFY l_t_range INDEX l_idx.
ELSE.
* fill the Selection table.
l_t_range-fieldname = 'TIMESTAMP'.
l_t_range-low = l_ts.
l_t_range-high = l_ts2.
l_t_range-sign = 'I'.
l_t_range-option = 'BT'.
APPEND l_t_range.
ENDIF.
p_subrc = 0.
*$*$ end of routine - insert your code only before this line *-*
您正在混合时间戳和离散的日期和时间计算 - 无法使用这种方式。您真正想要的可能是这样的东西:
DATA: l_date TYPE d,
l_time TYPE t,
l_ts TYPE rstimestmp.
FIELD-SYMBOLS: <ls_param> LIKE LINE OF l_t_range.
* ensure that the parameter exists
READ TABLE l_t_range ASSIGNING <ls_param> WITH KEY fieldname = 'TIMESTAMP'.
IF sy-subrc <> 0.
APPEND INITIAL LINE TO l_t_range ASSIGNING <ls_param>.
<ls_param>-fieldname = 'TIMESTAMP'.
ENDIF.
<ls_param>-sign = 'I'.
<ls_param>-option = 'BT'.
* "from" date = three months ago, more or less - probably the start of the day?
l_date = sy-datlo - 93.
l_time = '000000'. " or sy-timlo.
CONVERT DATE l_date TIME l_time INTO TIME STAMP l_ts TIME ZONE sy-zonlo.
<ls_param>-low = l_ts.
* "to" date = today - probably the end of the day?
l_date = sy-datlo.
l_time = '235959'. " or sy-timlo.
CONVERT DATE l_date TIME l_time INTO TIME STAMP l_ts TIME ZONE sy-zonlo.
<ls_param>-high = l_ts.