Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
Showing results for 
Search instead for 
Did you mean: 
Former Member

Business Scenario:

The SAP system must record all the intermediate values of different variables in a Workflow process. Standard SAP Workflow report does not provide all the Workflow and Task container values in a single row. It is necessary to store these variables for the purpose of detailed reporting and auditing.

This document provides a custom solution for capturing run time container values in a Purchase Requisition release workflow.

Purchase Requisition Release Workflow example

For the purpose of demo, consider Standard Purchase Req. Release Workflow - WS20000077. A new activity step with a dialog task ‘Request Rejection Reason’ has been added to the outcome ‘Release Refused’. This task prompts the Reviewer to provide a Rejection / Refusal Reason.


This new container variable ‘Rejection Reason’ is not available for End Users within any standard Workflow report.

The container values can be captured by implementing Programming exit in to a sample database table as shown below.

Implement Workflow Programming Exit

  • Call Transaction ‘SE24’ – Class Builder and enter a Z class object type name ‘ZCL_PR_WORKITEM_EXIT’ and click ‘Create’

  • On the Subsequent popup – enter a description for the class.

  • Choose instantiation type as ‘Public’ since we want all components of this class to be accessible within the Workflow. Click ‘Save’.

  • Next go to Interfaces tab and enter Interface name as ‘IF_SWF_IFS_WORKITEM_EXIT’

  • Since class ‘ZCL_PR_WORKITEM_EXIT’ is implementing interface ‘IF_SWF_IFS_WORKITEM_EXIT’, the method EVENT_RAISED of the interface gets automatically available to this class.

  • Double click on the method – ‘IF_SWF_IFS_WORKITEM_EXIT~EVENT_RAISED’ and write the following code:

METHOD if_swf_ifs_workitem_exit~event_raised.


* This exit is called by the workflow system at different stages of work item

* processing e.g. before creation, before execution, after execution etc.


* Data Declaration

  DATA: ls_wihead             TYPE swr_wihdr.

*       Workflow Container object

  DATA: l_wf_cont             TYPE REF TO if_swf_ifs_parameter_container,

*       Task Container object

        l_wi_cont             TYPE REF TO if_swf_ifs_parameter_container.

  DATA :

        ls_pr_wf_values       TYPE zpr_wf_values,

        l_value               TYPE string,

        l_rej_reason          TYPE zrej_reason.

* Fetch Current Work Item Header

  ls_wihead = im_workitem_context->get_header( ).

* Skip This exit if the Work item status is ERROR

  CHECK ls_wihead-wi_stat NE swfco_wi_status_error

  AND   ls_wihead-wi_stat NE swfco_wi_status_excpcaught

  AND   ls_wihead-wi_stat NE swfco_wi_status_excphandlr.

* Fetch Workflow Container

  l_wf_cont = im_workitem_context->get_wf_container( ).

* Fetch Work Item Container

  l_wi_cont = im_workitem_context->get_wi_container( ).

* Check for current Event

  CASE im_event_name.

*   Event 'State Changed' indicates that the Work Item now has a new processing status

    WHEN swrco_event_state_changed.

*     The 'Rejection Reason' will be available in Work Item container only after Execution of Work item

      IF ls_wihead-wi_stat = swfco_wi_status_completed. " STATUS - COMPLETED

        CLEAR l_value.

        CALL METHOD l_wi_cont->get


            name  = 'RejectionReason'


            value = l_value.

        WRITE l_value TO ls_pr_wf_values-rej_reason.

*       Also fetch Release code from Workflow container

        CLEAR l_value.

        CALL METHOD l_wf_cont->get


            name  = 'ReleaseCode'


            value = l_value.

        WRITE l_value TO ls_pr_wf_values-REL_CODE.

*       Store Rejection date and time

        MOVE :

             sy-datum               TO ls_pr_wf_values-rej_date,

             sy-uzeit               TO ls_pr_wf_values-rej_time..

*       Store Reviewer name

        CLEAR l_value.

        MOVE ls_wihead-wi_aagent  TO ls_pr_wf_values-reviewer.

*       Store Purchase Req.number from new task variable - Purchase Req.

        CLEAR l_value.

        CALL METHOD l_wi_cont->get


            name  = 'PurchaseReq'


            value = l_value.

        WRITE l_value TO ls_pr_wf_values-banfn.

*       Update the PR Workflow values table

        MODIFY zpr_wf_values FROM ls_pr_wf_values.

*       Do not write COMMIT statement in this Program Exit

*       The database table will be committed along with Workflow internal

*       COMMIT





  • Save and Activate Class ZCL_PR_WORKITEM_EXIT

  • Double click on the new task ‘Request Rejection Reason’ and go to tab ‘Program Exits’ and specify the newly create class ZCL_PR_WORKITEM_EXIT

  • Save and Activate Workflow template.

Working DEMO

  • Reviewer of Purchase Requisition hits the Reject Button

  • Reviewer is prompted to enter the Rejection Reason

  • Custom table ZPR_WF_VALUES now contains the runtime container values.

Labels in this area