2

我正在为格式为 YYYYMMDDhhmmss 的时间戳字段开发 DTP 过滤器例程。我试图将范围声明为({timestamp 3 months ago} 到 {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         *-* 
4

1 回答 1

3

您正在混淆时间戳和离散的日期和时间计算- 不会以这种方式工作。你真正想要的可能是这样的:

  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.
于 2012-11-07T22:21:04.540 回答