Skip to Content

Delete ALL EM Event Handlers and Messages – DO NOT USE IN PRODUCTION ENVIRONMENTS!

Hi All.

Be careful with this one!!!

I often find that I need to delete all Event Handlers and Messages in the Sandbox or Development environments.

This will do the job quickly!!




*Zenon Kowalewski 23 Decemeber 2015



DATA:   lt_evm_hdr         TYPE TABLE OF /saptrx/evm_hdr,

         lt_evm_cst         TYPE TABLE OF /saptrx/evm_cst,

         lt_evm_edl         TYPE TABLE OF /saptrx/evm_edl,

         lt_evm_lai         TYPE TABLE OF /saptrx/evm_lai,

         lt_evm_lid         TYPE TABLE OF /saptrx/evm_lid,

         lt_evm_mer         TYPE TABLE OF /saptrx/evm_mer,

         lt_evm_ned         TYPE TABLE OF /saptrx/evm_ned,

         lt_evm_nev         TYPE TABLE OF /saptrx/evm_nev,

         lt_evm_pai         TYPE TABLE OF /saptrx/evm_pai,

         lt_evm_pid         TYPE TABLE OF /saptrx/evm_pid,

         lt_evm_thd         TYPE TABLE OF /saptrx/evm_thd,

         lt_evm_txl         TYPE TABLE OF /saptrx/evm_txl,

         lt_evm_afb         TYPE TABLE OF /saptrx/evm_afb,

         lt_evm_afc         TYPE TABLE OF /saptrx/evm_afc,

         lt_evm_afh         TYPE TABLE OF /saptrx/evm_afh,

         lt_evm_afr         TYPE TABLE OF /saptrx/evm_afr,

         lt_evm_ref         TYPE TABLE OF /saptrx/evm_ref,

         lt_evm_sta         TYPE TABLE OF /saptrx/evm_sta,

         lt_evm_par         TYPE TABLE OF /saptrx/evm_par,

         lt_evm_eem         TYPE TABLE OF /saptrx/evm_eem,

         lt_evm_doc         TYPE TABLE OF /saptrx/evm_doc,

         lt_evm_0t20e       TYPE TABLE OF /SAPTRX/OT20E,   “remember to add message extension tables

         lt_evm_unpr        TYPE TABLE OF /SAPTRX/EVM_UNPR.

DATA: lt_eh_hdr        TYPE TABLE OF /saptrx/eh_hdr,

       lt_eh_authr      TYPE TABLE OF /saptrx/eh_authr,

       lt_eh_cntrl      TYPE TABLE OF /saptrx/eh_cntrl,

       lt_eh_eehst      TYPE TABLE OF /saptrx/eh_eehst,

       lt_eh_ermsg      TYPE TABLE OF /saptrx/eh_ermsg,

       lt_eh_evmsg      TYPE TABLE OF /saptrx/eh_evmsg,

       lt_eh_expev      TYPE TABLE OF /saptrx/eh_expev,

       lt_eh_info       TYPE TABLE OF /saptrx/eh_info,

       lt_eh_qryid      TYPE TABLE OF /saptrx/eh_qryid,

       lt_eh_seteh      TYPE TABLE OF /saptrx/eh_seteh,

       lt_eh_stat       TYPE TABLE OF /saptrx/eh_stat,

       lt_eh_sthst      TYPE TABLE OF /saptrx/eh_sthst,

       lt_eh_task       TYPE TABLE OF /saptrx/eh_task,

       lt_eh_trkid      TYPE TABLE OF /saptrx/eh_trkid,

       lt_eh_evmad      TYPE TABLE OF /saptrx/eh_evmad,

       lt_eh_measr      TYPE TABLE OF /saptrx/eh_measr,

       lt_eh_mehst      TYPE TABLE OF /saptrx/eh_mehst,

       lt_eh_hier       TYPE TABLE OF /saptrx/eh_hier,

       lt_eh_odt20      TYPE TABLE OF /SAPTRX/ODT20. “remember to add Header extension tables

DATA: ls_eh_hdr        TYPE /saptrx/eh_hdr,

       lv_objectid      TYPE cdhdr-objectid.


*Step 1) Archive


    USING SELECTION-SET  ‘ZEKO’    “name of variant


*Step 2) Delete Event Messages

   SELECT * FROM /saptrx/evm_hdr INTO TABLE lt_evm_hdr.

   SELECT * FROM /saptrx/evm_cst INTO TABLE lt_evm_cst.

   SELECT * FROM /saptrx/evm_edl INTO TABLE lt_evm_edl.

   SELECT * FROM /saptrx/evm_lai INTO TABLE lt_evm_lai.

   SELECT * FROM /saptrx/evm_lid INTO TABLE lt_evm_lid.

   SELECT * FROM /saptrx/evm_mer INTO TABLE lt_evm_mer.

   SELECT * FROM /saptrx/evm_ned INTO TABLE lt_evm_ned.

   SELECT * FROM /saptrx/evm_nev INTO TABLE lt_evm_nev.

   SELECT * FROM /saptrx/evm_pai INTO TABLE lt_evm_pai.

   SELECT * FROM /saptrx/evm_pid INTO TABLE lt_evm_pid.

   SELECT * FROM /saptrx/evm_thd INTO TABLE lt_evm_thd.

   SELECT * FROM /saptrx/evm_txl INTO TABLE lt_evm_txl.

   SELECT * FROM /saptrx/evm_afb INTO TABLE lt_evm_afb.

   SELECT * FROM /saptrx/evm_afc INTO TABLE lt_evm_afc.

   SELECT * FROM /saptrx/evm_afh INTO TABLE lt_evm_afh.

   SELECT * FROM /saptrx/evm_afr INTO TABLE lt_evm_afr.

   SELECT * FROM /saptrx/evm_ref INTO TABLE lt_evm_ref.

   SELECT * FROM /saptrx/evm_sta INTO TABLE lt_evm_sta.

   SELECT * FROM /saptrx/evm_par INTO TABLE lt_evm_par.

   SELECT * FROM /saptrx/evm_eem INTO TABLE lt_evm_eem.

   SELECT * FROM /saptrx/evm_doc INTO TABLE lt_evm_doc.

   SELECT * FROM /SAPTRX/OT20E   INTO TABLE lt_evm_0t20e.

*Remember the Extension tables!

   DELETE /SAPTRX/OT20E     FROM TABLE lt_evm_0t20e.

   DELETE /saptrx/evm_hdr   FROM TABLE lt_evm_hdr.

   DELETE /saptrx/evm_cst   FROM TABLE lt_evm_cst.

   DELETE /saptrx/evm_edl   FROM TABLE lt_evm_edl.

   DELETE /saptrx/evm_lai   FROM TABLE lt_evm_lai.

   DELETE /saptrx/evm_lid   FROM TABLE lt_evm_lid.

   DELETE /saptrx/evm_mer   FROM TABLE lt_evm_mer.

   DELETE /saptrx/evm_ned   FROM TABLE lt_evm_ned.

   DELETE /saptrx/evm_nev   FROM TABLE lt_evm_nev.

   DELETE /saptrx/evm_pai   FROM TABLE lt_evm_pai.

   DELETE /saptrx/evm_pid   FROM TABLE lt_evm_pid.

   DELETE /saptrx/evm_thd   FROM TABLE lt_evm_thd.

   DELETE /saptrx/evm_txl   FROM TABLE lt_evm_txl.

   DELETE /saptrx/evm_afb   FROM TABLE lt_evm_afb.

   DELETE /saptrx/evm_afc   FROM TABLE lt_evm_afc.

   DELETE /saptrx/evm_afh   FROM TABLE lt_evm_afh.

   DELETE /saptrx/evm_afr   FROM TABLE lt_evm_afr.

   DELETE /saptrx/evm_ref   FROM TABLE lt_evm_ref.

   DELETE /saptrx/evm_sta   FROM TABLE lt_evm_sta.

   DELETE /saptrx/evm_par   FROM TABLE lt_evm_par.

   DELETE /saptrx/evm_eem   FROM TABLE lt_evm_eem.

   DELETE /saptrx/evm_doc   FROM TABLE lt_evm_doc.

*Step 3) Delete Unprocessed Messages

  SELECT * FROM /saptrx/evm_unpr INTO TABLE lt_evm_unpr.

  DELETE /saptrx/evm_unpr FROM TABLE lt_evm_unpr.

*Step 4) Delete Event Handlers

   SELECT * FROM /saptrx/eh_hdr INTO TABLE lt_eh_hdr.

   SELECT * FROM /saptrx/eh_authr INTO TABLE lt_eh_authr.

   SELECT * FROM /saptrx/eh_cntrl INTO TABLE lt_eh_cntrl.

   SELECT * FROM /saptrx/eh_eehst INTO TABLE lt_eh_eehst.

   SELECT * FROM /saptrx/eh_ermsg INTO TABLE lt_eh_ermsg.

   SELECT * FROM /saptrx/eh_evmsg INTO TABLE lt_eh_evmsg.

   SELECT * FROM /saptrx/eh_expev INTO TABLE lt_eh_expev.

   SELECT * FROM /saptrx/eh_info  INTO TABLE lt_eh_info.

   SELECT * FROM /saptrx/eh_qryid INTO TABLE lt_eh_qryid.

   SELECT * FROM /saptrx/eh_stat  INTO TABLE lt_eh_stat.

   SELECT * FROM /saptrx/eh_sthst INTO TABLE lt_eh_sthst.

   SELECT * FROM /saptrx/eh_task  INTO TABLE lt_eh_task.

   SELECT * FROM /saptrx/eh_trkid INTO TABLE lt_eh_trkid.

   SELECT * FROM /saptrx/eh_measr INTO TABLE lt_eh_measr.

   SELECT * FROM /saptrx/eh_mehst INTO TABLE lt_eh_mehst.

   SELECT * FROM /saptrx/eh_evmad INTO TABLE lt_eh_evmad.

   SELECT * FROM /saptrx/eh_seteh INTO TABLE lt_eh_seteh.

   SELECT * FROM /saptrx/eh_hier  INTO TABLE lt_eh_hier.

*Extension tables!

   SELECT * FROM /SAPTRX/ODT20    INTO TABLE lt_eh_odt20.

   DELETE /saptrx/eh_hdr FROM TABLE lt_eh_hdr.

   DELETE /saptrx/eh_authr FROM TABLE lt_eh_authr.

   DELETE /saptrx/eh_cntrl FROM TABLE lt_eh_cntrl.

   DELETE /saptrx/eh_eehst FROM TABLE lt_eh_eehst.

   DELETE /saptrx/eh_ermsg FROM TABLE lt_eh_ermsg.

   DELETE /saptrx/eh_evmsg FROM TABLE lt_eh_evmsg.

   DELETE /saptrx/eh_expev FROM TABLE lt_eh_expev.

   DELETE /saptrx/eh_info  FROM TABLE lt_eh_info.

   DELETE /saptrx/eh_qryid FROM TABLE lt_eh_qryid.

   DELETE /saptrx/eh_stat  FROM TABLE lt_eh_stat.

   DELETE /saptrx/eh_sthst FROM TABLE lt_eh_sthst.

   DELETE /saptrx/eh_task  FROM TABLE lt_eh_task.

   DELETE /saptrx/eh_trkid FROM TABLE lt_eh_trkid.

   DELETE /saptrx/eh_measr FROM TABLE lt_eh_measr.

   DELETE /saptrx/eh_mehst FROM TABLE lt_eh_mehst.

   DELETE /saptrx/eh_evmad FROM TABLE lt_eh_evmad.

   DELETE /saptrx/eh_seteh FROM TABLE lt_eh_seteh.

   DELETE /saptrx/eh_hier  FROM TABLE lt_eh_hier.

   DELETE /SAPTRX/ODT20    FROM TABLE lt_eh_odt20.

* delete corresponding change documents

   LOOP AT lt_eh_hdr INTO ls_eh_hdr.

     MOVE ls_eh_hdr-eh_guid TO lv_objectid.



         objectclass                       = ‘/SAPTRX/EH_DATA’

         objectid                          = lv_objectid


         no_authority                      = 1

         no_changes_found                  = 2

         OTHERS                            = 3.

    IF sy-subrc <> 0.






You must be Logged on to comment or reply to a post.
    • Hi Steffen.

      I think the standard programs require a Residence time setting up and the minimum is 1 day which means you have to wait a day before you can delete the previous day.

      The program I wrote ignores Residence time.  Maybe useful if you want to delete all EH related data in a test environment..



      • Hi Zenon,

        Yes you are right.

        If we don’t give residence time then SAP EM takes default 100 days or else we need to specify minimum value e-g 1 day as you said.