DTP例程查找时间戳范围

时间:2012-11-07 21:55:05

标签: sap abap

我正在使用格式为YYYYMMDDhhmmss的时间戳字段的DTP过滤器例程。我试图将范围声明为({timestamp 3个月前}到{当前时间戳})。我对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         *-* 

1 个答案:

答案 0 :(得分:3)

你混淆了timestamps和离散的date and time calculations - 不会这样做。你真正想要的可能是这样的:

  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.