Home > ABAP, WorkFlow > Generate Business Object Event in the program

Generate Business Object Event in the program

January 7th, 2010 Leave a comment Go to comments

An event is created from any application program and published system-wide. Any number of receivers can react to the event. For example, the create event of sales order may trigger an approval workflow. Events that you want to use must be defined as components of an object type. Events are published without the creating application knowing whether a receiver reacts to them. The event manager checks whether there are active linkages for the published event.

There are many ways to publish an event to the system. In this post, I will introduce how to create event using ABAP program. An event can be created from any program by calling the function module SWE_EVENT_CREATE or SAP_WAPI_CREATE_EVENT.

Note that events say something about object status changes that have actually occurred. Therefore ensure that the event is not created until the relevant status change has taken place. For this, the function module for creating an event should be called in the same logical unit of work (LUW) as the one in which the status change is made.

Function module SWE_EVENT_CREATE has the following interface:

Import parameters
OBJTYPE SWETYPECOU-OBJTYPE Type of the triggering object.
OBJKEY SWEINSTCOU-OBJKEY 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 SWETYPECOU-EVENT ID of the event.

The event must be defined for the triggering object type.

Export parameters
EVENT_ID SWEDUMEVID-EVTID The event number has a value other than zero if the event manager could establish one or more receiver function modules.
Table parameters
EVENT_CONTAINER SWCONT Persistent event container of the event.

You only pass the event container if you have defined event parameters in addition to the predefined elements. The container you pass to the function module is filled with the relevant data in the event-creating application and then contains only the event parameters you defined.

When the function module is executed, the predefined elements (object reference, creation time, creator, and so on) are added to the event container.

Also we list all the interface of function module SWE_EVENT_CREATE, I think it is easier to understand it using some code snips.

  Include <;CNTN02>;.
  DATA: lv_objkey     TYPE  sweinstcou-objkey,
         lv_event_id   TYPE  swedumevid-evtid. "ID of triggered event
 
*prepare event container
          swc_container it_event_container.         "Declaration
          swc_create_container it_event_container.  "Initialization
 
*REQUESTOR_COMMENTS is the parameter of the event ZMMCANC_PO in the business object ZMMCANC_PO
          swc_set_table it_event_container 'REQUESTOR_COMMENTS'  it_comments."#EC *
 
          CONCATENATE wa_output-vbeln wa_output-vbelp wa_output-ebeln
                      wa_output-ebelp wa_output-lifnr gv_zowner_wf INTO lv_objkey.
 
*release event
          CALL FUNCTION 'SWE_EVENT_CREATE'
            EXPORTING
              objtype                       = 'ZMMCANC_PO'
              objkey                        = lv_objkey
              event                         = 'ZCANC_PO_WF_STARTED'
           IMPORTING
             event_id                      = lv_event_id
           TABLES
             event_container               = it_event_container
           EXCEPTIONS
             objtype_not_found             = 1
             OTHERS                       = 2.

In the next post, I will introduce more options to create event.

Useful Links

http://help.sap.com/saphelp_nw70/helpdata/en/c5/e4a930453d11d189430000e829fbbd/frameset.htm

http://help.sap.com/saphelp_nw04/helpdata/EN/c5/e4aec8453d11d189430000e829fbbd/frameset.htm

  1. No comments yet.
  1. No trackbacks yet.