You have the right to access the workitem container, fully !
I came across a requirement, where I need to read the work item container, which had a combination of complex and simple container element types. Initially, when I started, I felt this could be done with in minutes…, but later it made my hands black. Yes, some one might be laughing by looking at requirement, but the fact is fact…
Initially tried to read the work item container by using, standard SAP function module “SAP_WAPI_READ_CONTAINER”, but the function module does not return, any complex type elements, like multi-line or structure. Later, started to search for the function module, which returns the container instance, and this was the point where I started R&D and finally found the instance of the work item to get full access on it and read the elements irrespective of the their type.
The blog not only discusses, how to read container elements, but also presents how to get a full access on the work item and the approach too.
I started by developing a function module, The only thing which I was trying to determine, the context of the workitem, the instance of the work item context interface “IF_WAPI_WORKITEM_CONTEXT” then, I could easily access the work item container elements of any type, I remember how program exit is implemented and used in workflow.
The class responsible for implementing the interface is “CL_SWF_RUN_WORKITEM_CONTEXT”, and instantiating this was too simple by calling the static method of the class “GET_INSTANCE”. Once the class is instantiated, get the current instance of the work item container by using the interface (if_wapi_workitem_context) method “GET_WI_CONTAINER”.
Now at this point, one thing has to be noted that, a work item container can have multiple elements and in that, there could be any number of multi-line container elements and structures too, so the parameter interface of the function module must be in a generalized way where by using a parameter one should be able to access the whole work item container elements.
This could be done by simply converting the container instance to a BOR container. This could be only possible if the interface “IF_SWF_CNT_CONVERSION” is instantiated, so the instance of the work item container is converted to class “CL_SWF_CNT_CONTAINER”, this is because the interface if_swf_cnt_container, of the work item container is implemented in the same class, where we have the facility to even access the methods responsible for converting the container.
That’s all 😆 .
Implementation of analysis:
Accessing Fully the work item container:
In order to access the result of the function module, i;e the values inside the workitem container, make use of the SWC_GET_ELEMENT, SWC_GET_TABLE macros. If the above function module is called from a class method then , first make sure that you have included INCLUDE cntn01_swc, in the class local types –> macros. Then by using the macro SWC0_GET_TABLE , SWC0_GET_ELEMENT one should be able to access the container element into the class method.
In case of remote function calls, the code can be used inside a wrapper function module.