IBM BPM, V8.0.1, All platforms > Authoring services in Integration Designer > Services and service-related functions > Access external services with adapters > Configure and using adapters > IBM WebSphere Adapters > SAP Software > Configure the module for deployment > Performing prerequisite tasks specific to an interface > Implementing event-detection mechanisms

Implementing custom triggers

Custom triggers 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 must be passed to the function module by value and not by reference.

This procedure is for the Advanced event processing interface only.

If you are not using the Advanced event processing interface, skip this procedure.

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 a custom trigger for event detection:


Procedure

  1. Determine which verbs to support: Create, Update, or Delete. This helps define which transactions to investigate.
  2. Determine the business-object key for the transaction. This key must be unique to allow the adapter to retrieve the business object from the database.

    If a composite key is required, at triggering time you can specify each key attribute and its corresponding value as a name-value pair. When the business object is created at polling time, the adapter automatically populates the attributes with their values.

  3. Check that an SAP-provided user exit in the transaction has all the information needed to detect an event.

    For example, a user exit might not be able to implement a Delete verb because the business object is removed from the database before that point.

  4. If a user exit cannot be used, determine the appropriate location for the event-detection code, and then add the event-detection code using an SAP modification.

    Select a location that has access to the business object key and other variables used to make the decision.

    If you are implementing the future events capability, in addition to adding the event-detection code for future events, contact your Basis administrator to schedule the adapter-delivered batch program /CWLD/SUBMIT_FUTURE_EVENTS to run once every day.

  5. 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.
  6. Determine the criteria for detecting an event.

  7. Create the function module containing the event detection code.

  8. Create the include program and then add it to the transaction's code.
  9. Test all of the scenarios designed to detect an event.


Example

The following steps describe the process of creating an example SAP customer master using the custom trigger event-detection mechanism. The code that follows it is a result of this process.

  1. Upon investigation of the SAP customer master transaction, transaction XD01 is found to support the customer master creation business process.

  2. The Customer number is determined to be the unique key. The Customer number is stored in table/field KNA1-KUNNR.

    Because this event uses a single unique key, the code example uses the OBJKEY parameter to pass the key value.

  3. Transaction XD01 has a user exit in the transaction flow as part of the document save process (Form Userexit_save_document). At this point in the transaction, the customer number is available when the user exit is executed.

  4. An include statement is added to the user exit that points to the include program.

  5. At this time, the include program and a function module must be created.

The following code fragment illustrates the function call to the /CWLD/ADD_TO_QUEUE_AEP event trigger (using a single key value).

CASE HEADER_CHANGE_IND.
	WHEN 'I'.
	* The verb will always be a create if KNA1 data is entered.
	 IF KNA1_CREATE = 'X'. 
		HEADER_EVENT = C_CREATE_EVENT.
	ELSE.  
	* Check if an entry is in the config table for converting a create. If 
	* no entry is found, the default is to convert the extension of sales
	* area or company code to an update.
	SELECT SINGLE * FROM /CWLD/CONF_VAL
		WHERE CONF_NAME = C_CONVERT_CREATE
		AND CONF_VALUE = C_FALSE_WORD.

	IF SY-SUBRC = 0. 
		HEADER_EVENT = C_CREATE_EVENT.
	ELSE.
		HEADER_EVENT = C_UPDATE_EVENT. 
	ENDIF. 
	ENDIF.

	WHEN 'U'.
		HEADER_EVENT = C_UPDATE_EVENT.
	WHEN 'E' OR 'D'.
		HEADER_EVENT = C_DELETE_EVENT.
ENDCASE. 

	* See if it's a sold-to company.
	SELECT SINGLE * FROM /CWLD/CONF_VAL 
		WHERE CONF_NAME = C_AGCUSTMASTER
		AND CONF_VALUE = KNA1-KTOKD. 

	* clear temp_obj_type.       
	CLEAR TEMP_OBJ_NAME.       
	IF SY-SUBRC = 0. 
	* temp_obj_type = 'YXR_V51'.         
		TEMP_OBJ_NAME = C_OBJ_CUSTOMERMASTER.        
	ELSE.

* If it's not a sold-to company, check if it's another partner. 
	SELECT SINGLE * FROM /CWLD/CONF_VAL 			
		WHERE CONF_NAME = C_AGCUSTPARTNER 			
		AND CONF_VALUE = KNA1-KTOKD.     
	ENDIF.

CALL FUNCTION  '/CWLD/ADD_TO_QUEUE_AEP'            
	EXPORTING                 
		OBJ_NAME	= TEMP_OBJ_NAME
		OBJKEY	= OBJKEY
		EVENT = HEADER_EVENT 
* IDOC_NUMBER	= 
		GENERIC_RECTYPE = GENERIC_RECTYPE
	IMPORTING 
		RECTYPE	= RECTYPE   
	TABLES 
		EVENT_CONTAINER	 = EVENT_CONTAINER 
	EXCEPTIONS 
		OTHERS	= 1.  

The following code fragment illustrates the function call to the /CWLD/ADD_TO_QUEUE_IN_FUT_AEP event trigger (single key value).

DATA: DATE_IN_FUTURE LIKE SY_DATUM. 

CALL FUNCTION ' /CWLD/ADD_TO_QUEUE_IN_FUT_AEP'  	
	EXPORTING  		
		OBJ_NAME = TEMP_OBJ_NAME 		
		OBJKEY = OBJKEY  		
		EVENT = HEADER_EVENT 		
		VALID_DATE = DATE_IN_FUTURE  	
	IMPORTING  		
		RECTYPE = RECTYPE  	
	TABLES  		
		EVENT_CONTAINER = EVENT_CONTAINER  	
	EXCEPTIONS  		
		OTHERS = 1.


What to do next

Configure the adapter for Advanced event processing.

Implementing event-detection mechanisms