You have the right to access the workitem container, fully !
Case:
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.
Analysis:
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.
I didn't quite understand this "but the function module does not return, any complex type elements, like multi-line or structure."
The function returns them. Of course for example a structure in the container will come as CHAR255, but it is easy to "convert" into a structure. Well, of course you will loose data, if your structure is larger than 255 characters, so your way is much more reliable.
Thanks again. I will definately use this way, if I come across into a requirement similar of yours.
Regards,
Karri
Hi Pavan ,
Awesome stuff here . It really helped me to extract the container data , using SWC_GET_TABLE after your code snippet . I had a small question can we get the container data using SAP_WAPI_READ_CONTAINER ? I tried using the SWC_GET_TABLE but it dumps . If yes could you guide me how to go about it ?
Thanks and Regards ,
Sheldon Rodrigues
Maybe you already know how to use the SAP_WAPI_READ_CONTAINER? If not, you should find plenty of examples here in SCN by searching.
This function should be your first choice when trying to read WF container. Pavan's was is a more advanced and should be used only if you have some complex & long stuff in the container.
Regards,
Karri
Very intersting this post.
I am using your code to read deep tables (table with complex structures). I wonder how to use the result variable from your function: et_cont_val and et_cont_elem_def.
As this variables will be used directly in Bor method, no need for include <CNTN01>.
So, let's say my complex table, is called ZCOMPLEX_TAB.
I will have several entries with this name in et_cont_val and 1 entry in et_cont_elem_def.
I need to pass this table in function parameter, so how do I use et_cont_val and et_cont_elem_def?
Thank you in advance.
Regards,
Carla
Here's the code: an image doesn't really help when you want to quickly determine if it will work, manual typing long lines of code is not ideal. Text to copy and paste is...
data: lv_wiid type sww_wiid,
lcl_workitem_context type ref to cl_swf_run_workitem_context,
lcl_oref type ref to cx_root,
lv_text type string,
lcl_wi_cnt type ref to cl_swf_cnt_container,
lif_wi_cnt type ref to if_swf_ifs_parameter_container,
liv_wi_conv type ref to if_swf_cnt_conversion,
lt_cont_vals type swconttab,
lt_cont_defs type swbconttab.
try.
call method cl_swf_run_workitem_context=>get_instance
exporting
im_wiid = lv_wiid
receiving
re_instance = lcl_workitem_context.
catch cx_swf_run_wim into lcl_oref.
lv_text = lcl_oref->get_text( ).
endtry.
call method lcl_workitem_context->if_wapi_workitem_context~get_wi_container
receiving
re_container = lif_wi_cnt.
lcl_wi_cnt ?= lif_wi_cnt.
try.
call method lcl_wi_cnt->if_swf_cnt_conversion~to_bor_container
exporting
tunnel_non_bor_handles = 'X'
convert_bor_handles = 'X'
convert_to_runtime = 'X'
importing
values = lt_cont_vals
definition = lt_cont_defs.
catch cx_swf_cnt_element into lcl_oref.
lv_text = lcl_oref->get_text( ).
endtry.
Hi Pavan,
First of all thanks for this blog. I have a question does this approach help if I have a field in my structure which is more than 255 chars suppose 800 or 1000 chars. I tried the above code but while converting to BOR the fields with 800 chars gets excluded as there is check in the standard FM for 255 chars. Can you please let me know if we can read if the structure contains fields which are individually more than 255 chars.