Sunday, October 10, 2010

Passing Mutiple values to Workflow in BADI

In BADI we cannot include INCLUDE .. So we need to use some other way to pass multiple values to Workflow.

For that, go to SE24 give the interface name.



Then go to goto --> Class-local types --> macros



In the editor, include INCLUDE cntn01_swc instead of INCLUDE




Macros written in the program is also different.

Please see one example code.

***********************************

***---INTERNAL TABLE DECLARATION
DATA : lit_event_container TYPE TABLE OF swcont. "event container

*--Creating a container
swc0_create_container lit_event_container.

*--Filling event container

swc0_set_element lit_event_container 'User' draw-dwnam.
swc0_set_element lit_event_container 'DocumentStatus' new_status.
swc0_set_element lit_event_container 'DocumentStatus_old' old_status.
swc0_set_element lit_event_container 'Document_Desc' lfs_drat-dktxt.

CALL FUNCTION 'SWE_EVENT_CREATE'
EXPORTING
objtype = l_objtype
objkey = l_objkey
event = l_event
* creator = ' '
* take_workitem_requester = ' '
* start_with_delay = ' '
* start_recfb_synchron = ' '
* no_commit_for_queue = ' '
* debug_flag = ' '
* no_logging = ' '
* ident =
IMPORTING
event_id = l_eventid
* receiver_count =
TABLES
event_container = lit_event_container
EXCEPTIONS
objtype_not_found = 1
others = 2
.
IF sy-subrc <> 0.
* message id sy-msgid type sy-msgty number sy-msgno
* with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
COMMIT WORK.

****************************************************

See the event parameter list

Passing Multiple Values to Workflow

Passing Multiple values from the triggering program to Workflow.

First we need to declare the event container variables for the required event.

See the screen shots for creating event container variables.







Now we have defined the event container variables.

After that we need to do the coding in the workflow triggering point.

*-- For Passing Event Container Values
INCLUDE .
swc_container wf_contnr.
*-- create the container of type container
swc_create_container wf_contnr.
swc_set_element wf_contnr 'EvtParameter1' p_gwf_onrname.

*-- Triggering the workflow ( note that we are passing the event container )

CALL FUNCTION 'SWE_EVENT_CREATE'
EXPORTING
objtype = 'ZEHS_RA'
objkey = p_gwf_entryno
event = p_gwf_event
* CREATOR = ' '
* TAKE_WORKITEM_REQUESTER = ' '
* START_WITH_DELAY = ' '
* START_RECFB_SYNCHRON = ' '
* NO_COMMIT_FOR_QUEUE = ' '
* DEBUG_FLAG = ' '
* NO_LOGGING = ' '
* IDENT =
* IMPORTING
* EVENT_ID =
* RECEIVER_COUNT =
TABLES
event_container = wf_contnr
EXCEPTIONS
objtype_not_found = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
COMMIT WORK.

***************************************************
Please see one example program
***************************************************
*-- For Passing Event Container Values
INCLUDE .
swc_container wf_contnr.
* swc_container wf_contnr1.
swc_create_container wf_contnr.
* swc_create_container wf_contnr1.
IF p_gwf_onrname IS NOT INITIAL AND p_gwf_onrname NE space.

swc_set_element wf_contnr 'NextLevel' p_gwf_onrname.
swc_set_element wf_contnr 'Initiator' sy-uname.
ENDIF.
IF p_gwf_onrname IS INITIAL.
swc_set_element wf_contnr 'Initiator' sy-uname.
ENDIF.
*--------------------------------------------------------------*


CALL FUNCTION 'SWE_EVENT_CREATE'
EXPORTING
objtype = 'ZEHS_RA'
objkey = p_gwf_entryno
event = p_gwf_event
* CREATOR = ' '
* TAKE_WORKITEM_REQUESTER = ' '
* START_WITH_DELAY = ' '
* START_RECFB_SYNCHRON = ' '
* NO_COMMIT_FOR_QUEUE = ' '
* DEBUG_FLAG = ' '
* NO_LOGGING = ' '
* IDENT =
* IMPORTING
* EVENT_ID =
* RECEIVER_COUNT =
TABLES
event_container = wf_contnr
EXCEPTIONS
objtype_not_found = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
COMMIT WORK.