How to Read SAP Workflow Container Contents using ABAP Function Module
ABAP programmer can use ABAP function module SAP_WAPI_READ_CONTAINER to display and read SAP workflow task container contents which are stored as element-value pairs. In this ABAP tutorial, I tried to share sample ABAP codes which can help the developers to use for reading SAP workflow container data.
ABAP programmers can use standart ABAP function module SAP_WAPI_READ_CONTAINER to read the contents of a SAP workflow task container data.
To see how SAP_WAPI_READ_CONTAINER ABAP function module works, let's use a sample work item id. Perhaps before you call SE37 tcode, first call SWIA transaction code (Process Work Item as Administrator) and execute the report and select a sample Work Item ID from the list.
Now we are ready to execute SE37 tcode and paste the function module "SAP_WAPI_READ_CONTAINER" in the FM name input text. Run the function module. Then provide the work item id as the marked WORKITEM_ID import parameter value.
Run ABAP function module SAP_WAPI_READ_CONTAINER to read container data
After you execute the SAP_WAPI_READ_CONTAINER function module, as seen in below screenshot SIMPLE_CONTAINER Table parameter can be used to display the contents of the workitem container data.
Execution results of ABAP function module and Simple_Container with Workflow Item container data
When ABAP programmer clicks on Simple_Container table parameter, as seen in below image the workflow container data is listed as element value pairs.
Execution results of ABAP function module and Simple_Container with Workflow Item container data
If you want to develop an ABAP program which reads workflow container data using SAP_WAPI_READ_CONTAINER function module, you can use following ABAP code sample as a starting point for your report.
DATA gt_simple_container TYPE TABLE OF swr_cont.
CALL FUNCTION 'SAP_WAPI_READ_CONTAINER'
EXPORTING
workitem_id = 446146
* LANGUAGE = SY-LANGU
* USER = SY-UNAME
* BUFFERED_ACCESS = 'X'
* IMPORTING
* RETURN_CODE =
* IFS_XML_CONTAINER =
* IFS_XML_CONTAINER_SCHEMA =
TABLES
simple_container = gt_simple_container
* MESSAGE_LINES =
* MESSAGE_STRUCT =
* SUBCONTAINER_BOR_OBJECTS =
* SUBCONTAINER_ALL_OBJECTS =
.
DATA h1(25) TYPE c VALUE ' Element'.
DATA h2(50) TYPE c VALUE ' Value'.
IF gt_simple_container IS NOT INITIAL.
WRITE:/ h1, h2.
ULINE.
ENDIF.
LOOP AT gt_simple_container INTO DATA(gs_simple_container).
WRITE:/ gs_simple_container-element(25) UNDER h1,
gs_simple_container-value(50) UNDER h2.
ENDLOOP.
Above ABAP program will list all element-value pairs stored in the workflow container content.
ABAP codes to list Workflow container data as key-value pairs
If you work on a specific workflow task, it is possible that you already know the element names of the ABAP workflow container data. If the ABAP programmer is dealing with specific container data of a SAP workflow task, you can directly READ related element from the Simple_Container table parameter.
DATA gt_simple_container TYPE TABLE OF swr_cont.
CALL FUNCTION 'SAP_WAPI_READ_CONTAINER'
EXPORTING
workitem_id = 446146
TABLES
simple_container = gt_simple_container.
IF gt_simple_container IS NOT INITIAL.
READ TABLE gt_simple_container REFERENCE INTO DATA(lr_simple_container) WITH KEY element = 'CAMPAIGN_ID'.
IF sy-subrc = 0.
WRITE: 'Campaign ID', lr_simple_container->value .
ENDIF.
READ TABLE gt_simple_container REFERENCE INTO lr_simple_container WITH KEY element = 'VKBUR'.
IF sy-subrc = 0.
WRITE: 'Sales Office', lr_simple_container->value .
ENDIF.
READ TABLE gt_simple_container REFERENCE INTO lr_simple_container WITH KEY element = 'E_DECISION'.
IF sy-subrc = 0.
WRITE: 'Decision', lr_simple_container->value .
ENDIF.
ENDIF.
Here is the output of the simple ABAP report which displays specific element values from a SAP Workflow task container.
How to read SAP Workflow container contents for specific element
Above ABAP codes work for a given specific SAP Workflow task id. If you need to display data for a given task (like TS90900107, etc) in a defined period the programmer has to loop in the list of work items and call above code block. Of course for a better look-and-feel the workflow container data should be stored in an internal table and the result could be displayed on an ALV grid for a table display.
DATA header1(25) TYPE c VALUE 'WorkItem ID'.
DATA header2(25) TYPE c VALUE 'Campaign ID'.
data s_taskid like swwwihead-wi_rh_task VALUE 'TS90900107'.
DATA gt_simple_container TYPE TABLE OF swr_cont.
SELECT wi_id
FROM swwwihead
INTO TABLE @DATA(lt_swwwihead)
WHERE
wi_rh_task = @s_taskid AND " task id
* wi_cd IN @s_wi_cd AND " create date filter criteria
wi_stat NE 'COMPLETED'.
IF lt_swwwihead IS NOT INITIAL.
WRITE:/ header1, header2.
ENDIF.
LOOP AT lt_swwwihead REFERENCE INTO DATA(lr_swwwihead).
REFRESH gt_simple_container.
CALL FUNCTION 'SAP_WAPI_READ_CONTAINER'
EXPORTING
workitem_id = lr_swwwihead->wi_id
TABLES
simple_container = gt_simple_container.
READ TABLE gt_simple_container REFERENCE INTO DATA(lr_simple_container) WITH KEY element = 'CAMPAIGN_ID'.
IF sy-subrc = 0.
WRITE: /
lr_swwwihead->wi_id UNDER header1,
lr_simple_container->value UNDER header2.
ENDIF.
ENDLOOP.