Posted: Thu Feb 19, 2009 3:23 pm Post subject: Logically delete workflow instances matching specifications
Author: Kjetil Kilhavn KJETILK at statoil.com
I suggest we all quit yapping about this before WW III starts.
Here's a little program for those who need to cancel specific work items, and that will be the last time I answer a question about logical deletion unless I forget to don't answer them in the future.
Quote:
Sym. Text dLen mLen
L01 Work items successfully cancelled: 34 45
L02 Work items where cancellation failed: 37 45
L03 Discarded input data: 21 45
SB1 Work item IDs specified in file 31 50
SB2 Selection based on workflow header 34 50
SB3 Level of detail in output from report 37 50
Name Text Dict.
P_FNAME File name X
P_L_FAIL Details about failed Wis
P_L_OK Details about cancelled Wis
S_CREDAT Creation date X
S_STATUS Status X
S_TASK Task X
S_WF_ID ID X
Code:
*&---------------------------------------------------------------------*
*& Report ZCAAH_WORKFLOW_CANCEL *
*& *
*&---------------------------------------------------------------------*
*& Logically delete workflow instances matching specifications. *
*& Specification can be via selection screen or file of work item IDs *
*&---------------------------------------------------------------------*
REPORT zcaah_workflow_cancel
* MESSAGE-ID
NO STANDARD PAGE HEADING
LINE-COUNT 65 LINE-SIZE 132.
*=======================================================================
* P R O G R A M D O C U M E N T A T I O N
*=======================================================================
* SHORT TEXT
* Cancel workflow instances
* ----------------------------------------------------------------------
* ATTENTION!
* This program only performs cancellation, no restarting
* ----------------------------------------------------------------------
* PROGRAM DESCRIPTION
* Use SAP API function to cancel active workflow instances specified
* on selection screen or in file
* ----------------------------------------------------------------------
* PROGRAM AUTHORIZATIONS
* Authorization group ZZ01 - Administration
* ----------------------------------------------------------------------
* RELATED CUSTOMIZING
* None
* ----------------------------------------------------------------------
* Date : 08.09.2004
* Author : Kjetil Kilhavn, Statoil KTJ IT BKS Basis
* ======================================================================
* Ver. Date Author CR-no Description of changes
*-----------------------------------------------------------------------
* 1.0 ZOOM 7 KJETILK 26818 Initial version
*=======================================================================
* ---------------------------------------------------------
* INTERNAL TABLES
* ---------------------------------------------------------
DATA:
gt_workitems TYPE STANDARD TABLE OF swwwihead,
gt_messages_ok TYPE STANDARD TABLE OF string,
gt_messages_failed TYPE STANDARD TABLE OF string,
gt_messages_discard TYPE STANDARD TABLE OF string.
* ---------------------------------------------------------
* VARIABLES
* ---------------------------------------------------------
DATA:
g_defaultpath TYPE rlgrap-filename,
g_workitem LIKE LINE OF gt_workitems,
g_subrc TYPE syst-subrc,
g_message TYPE string.
DATA:
g_count TYPE syst-dbcnt,
g_count_ok LIKE g_count,
g_count_failed LIKE g_count,
g_count_discarded LIKE g_count.
* ---------------------------------------------------------
* SCREEN FORMATTING
* ---------------------------------------------------------
* Input from file
SELECTION-SCREEN BEGIN OF BLOCK b1
WITH FRAME
TITLE text-sb1.
PARAMETERS:
p_fname TYPE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK b1.
* Input from selection screen
SELECTION-SCREEN BEGIN OF BLOCK b2
WITH FRAME
TITLE text-sb2.
SELECT-OPTIONS:
s_wf_id FOR g_workitem-wi_id,
s_task FOR g_workitem-wi_rh_task,
s_status FOR g_workitem-wi_stat,
s_credat FOR g_workitem-wi_cd.
SELECTION-SCREEN END OF BLOCK b2.
* Level of detail in output
SELECTION-SCREEN BEGIN OF BLOCK b3
WITH FRAME
TITLE text-sb3.
PARAMETERS:
p_l_ok TYPE boolean AS CHECKBOX DEFAULT space,
p_l_fail TYPE boolean AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK b3.
* ---------------------------------------------------------
* INITIALIZATION OF VARIABLES, FLAGS, AUTHORITY_CHECK, ETC.
* ---------------------------------------------------------
INITIALIZATION.
* Default path for file upload
CALL FUNCTION 'WS_ULDL_PATH'
IMPORTING
upload_path = g_defaultpath.
* ---------------------------------------------------------
* SCREEN VALIDATIONS
* ---------------------------------------------------------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
DATA:
l_filename LIKE p_fname.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_path = g_defaultpath
mode = 'O'
IMPORTING
filename = l_filename
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 99.
IF syst-subrc = 0.
p_fname = l_filename.
ELSE.
IF NOT syst-msgid IS INITIAL AND
NOT syst-msgty IS INITIAL AND
NOT syst-msgno IS INITIAL.
MESSAGE ID syst-msgid TYPE syst-msgty NUMBER syst-msgno
WITH syst-msgv1 syst-msgv2 syst-msgv3 syst-msgv4.
ENDIF.
ENDIF.
* ---------------------------------------------------------
* Select work items
* ---------------------------------------------------------
PERFORM select_work_items.
END-OF-SELECTION.
* ---------------------------------------------------------
* Cancel workflows
* ---------------------------------------------------------
LOOP AT gt_workitems
INTO g_workitem.
PERFORM cancel_workflow
USING g_workitem-wi_id
CHANGING g_subrc
g_message.
IF g_subrc = 0.
g_count_ok = g_count_ok + 1.
APPEND g_message TO gt_messages_ok.
ELSE.
g_count_failed = g_count_failed + 1.
APPEND g_message TO gt_messages_failed.
ENDIF.
ENDLOOP.
COMMIT WORK AND WAIT.
* ---------------------------------------------------------
* Report results
* ---------------------------------------------------------
* Successfully cancelled work items
FORMAT COLOR COL_HEADING.
WRITE: / text-l01, g_count_ok.
FORMAT COLOR COL_BACKGROUND.
IF p_l_ok = 'X'.
LOOP AT gt_messages_ok
INTO g_message.
WRITE AT /10 g_message.
ENDLOOP.
ENDIF.
* Work items which could not be cancelled
SKIP 3.
FORMAT COLOR COL_HEADING.
WRITE: / text-l02, g_count_failed.
FORMAT COLOR COL_BACKGROUND.
IF p_l_fail = 'X'.
LOOP AT gt_messages_failed
INTO g_message.
WRITE AT /10 g_message.
ENDLOOP.
ENDIF.
* Discarded input from file
IF NOT p_fname IS INITIAL.
SKIP 3.
FORMAT COLOR COL_HEADING.
WRITE: / text-l03, g_count_discarded.
FORMAT COLOR COL_BACKGROUND.
LOOP AT gt_messages_discard
INTO g_message.
WRITE AT /10 g_message.
ENDLOOP.
ENDIF.
END-OF-PAGE.
* ---------------------------------------------------------
* Function keys
* ---------------------------------------------------------
AT USER-COMMAND.
CASE sy-ucomm.
WHEN 'X'.
ENDCASE.
* ---------------------------------------------------------
* FORMS :
* ---------------------------------------------------------
*---------------------------------------------------------------------*
* FORM select_work_items *
*---------------------------------------------------------------------*
* Select the work items that are going to be cancelled *
* This form just calls the appropriate form based on specifications *
* on the selection screen. *
*---------------------------------------------------------------------*
FORM select_work_items.
IF NOT p_fname IS INITIAL.
PERFORM select_work_items_from_file.
ELSE.
PERFORM select_work_items_from_crit.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM select_work_items_from_file *
*---------------------------------------------------------------------*
* Get work item IDs from file and select data from header afterwards *
* *
* Work items which are not workflow items or are in status COMPLETED *
* or CANCELLED are stored in table gt_failed_file_data *
*---------------------------------------------------------------------*
FORM select_work_items_from_file.
CHECK NOT p_fname IS INITIAL.
DATA:
t_workitem_ids TYPE STANDARD TABLE OF char12.
FIELD-SYMBOLS:
<workitem_id> LIKE LINE OF t_workitem_ids.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = p_fname
TABLES
data_tab = t_workitem_ids
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
OTHERS = 99.
IF syst-subrc <> 0.
IF NOT syst-msgid IS INITIAL AND
NOT syst-msgty IS INITIAL AND
NOT syst-msgno IS INITIAL.
MESSAGE ID syst-msgid TYPE syst-msgty NUMBER syst-msgno
WITH syst-msgv1 syst-msgv2 syst-msgv3 syst-msgv4.
ENDIF.
EXIT.
ENDIF.
IF g_workitem IS INITIAL.
CONCATENATE <workitem_id>
': not a work item ID'
INTO g_message.
ENDIF.
* Any problems?
IF NOT g_message IS INITIAL.
APPEND g_message TO gt_messages_discard.
g_count_discarded = g_count_discarded + 1.
CONTINUE.
ENDIF.
* Add this work item to list of work items to process
APPEND g_workitem TO gt_workitems.
ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
* FORM select_work_items_from_crit *
*---------------------------------------------------------------------*
* Select work item IDs matching criteria *
*---------------------------------------------------------------------*
FORM select_work_items_from_crit.
CHECK NOT ( s_wf_id IS INITIAL AND
s_task IS INITIAL AND
s_status IS INITIAL AND
s_credat IS INITIAL ).
SELECT *
INTO CORRESPONDING FIELDS OF TABLE gt_workitems
FROM swwwihead
WHERE wi_id IN s_wf_id AND
wi_rh_task IN s_task AND
wi_stat IN s_status AND
wi_cd IN s_credat.
g_count = syst-dbcnt.
ENDFORM.
*---------------------------------------------------------------------*
* FORM cancel_workflow *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> WORKITEM_ID *
*---------------------------------------------------------------------*
FORM cancel_workflow
USING workitem_id TYPE sww_wiid
CHANGING e_subrc TYPE syst-subrc
e_message TYPE string.
* ---------------------------------------------------------
* Initialize
* ---------------------------------------------------------
CHECK NOT workitem_id IS INITIAL.
CLEAR e_subrc.
CLEAR e_message.
CONCATENATE 'Work item'
workitem_id
INTO e_message
SEPARATED BY space.
* ---------------------------------------------------------
* Check work item before cancellation
* ---------------------------------------------------------
SELECT SINGLE *
INTO CORRESPONDING FIELDS OF g_workitem
FROM swwwihead
WHERE wi_id = workitem_id.
IF syst-subrc <> 0.
e_subrc = syst-subrc.
CONCATENATE e_message
': not found in header table swwwihead'
INTO e_message.
ELSE.
IF g_workitem-wi_stat = 'COMPLETED'
OR g_workitem-wi_stat = 'CANCELLED'.
e_subrc = 99.
CONCATENATE e_message
': status ('
g_workitem-wi_stat
') not allowed'
INTO e_message.
ELSEIF g_workitem-wi_type <> 'F'.
IF NOT g_workitem-wi_chckwi IS INITIAL.
e_subrc = 99.
CONCATENATE e_message
': type ('
g_workitem-wi_type
') not allowed'
INTO e_message.
ENDIF.
ENDIF.
ENDIF.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.