Once you determine the business process to support (for example, sales quotes or sales orders), and determine the preferred event detection mechanism, implement the mechanism for your business process.
The following sections describe the implementation process for the four event detection mechanisms implemented by the IBM WebSphere Business Integration Adapter for mySAP.com. Whenever applicable, an example is provided along with sample code.
Code enhancement requires encapsulating a portion of ABAP code in a custom function module. The event detection code is written as a function module to ensure that the processing remains separate from the transaction. Any tables or variables used from the transaction need to be passed to the function module by value and not by reference.
To minimize the effects of locking a business object when retrieving an event, the function module typically executes in an update-task mode. To avoid inconsistencies, do not use update task if the function module is already being called within a process that is in an update -task mode.
To minimize the impact in the transaction, place the function module within another include program. Using an include program allows you to make changes to custom code rather than to SAP code.
The event detection code contains logic that identifies the object for the event. For example, the sales order transaction handles many types of orders, but only one order type is required. This logic is in the event detection code. The general strategy for placing this event detection code is to insert it just before the data is committed to the database. The function module containing the event detection code is typically created as a part of the function group for the business object.
To implement Code Enhancement for event detection:
Research a business process by looking for a "commit work statement" in the code executed by the transaction for the business process. You can use the ABAP debugger to investigate the value of different attributes at that point.
The following steps describe the process of creating an example SAP sales quote using the Code Enhancement event detection mechanism. The code that follows it is a result of this process.
The new function module contains the following code:
If VBAK-VBTYP = 'B'. C_OBJ_ORDER = 'SAP_SalesQuote'. TMP_OBJKEY = XVBAK-VBELN. TMP_EVENT = 'Create'. TMP_OBJTYPE = Space. CALL FUNCTION 'Y_XR_ADD_TO_QUEUE' EXPORTING OBJTYPE = TMP_OBJTYPE OBJNAME = C_OBJ_ORDER OBJKEY = TMP_OBJKEY EVENT = TMP_EVENT GENERIC_RECTYPE = '' IMPORTING RECTYPE = TMP_RECTYPE TABLES EVENT_CONTAINER = TMP_EVENT_CONTAINER EXCEPTIONS OTHERS = 1. Endif.
To implement batch program as an event detection mechanism, you must write an ABAP program that evaluates database information. If the criteria in the ABAP program is fulfilled when the program executes, then an event is triggered.
To implement Batch Program for event detection:
The following steps describe the process of creating a batch program that detects events for all sales quotes created on today's date. The code that follows it is a result of this process.
The following sample code supports the SAP Sales Quote as a batch program:
REPORT ZSALESORDERBATCH. tables: vbak. parameter: d_date like sy-datum default sy-datum. data: tmp_key like YXR_EVENT-OBJ_KEY, tmp_event_container like swcont occurs 0. " retrieve all sales quotes for today's date " sales quotes have vbtyp = B select * from vbak where erdat = d_date and vbtyp = 'B'. tmp_key = vbak-vbeln. TMP_OBJTYPE = space. CALL FUNCTION 'Y_XR_ADD_TO_QUEUE' EXPORTING OBJTYPE = TMP_OBJTYPE OBJNAME = 'SAP_SalesQuote' OBJKEY = tmp_key EVENT = 'Create' GENERIC_RECTYPE = '' IMPORTING RECTYPE = r_rectype TABLES EVENT_CONTAINER = tmp_event_container. write: / vbak-vbeln. endselect.
Business workflow is a set or sequence of logically related business operations. The processing logic within a workflow detects events. The Business Workflow event detection mechanism relies on the SAP Business Object Repository (BOR), which contains the directory of objects along with their related attributes, methods, and events.
To implement business workflow for event detection:
The following example of SAP sales quote can be used to implement an event trigger using business workflow:
Object type--ZMYQUOTE
Event--SAP_SalesQuote
Name--SAP Sales Quote
Description--Example of an SAP Sales Quote Subtype
Program--ZMYSALESQUOTE
Application--V
Object type--ZMYQUOTE
Event--SAP_SalesQuote
Receiver FM--Y_XR_ADD_TO_QUEUE_DUMMY
Receiver type FM--Y_XR_ADD_TO_QUEUE_WF
The business workflow event detection mechanism is created and active. It is set up to detect all SAP Customer Quotes that are created.