Events are part of business object and are triggered by a possible change in the state of the object.
Workflows are usually started using events.
Event parameters
Event parameters are defined as elements of the event container in the Business Object Builder and
are passed to the event receivers using a binding. The following event parameters are held in the
event container automatically:
_EVT_OBJECT: The reference to the object whose change of state is described by the event.
_EVT_CREATOR: The user name of the party who triggered the event creation.
, etc
To add event parameters, position the cursor on the event ID and select PARAMETERS.
Event Container
The event container contains the event parameters as container elements. If you define triggering events or terminating events for a task, you can specify the binding from the event container to the task container. If you define triggering events for a workflow, you can specify the binding from the event container to the workflow container.
Creating an Event
Choose Tools ---> Business Workflow ---> Development ---> Environment
Alternately you can also go to the transaction SWO1.
Select any custom object and press change
NOTE: During processing of an event, an attempt is made to regenerate the instance triggered by the event. However, for certain events (DELETED, for example), this is not possible since the persistent object has meanwhile been deleted.
If the checkbox “Triggering object does not exist” is set, the object no longer exists after the event is triggered and so runtime objects can no longer be generated for this object.
After adding an event parameter, return to the previous screen and change the release status of the
event. This can be done from Edit > Change Release Status > Object Type Component > to Implemented. After changing status “To Implemented”, change its status to “Released” by the
same process. This indicates that the added event has been released for use by the customers.
Methods of Event Creation
There are various ways in which events can be created:
- Function module
- Change documents
- General status management
- Business Transaction Events
- Logistics Information System (LIS)
- Message Control
- ABAP classes
method RAISE of an instance of type IF_SWF_EVT_EVENT.
- Step Event Creator in Workflow Builder
- HR master data
Event creation when HR master data changes.
Function Module
You can create events from application or system programs by calling one of the relevant function
modules SWE_EVENT_CREATE or SAP_WAPI_CREATE_EVENT.
The Function Module SAP_WAPI_CREATE_EVENT has the following interface:
EXPORTING | ||
object_type | SWETYPECOUOBJTYPE | Type of the triggering object |
object_key | SWEINSTCOUOBJKEY | Concatenated,
object type-specific key of the triggering object. The reference to the triggering object is created internally from this information and written to the event container under the element ID _Evt_Object. |
event | SWETYPECOUEVENT | ID
of the event. The event must be defined for the triggering object type. |
IMPORTING | ||
event_id | SWEDUMEVIDEVTID | The
event number has a value other than zero if the event manager could establish
one or more receiver function modules. If no receiver could be established, zero is returned as the event number. |
Example:
begin_method create_event changing container.
DATA:
hlevel TYPE ztb_fpt_wf_usfbk-zversion,
org_unit TYPE ztb_fpt_mm001-zorg_unit,
pr_number TYPE eban-banfn,
update_mode TYPE ztb_fpt_wf_usfbk-umode,
zversion TYPE ztb_fpt_wf_usfbk-zversion,
wa_user TYPE ztb_fpt_mm001,
pr_type TYPE eban-bsart.
DATA:
l_wk_objtyp TYPE swr_struct-object_typ,
l_wk_objkey TYPE swr_struct-object_key,
l_wk_event TYPE swr_struct-event,
l_wk_subrc TYPE sy-subrc,
l_wk_eventid TYPE swr_struct-event_id.
swc_get_element container 'ORG_UNIT' org_unit.
swc_get_element container 'PR_NUMBER' pr_number.
swc_get_element container 'UPDATE_MODE' update_mode.
swc_get_element container 'ZVERSION' zversion.
swc_get_element container 'PR_TYPE' pr_type.
* concatenate the key fields
CONCATENATE hlevel
org_unit
pr_number
update_mode
pr_type
zversion
INTO l_wk_objkey RESPECTING BLANKS.
l_wk_objtyp = 'ZOT_PR'.
l_wk_event = 'EVT_AGREEMENT'.
CALL FUNCTION 'SAP_WAPI_CREATE_EVENT'
EXPORTING
object_type = l_wk_objtyp
object_key = l_wk_objkey
event = l_wk_event
* COMMIT_WORK = 'X'
* EVENT_LANGUAGE = SY-LANGU
language = sy-langu
* USER = SY-UNAME
* IFS_XML_CONTAINER =
IMPORTING
return_code = l_wk_subrc
event_id = l_wk_eventid
* TABLES
* INPUT_CONTAINER =
* MESSAGE_LINES =
* MESSAGE_STRUCT =
.
swc_set_element container 'HLEVEL' hlevel.
swc_set_element container 'WA_USER' wa_user.
end_method.
The event is not instance-independent so that you must pass the keyfields as parameter for FM to initiate the instance of BOR to be able to call its event. In the workflow builder, if you use Wait step to listen to the event, you must pass the same instance (same keyfields of BO triggered event) into Container Element of Wait step.
Note: Since the asynchronous RFC for calling the receiver function module is not triggered until
after the next COMMIT WORK , you must check the COMMIT WORK Exporting Parameter in your application after the function module for creating an event is called in order for the events to actually be created.
Although both the function modules SAP_WAPI_CREATE_EVENT and SWE_EVENT_CREATE
have similar signatures, it is recommend that you use SAP_WAPI_CREATE_EVENT instead of the
old function module SWE_EVENT_CREATE.
No comments:
Post a Comment