FM to logically delete an active WF

Kjetil Kilhavn KJETILK at statoil.com
Fri Oct 28 10:49:08 EDT 2005


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.


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


*&---------------------------------------------------------------------*
*& 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
*=======================================================================

* ---------------------------------------------------------
* DATABASETABLES
* ---------------------------------------------------------



* ---------------------------------------------------------
* 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.



* ---------------------------------------------------------
* CONSTANTS
* ---------------------------------------------------------



* ---------------------------------------------------------
* 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.





AT SELECTION-SCREEN.





* ---------------------------------------------------------
* MAIN-PROGRAM
* ---------------------------------------------------------
TOP-OF-PAGE.





START-OF-SELECTION.
* ---------------------------------------------------------
* Authorization check
* ---------------------------------------------------------


* ---------------------------------------------------------
* 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.

  DESCRIBE TABLE t_workitem_ids
           LINES g_count.

  LOOP AT t_workitem_ids
       ASSIGNING <workitem_id>.
    CLEAR g_workitem.
    CLEAR g_message.
    g_workitem-wi_id = <workitem_id>.

    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.

  CHECK e_subrc IS INITIAL.


* ---------------------------------------------------------
* Cancel workflow
* ---------------------------------------------------------
  CALL FUNCTION 'SWW_WI_ADMIN_CANCEL'
       EXPORTING
            wi_id                       = workitem_id
       EXCEPTIONS
            update_failed               = 1
            no_authorization            = 2
            infeasible_state_transition = 3
            OTHERS                      = 99.
  e_subrc = syst-subrc.

  CASE e_subrc.
    WHEN 0.
      CONCATENATE e_message
                  ': cancelled'
                  INTO e_message.

    WHEN 1.
      CONCATENATE e_message
                  ': update failed'
                  INTO e_message.

    WHEN 2.
      CONCATENATE e_message
                  ': no authorisation'
                  INTO e_message.

    WHEN 3.
      CONCATENATE e_message
                  ': infeasible state transition'
                  INTO e_message.

    WHEN OTHERS.
      CONCATENATE e_message
                  ': other error'
                  INTO e_message.
  ENDCASE.
ENDFORM. 

-- 
Kjetil Kilhavn, Statoil ØFT KTJ ITS BKS SAP Basis




-----Original Message-----
From: sap-wug-bounces at mit.edu [mailto:sap-wug-bounces at mit.edu] On Behalf Of Rick Sample
Sent: 28. oktober 2005 16:22
To: manish.khanna at amd.com; sap-wug at mit.edu
Subject: RE: FM to logically delete an active WF

Sorry. I missed (as well as the 'master') the "FM" part. 
You can use SWW_WI_ADMIN_CANCEL. 
No mass Logically Deletes exists in 4.6c as far as I know. 
You would have to use this along with a program to feed the WI_ID. 
No SAP_WAPI_ADM_WORKFLOW_CANCEL in 4.6c.
If I am wrong, please let me know. 

Sure, a bit more time investigating would help but when you are new and don't have a starting point it can be overwhelming. If you search 'Logically' 
from http://www.google.com/search?hl=en&lr=&safe=off&q=site%3Amailman.mit.edu+sap-wug&btnG=Search
put in site:mailman.mit.edu sap-wug and your search. 
Then you will see some posts on how to go about the mass delete using SWW_WI_ADMIN_CANCEL.

Some folks are legends in their own minds so DO NOT let that stop you from asking questions! 
Reading the other replies from the 'master' is more disturbing than the "Stupid Questions". 
This comment and the "This is not a kindergarden" comment is totally inappropriate. Period! 
I am shocked that these comments made it threw to the list. I will drop it and not comment about this issue again.
I will leave it to the moderator. 

Hopefully, this will not repeat itself. 

Rick 


>>> manish.khanna at amd.com 10/28/2005 3:46 >>>
Sincere apologies to disturb such a 'master' of the workflow with such a tiny question. I'm still a novice and can't reach your level of expertise. Kindly ignore my mails in the future as you may find my questions too easy to answer.
 
________________________________

From: sap-wug-bounces at mit.edu [mailto:sap-wug-bounces at mit.edu] On Behalf Of Kjetil Kilhavn
Sent: Friday, October 28, 2005 1:55 PM
To: SAP Workflow Users' Group
Subject: RE: FM to logically delete an active WF
 
1) By reading some of the basic the information SAP delivers with the system
2) By poking around in the menu
3) By using SWI1 and going into change mode for the work item
 
Do us a favour please, ask a more interesting question next time.
--
Kjetil Kilhavn, Statoil ØFT KTJ ITS BKS SAP Basis
 
 
________________________________

From: sap-wug-bounces at mit.edu [mailto:sap-wug-bounces at mit.edu] On Behalf Of Khanna, Manish
Sent: 28. oktober 2005 10:06
To: SAP Workflow Users' Group
Subject: FM to logically delete an active WF
Hi,
 
How can I cancel(logically delete an active WF)
 
Thanks
Manish


_______________________________________________
SAP-WUG mailing list
SAP-WUG at mit.edu
http://mailman.mit.edu/mailman/listinfo/sap-wug


-------------------------------------------------------------------
The information contained in this message may be CONFIDENTIAL and is
intended for the addressee only. Any unauthorised use, dissemination of the
information or copying of this message is prohibited. If you are not the
addressee, please notify the sender immediately by return e-mail and delete
this message.
Thank you.



More information about the SAP-WUG mailing list