2012-11-07 141 views
2

我正在爲YYYYMMDDhhmmss格式的時間戳字段使用DTP過濾器例程。我試圖將範圍聲明爲({3個月前的時間戳}到{當前時間戳})。我對ABAP非常陌生,現在基本上已經設置了代碼,所以它沒有任何語法錯誤。當我將它分配給「l_ts」時,我目前無法獲得正確的時間戳填充。DTP例程查找時間戳範圍

*$*$ 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   *-* 

回答

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. 
+0

我不得不做一些編輯,因爲我試圖填充的字段是長度(14),而時間戳類型是長度(15)。另外,分配 -option ='EQ'並沒有給它一個範圍。我必須改變='BT'。否則,這工作完美,是一個很好的學習經驗,謝謝。 – Jared