Trigger outbound idocs by linking change document object with business object events
To transfer master data (For example: vendor master, material master, customer master) changes instantly through idocs from SAP to legacy systems, we do not have automated mechanism like message control technique which is used to transfer transaction data (For example: purchase orders, sales orders). To overcome this problem we can use concept of linking business object events and change document objects to transfer master data idocs.
Below, I will explain with an example how material master price changes are communicated instantly to legacy systems.
- Change Document Objects
- Link change document object with business object event
- Assign business object event to receiver function module
- Convert XML data in receiver function module.
1. Change Document Objects
Transaction code: SCDO
- Change document object contains the tables in which the data of the business object is stored. Function modules that are called in the corresponding application programs and that log the changes at runtime can be generated from the change document object.
- Logging only takes place if the fields whose contents were changed refer to a data element that was flagged as relevant for the change document.
- Below screen shots depicts the list of tables contained in change document object ‘MATERIAL’. Our material price field ‘VERPR’ is stored in table ‘MBEW’. Whenever change is made to material price, function modules associated to change document object logs the change in CDHDR and CDPOS tables.
- Below screen shot shows list of function modules, DDIC objects and programs generated for change document object ‘MATERIAL’.
2. Link change document object with business object event
Transaction code: SWEC
- After suitable change document object is selected we need to assign change document object to business object.
- Both change document object and business object which we link should have same key. So the business object should be relevant to change document object. In this example, I am using BOR ‘ZUS1001006’ (copied from ‘BUS1001006’) and new event ‘changed’ is created.
- Below screen shot shows our custom BOR ‘ZUS1001006’ with event changed. SWO1 is the transaction code for business objects.
Step 1: Go to transaction SWEC. Click on new entries.
Step 2: Fill the necessary inputs and save.
Since our business object event needs to be triggered only when there is a change in material, I have selected the radio button on change.
We can limit the event to trigger only for few fields. This can be achieved by maintaining the fields and their corresponding table name in the node field restrictions.
3.Assign business object event to receiver function module
Transaction code: SWETYPV
Create a custom receiver function module and it should have interface parameters same as standard FM ‘SWW_WI_CREATE_VIA_EVENT_IBF’.
Step 1: Go to transaction code SWETYPV, click on new entries and fill input fields as below and save. Make sure to check Linkage Activated check box.
4. Convert XML data in receiver function module
Transaction code: SE37
- Function module ‘Z_IDOC_CREATE_MAT_PRICE_CHANGE’, receives the data regarding change in XML format.
- Event_container is the internal table which holds the xml data. This needs to be parsed using function module ‘SMUM_XML_PARSE’ to obtain appropriate structure from which we will fetch change document number generated for price change.
- Data fetched from CDPOS table for change document number should be sufficient to generate idoc using FM ‘MASTETR_IDOC_DISTRIBUTE’.
- Next screen shot shows the code, how xstring is parsed and change document number is obtained.