A change pointer uses change documents and is one of the
more challenging event detection mechanisms to implement. The SAP
Business Object Repository (BOR) is used as well as Application Link
Enabled (ALE) technology. A change document always refers to a business
document object having at least one database table assigned to it.
If the data element in a table is marked as requiring a change document
and the table is assigned to a business document object, then a change
in value of the field defined by the data element generates a change
document. The changes are captured in tables CDHDR and CDPOS and are
used for event detection.
About this task
Note: This procedure is for the Advanced event processing
interface only. If you are not using the Advanced event processing
interface, skip this procedure.
To implement change pointer
for event detection:
Procedure
- Activate the global Change pointers flag in transaction
BD61.
- Change the SAP function module CHANGE_POINTERS_CREATE to
include the function module call to /CWLD/EVENT_FROM_CHANGE_POINTR.
- Determine which verbs to support: Create, Update, or Delete.
- Check if the SAP business process (transaction) utilizes
change documents:
- In the Environment menu for the transaction, does a Change function
exist? How about when you click Go To, and then click Statistics?
- If you change data in the transaction, is there a new entry in
table CDHDR that reflects the change?
- In the database tables associated with a transaction, do any of
the data elements have the Change Document flag set?
- If the answer is Yes to any of these questions, the transaction
uses change documents.
- Determine if the data elements that set the Change Document
flag capture all of the information needed to detect an event. Changing
the Change Document flag is not recommended because it changes an
SAP-delivered object.
- Determine the business object key for the transaction.
The business object key must be unique so that the business object
can be retrieved from the database. A composite key may be required.
This is normally table/field CDHDR-OBJECTID.
- Determine the criteria for detecting an event. Use table/field
CDHDR-OBJECTCLAS as the main differentiator. CDPOS-TABNAME may also
be used to detect the event.
- Update function module /CWLD/EVENT_FROM_CHANGE_POINTR
with the logic to detect the event.
Example
The following
example of an SAP sales quote can be used to implement an event trigger
using change pointer:
- Update is determined to be the supported verb. Investigating the
sales quote create transaction shows that the Create verb is not detected
through this mechanism.
- When performing the checks of the business for sales quote:
- The Change function is available from the Environment menu in
transaction VA22.
- Making a change to a sales quote results in a new entry in table
CDHDR.
- Looking at table VBAP, the field ZMENG has the Change Document
flag set.
- No evaluation of data elements was done for this example.
- The sales quote number is determined to be the unique key in CDHDR-OBJECTID.
- CDHDR-OBJECTCLAS has a value of VERKBELEG, which is the main differentiator.
Only sales quotes should be picked up. The code checks the TCODE field
in the header table, but a proper lookup should be done in the VBAK
table.
The following sample code is added to /CWLD/EVENT_FROM_CHANGE_POINTR:
when 'VERKBELEG'.
data: skey like /cwld/log_header-obj_key,
s_event like swetypecou-event,
r_genrectype like swetypecou-rectype,
r_rectype like swetypecou-rectype,
t_event_container like swcont occurs 1 with header line.
" Quick check. Should check document category (VBTYP) in VBAK.
check header-tcode = 'VA22'.
" Event detection has started
perform log_create using c_log_normal c_blank c_event_from_change_pointer c_blank.
" Set the primary key
skey = header-objectid.
" Set the verb
s_event = c_update_event.
" Log adding the event to the queue
perform log_update using c_information_log text-i44
'SAP4_SalesQuote' s_event skey.
" Event detection has finished.
perform log_update using c_finished_log c_blank
c_blank c_blank c_blank.
call function '/CWLD/ADD_TO_QUEUE_AEP'
exporting
obj_name = 'SAP4_SalesQuote'
objkey = skey
event = s_event
generic_rectype = r_genrectype
importing
rectype = r_rectype
tables
event_container = t_event_container
exceptions
others = 1.
What to do next
Configure the adapter for Advanced event processing.