Powered By

Free XML Skins for Blogger

Powered by Blogger

Friday, October 10, 2008

How to change the deadline of the workitem programmatically in SAP?

Following code is used to changes the deadline of any work item which is in WAITING state. The FMs needs the input like the object type for which the workflow has executed, the workflow ID to which the workitem belongs and the Task id of the standard task which is executed and in waiting state.

DATA: lit_deadline TYPE TABLE OF swwdeadlin,
lt_workitem TYPE TABLE OF swr_wihdr,
lt_rel_wi TYPE TABLE OF swwwihead,
w_workitem TYPE swr_wihdr,
w_rel_wi TYPE swwwihead,
w_deadline TYPE swwdeadlin,
l_objkey TYPE swo_typeid,
l_retcode TYPE sy-subrc.
* Retrieve the work items executed for desired Object type
CALL FUNCTION 'SAP_WAPI_WORKITEMS_TO_OBJECT'
EXPORTING
objtype = l_objtype
objkey = l_objkey
top_level_items = space
selection_status_variant = '0001'
IMPORTING
return_code = l_ret_code
TABLES
worklist = lt_workitem.
* Select the workitems executed for particular Workflow.
SORT lt_workitem BY wi_rh_task wi_stat.
READ TABLE lt_workitem
INTO w_workitem
WITH KEY wi_rh_task = 'WS91001143'
wi_stat = 'STARTED'
BINARY SEARCH.
* Select the dependent workitems of 'WS91001143'.
CALL FUNCTION 'SWI_GET_DEPENDENT_WORKITEMS'
EXPORTING
wi_id = w_workitem-wi_id
TABLES
dependent_wis = lt_rel_wi.
* Select the workitems for which the deadline needs to be changed.
SORT lt_rel_wi BY wi_rh_task wi_stat.
READ TABLE lt_rel_wi
INTO w_rel_wi
WITH KEY wi_rh_task = 'TS91001414'
wi_stat = 'WAITING'
BINARY SEARCH.
* Update the deadline of the waiting task.
w_deadline-wi_dattype = 'DS'.
w_deadline-wi_date = l_new_date.
w_deadline-wi_time = '000001'.
APPEND w_deadline TO lt_deadline.
CALL FUNCTION 'SWW_WI_DEADLINES_CHANGE'
EXPORTING
wi_id = w_rel_wi-wi_id
do_commit = 'X'
TABLES
deadline_attributes = lt_deadline
EXCEPTIONS
no_authorization = 1
invalid_type = 2
update_failed = 3
invalid_status = 4
OTHERS = 5.
if sy-subrc <> 0.

endif.

No comments:

Archives