SAP Workflow : Dynamic Deadline Monitoring
October 5, 2020

Step 1: Configure Deadline Monitoring for the task

I have used the blog from Arun B on Deadline Monitoring – Escalation on Latest End to configure the Deadline Monitioring for SAP Workflow task. The result is that workflow is triggered and decision task has default escalation or latest end as per the configurations mentioned in the task.

Configure the Latest End
Outcome was added as per the Latest End configuration

Step 2: Configure the Program Exits to modify the Deadline

Configure a program exits for the decision task. So that we can update the various Workflow Task properties and take required actions at different stages of a Workflow Task.

  1. ABAP Class is used for Workflow Program eixts, add the interface “IF_SWF_IFS_WORKITEM_EXIT” to the Class to be used for Program Exits
  2. Mention the Class to be used for Program Exits in the Workflow Task
Add Workflow Exit interface to the ABAP Class
Mention the Class to be used for Program Exits of the given Workflow Task

Step 3: Code the Dynamaic Deadline Update

As a result of Step 2, default method “IF_SWF_IFS_WORKITEM_EXIT~EVENT_RAISED” is added to the ABAP Class. This method can be used to handle all the events of SAP Workflow Task.

  1. After Creation event of the Task is used to handle the dynamic deadline scenario
  2. You can store the the dynamic deadline offset value in a custom table or using SAP Selection Variant Table (TVARVC)
  3. Fetch the Deadline Offset values, ( I am using seconds as offset values so that it helps me to faster testing. Its your choice, use as it suits you )
  4. Method TD_ADD ( Addition of Duration in Seconds to Date/Time Pair ) of the class CL_ABAP_TSTMP ( Arithmetic and Conversion for Time Stamps ) to add the offset value.
  5. Update the Latest End deadline using the FM “SWW_WI_DEADLINES_CHANGE” ( Change Deadline Attributes of Work Item (Types W, E, F, and B) )
DATA: lv_init_date TYPE sydatum,
      lv_init_time TYPE syuzeit,
      lt_deadline  TYPE STANDARD TABLE OF swwdeadlin.

IF im_event_name EQ swfco_event_after_creation.         " After Creation

  DATA(lv_wi_id) = im_workitem_context->get_workitem_id( ).

  lv_init_date = sy-datum.
  lv_init_time = sy-uzeit.


  " Get Escalation In Seconds
  me->get_escalation_time(
    IMPORTING
      ev_escalation_time = DATA(lv_esc_time)
  ).
  TRY.
      " Add Offset Time
      cl_abap_tstmp=>td_add(
        EXPORTING
          date     = lv_init_date
          time     = lv_init_time
          secs     = lv_esc_time
        IMPORTING
          res_date = DATA(lv_latest_date)
          res_time = DATA(lv_latest_time)
      ).
      
      " Update Deadline Details
      APPEND INITIAL LINE TO lt_deadline ASSIGNING FIELD-SYMBOL(<lfs_dline>).
      <lfs_dline>-wi_dattype = swfco_latest_end.           " Deadline Type : latest End
      <lfs_dline>-wi_date = lv_latest_date.                " Deadline Date
      <lfs_dline>-wi_time = lv_latest_time.                " Deadline Time
      <lfs_dline>-wi_action = swfco_wim_deadline_callback. " Deadline Action to be taken

      " Update Deadline
      CALL FUNCTION 'SWW_WI_DEADLINES_CHANGE'
        EXPORTING
          wi_id               = lv_wi_id
        TABLES
          deadline_attributes = lt_deadline
        EXCEPTIONS
          no_authorization    = 1
          invalid_type        = 2
          update_failed       = 3
          invalid_status      = 4
          OTHERS              = 5.
      IF sy-subrc <> 0.
      ENDIF.

    CATCH cx_parameter_invalid_type cx_parameter_invalid_range.
  ENDTRY.

ENDIF.