Untitled

Coder2828 avatar
Coder2828
plain_text
04/15/2026 7:13 AM
1.7 KB
11
Indexable
DATA lt_workitems TYPE TABLE OF swrjwi.
DATA lv_cutoff    TYPE timestamp.

" Calculate 72h cutoff
lv_cutoff = cl_abap_context_info=>get_system_date( ) - 3. " simplification
" Properly use timestamp subtraction in your implementation

" Read open PR approval workitems older than 72h
SELECT wi~wi_id, wi~wi_stat, wi~wi_cd, wi~wi_ct
  FROM swrjwi AS wi
    WHERE wi~wi_stat = 'STARTED'       " workitem is open
        AND wi~task   = 'TS00008267'     " PR approval task ID — verify in your system
            AND wi~wi_cd  <= @lv_cutoff      " created before cutoff
              INTO TABLE @DATA(lt_overdue).

LOOP AT lt_overdue INTO DATA(ls_wi).

  DATA(lv_result) = 'APPROVED'. " or the outcome key your task uses

  CALL FUNCTION 'SAP_WAPI_WORKITEM_COMPLETE'
    EXPORTING
      workitem_id     = ls_wi-wi_id
      actual_agent    = 'WF-BATCH'   " technical user
      do_commit       = abap_true
    EXCEPTIONS
      workitem_id_unknown        = 1
      workitem_wrong_status      = 2
      OTHERS                     = 3.

  IF sy-subrc = 0.
    " Log the skip
    INSERT INTO zpr_approval_skip VALUES
      ( wi_id          = ls_wi-wi_id
        skip_timestamp = cl_abap_context_info=>get_system_date( )
        skip_reason    = '72H_OVERDUE'
        completed_by   = 'WF-BATCH' ).
  ENDIF.

ENDLOOP.


Editor is loading...
Leave a Comment