White Paper: Workflow, Webdynpro and UWL integration
Case Study:
The below solution speaks about the custom approval/rejection screen built with custom webdynpro and registered with
Universal Worklist Configuration (UWL).
For a business process flow solution development, an approval screen is needed which will do line item level approval/rejection
along with comments. For this requirement, it is not feasible to go with standard SAP workflow dialog screen.
So, custom webdynpro is needed which should incorporate the table UI with approval/rejection and comments box.
Also, workflow deadline features a restricted option. Our requirement wants a custom deadline monitoring which will send
remainder mails every n days (or whatever will be maintained in Z config) with a flexibility of changing the interval from the Z
config.
Therefore, we need to go for a solution as:
1. Workflow with custom deadline monitoring
2. Custom Webdynpro for line item based approval/rejection
3. Integration with UWL
Solution:
Workflow:
Create new workflow template in SWDD
Below design blocks are needed for the workflow.
Deadline initialization for the first time
we can determine the deadline date/time by using the FM
END_TIME_DETERMINE passing the current system date/time &
Deadline duration by reading from the config table
Approval step is designed which is just an activity step in workflow
a. In order to restrict the opening of this dialog activity step in SWBP, we use
the object type & method:
CL_HRASR00_WF_COMPONENTS-> WI_EXECUTION_VIA_R3_INBOX
b. The step needs to be modified with the latest end deadline date/time
information which we get from the above deadline initialization step and the outcome
will be modeled.
Prepared by Amalendu Pandit (SAP ABAP & Data Migration Consultant, Wipro Technologies)
White Paper: Workflow, Webdynpro and UWL integration
c. An execution flag variable needs to be defined in workflow container
which will define the execution state of the dialog workitem.
d. Rule resolution is done to retrieve the agent for the dialog approval workitem
This is heart and soul of the custom deadline monitoring.
The below steps are inserted in the Latest End branch of the activity step
a. Wait step is inserted to introduce a dummy wait with the requested start
equal to the deadline date/time determined previously.
Logic: Latest end is given to the dialog workitem. It means it will trigger deadline
after the concerned the deadline date/time. Now, same deadline date/time is
assigned to requested start of the dummy wait step. So, wait step will be executed
when the deadline date/time has passed.
b. After the wait time, insert necessary steps line fetching approvers email,
sending email, etc.
c. Further initialize the deadline determining the new deadline date/time.
d. This entire branch will go in loop with the condition:
Event binding with workflow configuration:
Bind event with the workflow template in SWE2:
Prepared by Amalendu Pandit (SAP ABAP & Data Migration Consultant, Wipro Technologies)
White Paper: Workflow, Webdynpro and UWL integration
Sample Code:
DATA: lo_event_param TYPE REF TO if_swf_ifs_parameter_container,
l_event
TYPE REF TO if_swf_evt_event,
l_event_ref
TYPE REF TO cl_swf_evt_event.
DATA: l_event_id TYPE swe_evtid.
* Event raise...
* ZSC_IM_APP -> RAISE_APPROVAL_WF
IF lt_im_pur_s01_item IS NOT INITIAL.
lo_event_param = cl_swf_evt_event=>get_event_container(
im_objcateg = c_objcateg
im_objtype
= c_obj_type
im_event
= c_event
).
* Class is used as internal table passing through macro is quite unstable.
* Setting container through class...
lo_event_param->set(
EXPORTING
name
= 'ITEM_RECORDS'
value
= lt_im_pur_s01_item
).
* Get event id...
l_event = cl_swf_evt_event=>get_instance(
im_objcateg
= c_objcateg
im_objtype
= c_obj_type
im_event
= c_event
im_objkey
= c_obj_key
im_event_container = lo_event_param
).
* Raise event...
l_event->raise( ).
COMMIT WORK AND WAIT.
l_event_ref ?= l_event.
l_event_id = l_event_ref->get_event_id( ).
WAIT UP TO 2 SECONDS.
* Fetch the workitem id by event id through table SWW_WI2OBJ...
SELECT SINGLE wi_id INTO lw_reckey
FROM sww_wi2obj
WHERE catid EQ 'CL'
AND instid EQ l_event_id
AND typeid EQ 'CL_SWF_UTL_EVT_IDENTIFIER'.
Prepared by Amalendu Pandit (SAP ABAP & Data Migration Consultant, Wipro Technologies)
White Paper: Workflow, Webdynpro and UWL integration
Webdynpro:
Create webdynpro in SE80 as below:
The above webdynpro screen consists of header records, a table UI with approval/rejection radio button beside each record,
comments box (not in the screengrab as it is on the extreme RHS) and finally a SUBMIT button on the top.
For the table UI, below columns are inserted along with the record structure fields.
WINDOW definition for UWL integration:
A window is defined with interface option selected. (This ensures that the window is visible to the external interface that interacts
with it. (in this case, UWL) Now, we need to handle the workitem id coming from the UWL into webdynpro through defining an
event handler for default startup INBOUND PLUG.
Prepared by Amalendu Pandit (SAP ABAP & Data Migration Consultant, Wipro Technologies)
White Paper: Workflow, Webdynpro and UWL integration
Define parameter WI_ID in the method. This WI_ID variable name should be exact as should be defined in SWFVISU tcode for
integration. (Integration part, we will discuss below in detail later.)
And then, do the necessary activities.
Sample code:
wd_comp_controller->wi_id = wi_id.
CALL FUNCTION 'SWI_GET_ROOT_WORKITEM'
EXPORTING
wi_id
= wi_id
IMPORTING
root_item
= root_item
EXCEPTIONS
workitem_does_not_exist = 1
OTHERS
= 2.
IF sy-subrc EQ 0.
wi_runtime_ctxt = cl_swf_run_workitem_context=>get_instance(
im_wiid = root_item-wi_id
).
wi_cont_int = wi_runtime_ctxt->if_wapi_workitem_context~get_wi_container( ).
wi_cont_int->get(
EXPORTING
name
= 'APP_ITEMS'
IMPORTING
value
= wd_comp_controller->item_records
).
Context for the view:
Prepared by Amalendu Pandit (SAP ABAP & Data Migration Consultant, Wipro Technologies)
White Paper: Workflow, Webdynpro and UWL integration
ITEM_RECORDS: Records for approval/rejection. It also contains approval and rejection flag for runtime values.
NO_RECORDS: variable for dynamic handling of the total no of records. This is used to avoid unnecessary empty lines in the table.
CREATED_BY: workitem created by
CREATED_ON: workitem created on
NOTE: Variable handler for long text for comments.
SUMB_ENABLE: Variable for SUBMIT enable/disable property.
Methods:
WD_INIT:
Initially the property of the SUMIT button enable is set to true.
WDDOMODIFYVIEW:
date/time/status.
For the first time, the approval flag is set for all items. And the header values for display are set like
ONACTIONAPPROVE_REC:
Action handler for approval radio button. Set the flag to true.
ONACTIONREJECT_REC:
Action handler for approval radio button. Set the flag to true.
ONACTIONONSUBMIT: Handler for submit button. This does the entire logic from the processing of the approval/rejection of the
records to the completion of the dialog workitem. (N.B.: In this scenario, we have to take care of completion of the workflow as
this is custom solution)
Processing logic pseudo code snippet:
1.
2.
3.
4.
Fetch the context record internal table.
Get Comment (NOTE) attribute from context.
If any rejected item is there, put an error validation message for entering comments if the comments box is empty.
Store the long text in comments box in long text object.
ls_head-tdobject = < Object name >.
ls_head-tdname = < Object key >.
We have dialog workitem key.
ls_head-tdid = 'Object ID'.
ls_head-tdspras = 'E'.
Finally, store the long text in an internal table of TLINE and save the text to DB using FM SAVE_TEXT.
5. Do necessary post processing with the approved/rejected item records.
6. Once everything is successful, reserve the workitem using FM SAP_WAPI_RESERVE_WORKITEM. This is done to avoid
any other user to execute the workitem later, if anything goes wrong here. Same user will execute the workitem next time.
Sample call:
CALL FUNCTION 'SAP_WAPI_RESERVE_WORKITEM'
EXPORTING
workitem_id = wd_comp_controller->wi_id
actual_agent = sy-uname
do_commit
= 'X'
IMPORTING
return_code = return_code.
7. Get the root/parent workitem container for the container update, if required.
Sample call:
CALL FUNCTION 'SWI_GET_ROOT_WORKITEM'
EXPORTING
wi_id
= wd_comp_controller->wi_id
IMPORTING
root_item
= root_item
EXCEPTIONS
workitem_does_not_exist = 1
OTHERS
= 2.
Prepared by Amalendu Pandit (SAP ABAP & Data Migration Consultant, Wipro Technologies)
White Paper: Workflow, Webdynpro and UWL integration
8. Container update:
Sample code:
DATA: wi_runtime_ctxt TYPE REF TO cl_swf_run_workitem_context,
wi_cont_int TYPE REF TO if_swf_ifs_parameter_container,
wi_cont_cl TYPE REF TO cl_swf_cnt_container.
wi_runtime_ctxt = cl_swf_run_workitem_context=>get_instance(
im_wiid = root_item-wi_id
).
wi_cont_int = wi_runtime_ctxt->if_wapi_workitem_context~get_wi_container( ).
wi_cont_cl ?= wi_cont_int.
wi_cont_cl->if_swf_cnt_element_access_1~element_set_value(
EXPORTING
name
= 'APP_ITEMS'
value
= lt_items
).
wi_cont_cl->save_to_database( ).
wi_runtime_ctxt->publish( ).
9. Complete the workitem:
Sample code:
CALL FUNCTION 'SAP_WAPI_WORKITEM_COMPLETE'
EXPORTING
workitem_id = wd_comp_controller->wi_id
actual_agent = sy-uname
do_commit
= 'X'
IMPORTING
return_code = return_code.
10. Finally, if everything is successful, return a success message to the user and then disable the SUMIT button. This is done to
avoid further click on the SUBMIT button as already post processing is completed.
Sample code:
lv_sumb_enable = abap_false.
lo_el_context = wd_context->get_element( ).
lo_el_context->get_attribute(
EXPORTING
name = `SUMB_ENABLE`
IMPORTING
value = lv_sumb_enable ).
Finally, generate a webdynpro application.
Prepared by Amalendu Pandit (SAP ABAP & Data Migration Consultant, Wipro Technologies)
White Paper: Workflow, Webdynpro and UWL integration
Sample UWL & Webdynpro approval screen:
Integration of webdynpro with UWL:
Tcode SWFVISU is provided by SAP to integrate workflow dialog task with UWL.
1. The activity step we designed in the workflow the task name we will need to give in the config here.
2. Then selecting the record, navigate to Visualization Parameter and configure as below:
Prepared by Amalendu Pandit (SAP ABAP & Data Migration Consultant, Wipro Technologies)
White Paper: Workflow, Webdynpro and UWL integration
Portal Config:
1. Go to Portal System Administration Universal Worklist & Workflow (on the left hand side) Universal Worklist Administration.
2. Under the Universal Worklist - Administration, select the desired system alias and re-register.
The config from SWFVISU will flow to portal and re-registers it.
This marks the end of the technical configuration which will set the entire approval webdynpro
integration with workflow and UWL and the application is good to go.
Prepared by Amalendu Pandit (SAP ABAP & Data Migration Consultant, Wipro Technologies)