Skip to Content
Technical Articles

Custom Event generation through change documents and handling with Abap class

Business Scenario

While changing the material variant configuration , some other changes have to be performed in the Material.  Change of Material variant config is saved in the table CDHDR with the Objectclass IBINVALUES .

Implementation

Following steps needs to be carried out in order to generate and handle the change event of the Object IBINVALUES.

Create Class and Event

Create a class and event , which has to be triggered when the variant configuration is changed.

Mapping object class to Event in SWEC

In this case , two entries have been created , for creation and change event .

While creating these Entries , there comes some waring regarding the Namespace, which can be ignored. Also an error will come that the interface IF_WORKFLOW is not implemented in the class. So you need to implement this Interface in your Event class. This Interface includes some other Interfaces which will be automatically added.

Create method to handle the event 

Now in order to handle the event , handler method has to be created. This Handler method comes with the Interface BI_EVENT_HANDLER_STATIC . Same class which is containing the Event could also be used for creating the handler method . This method contains various Importing parameters out of which the Event and Event_container are the most Important ones.

 

Through the following code , obect id present in the table CDHDR could be read.

 CASE event.
      WHEN 'VCM_LANGTX'.
        TRY.
*    Read Object id from container . Event container object is available as object reference .
            CALL METHOD event_container->get
              EXPORTING
                name       = 'CD_OBJECTID'
              IMPORTING
                value      = lf_object_id
                returncode = lf_returncode.

          CATCH cx_swf_cnt_cont_access_denied
                cx_swf_cnt_elem_not_found
                cx_swf_cnt_elem_access_denied
                cx_swf_cnt_elem_type_conflict
                cx_swf_cnt_unit_type_conflict
                cx_swf_cnt_elem_def_invalid
                cx_swf_cnt_invalid_qname
                cx_swf_cnt_container.
        ENDTRY.
    ENDCASE.

 

Assigning Handler method to the Event through SWETYPV

The custom event will be raised and the method to handle the event is also available. With the following linkage , the Event handler is assigned to the event.

Testing

Activate the tracing in SWELS and see the event generated and forwarded to the method in the tcode SWEL.

 

Conclusion

Following these steps, it will be possible to Implement actions on any change object class.

Let me know if there are any questions or comment if anything related to this topic is important .

Be the first to leave a comment
You must be Logged on to comment or reply to a post.