Programming for events triggered by system is a little tricky but they are a great help when using exits are not a solution. Consider a situation where a delivery details needs to be saved in a Z-Table and used to create a file. These delivery details needs saved only after a delivery is saved. Doing this in user-exit/BDIs might cause some issues in case the saving of the delivery fails or the data in the tables are not updated when the code is executed. Such scenarios can pose issues because code potentially might work in a development system, it might hit into roadblock in a more well-tuned quality or production system.
Here comes the Event Type Linkages to rescue. For different events, the code can be written in FMs and the FMs can be called upon when the events are triggered. Since they rely on events, the both issues – failure or delay in saving data will never happen.
In tcode SWETYPV, we define Receiver FM and Check FM for an object category, object type and event. First tricky part is to identify what object category, object type and event needs to be used.
There are two transactions – SWELS and SWEL. Former is used to switch on/off the trace on events while latter is used to read the trace.
To identify object category, object type and event – the simplest way is to google and find out if somebody has given a shot to your requirement. If not, the next available solution is to switch on the trace and then execute the transaction. Then read the trace to identify an event which can be used. Explore the options in the event and see if anything suits the requirement.
Check FM is used to control execution of Receiver FM. This ensures if any condition needs to be set up without hitting the Receiver FM it can be done separately and this helps because while testing, you can switch on trace and see how FMs are executed. Condition failure can be identified y presence of only Check FM while if both are present, the condition was success. Main code can be written in Receiver FM.
Last point, ensure linkage is activated.