Code enhancement

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:

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.

  1. Upon investigation of the SAP sales quote transaction, transaction VA21 is found to support the desired sales quote creation business process.
  2. The sales quote number is determined to be the unique key. The Sales quote number is stored in table/field VBAK-VBELN.
  3. Transaction VA21 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 quote number is available when the user exit is executed.
  4. The user exit belongs to other business processes, so additional coding is needed to differentiate a sales quote from other categories of documents. VBAK-VBTYP is available to determine the document category. A sales quote is saved in the SAP database with a document category of B.
  5. An include statement is added to the user exit that points to the include program.
  6. At this time, the include program and a function module need to be created.

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.
 

Copyright IBM Corp. 1997, 2003