Skip to Content

Almost all SAP EM implementations comes with it’s fair share of coding. I would say that most of the coding occurs on the data extraction side (on the application system) but there are occasions where we need to create a unique response to an event when it arrives for processing on SAP EM. One of the ways to accomplish this would be through the creation of a custom rule set activity. In this document I will describe some features, with code snippets, that will show you how to go about pulling the needed data for your function.

act1.JPG

I assume that you already know where to go to create a rule set funtion so lets get started with understanding the code…

Declarations of a rule set function

  DATA: l_eh_data         TYPE /saptrx/eh_data,

      ls_hdr            TYPE /saptrx/eh_hdr_dyn,
     ls_cntrl         
TYPE /saptrx/eh_cntrl_dyn,
     lt_cntrl         
TYPE /saptrx/eh_cntrl_tab,
     l_eh_flags       
TYPE /saptrx/eh_access_flags,
     l_model          
TYPE REF TO /saptrx/cl_eh_event_msg_model,
     l_evm_data       
TYPE /saptrx/evm_tables,
     ls_evm_hdr       
TYPE /saptrx/evm_hdr_str,
     l_evt_guid       
TYPE /saptrx/ev_guid,
     ls_evmsg         
TYPE /saptrx/eh_evmsg_dyn,
     lt_eh_evmsg      
TYPE STANDARD TABLE OF /saptrx/eh_evmsg_dyn,

      l_parameters      TYPE /saptrx/evm_par_stru,
     l_param1         
TYPE /saptrx/function_param,
      l_arg_1           TYPE /saptrx/msg_var,
      ls_evm_header     TYPE /saptrx/evm_hdr_str,
      ls_bapi_cntrl    
TYPE /saptrx/eh_cntrl_dyn,
     ls_tspardc       
TYPE /saptrx/tspardc.

Retrieving Data

Retrieving Activity Parameters

act2.JPG

  DATA:

     l_param1          TYPE /saptrx/function_param,
     l_arg_1           TYPE /saptrx/msg_var,

* First parameter:
l_param1
= i_eaitaskparam_1.

* If parameter has a meta data element like <EVENT_MSG-HDR-TRXCOD> then:
l_arg_1
= i_eaieh_model->get_activity_meta_data(
i_eai
= i_eai
i_meta_data
= l_param1 ).


Retrieving EH Detail

  DATA: l_eh_data         TYPE /saptrx/eh_data,

      l_eh_flags        TYPE /saptrx/eh_access_flags.


l_eh_flags
evm_ext =
l_eh_flags
evmsg    =
l_eh_flags
cntrl   = ‘X’.
l_eh_data
= i_eaieh_model->eh_data( l_eh_flags ).


Available Flags

AUTHR

CNTRL

EEHST

ERMSG

EVMSG

EXPEV

INFO

QRYID

STAT

STHST

TASK

TRKID

EVM_HDR

CONS_EVT

HDR_EXT

EHSET

MEASR

MEHST

FILES

HIER

TRKTYPE

EVM_EXT

EVM_DOC

Tables in L_EH_DATA

Component

Table Type

Row Type

HDR

/SAPTRX/EH_HDR_DYN

/SAPTRX/EH_HDR_DYN

Significant fields:

EH_GUID                     /SAPTRX/EH_GUID                     Event Handler: Globally Unique ID

TRACKINGIDTYPE     /SAPTRX/TRXCOD                      Tracking ID Code Set

TRACKINGID              /SAPTRX/TRXID                           Tracking ID

AO_SYSTEM               /SAPTRX/APPSYSTEMNAME      Application System Name

AO_CLIENT                 /SAPTRX/AO_CLIENT                 Application Object Client

AO_TYPE                    /SAPTRX/AOTYPE                       Application Object Type

AO_ID                          /SAPTRX/AOID                             Application Object

BUS_PROC_TYPE      /SAPTRX/TRK_OBJ_TYPE          Business Process Type

EH_TYPE                     /SAPTRX/TRK_TYPE                   Event Handler Type

EH_ACTIVE                 /SAPTRX/EH_ACTIVE                  Event Handler Is Active

EH_DELETED             /SAPTRX/EH_DELETE                 Event Handler Has Been Deleted

EH_CHANGEABLE     /SAPTRX/EH_CHANGEABLE      Event Handler Changeable Indicator

ACTIVE_DATE            /SAPTRX/ACTIVE_DATETIME    Event Handler Active Time Stamp

INACTIVE_DATE         /SAPTRX/INACTIVE_DATETIME Inactive Date/Time

EH_ARCHIVED           /SAPTRX/EH_ARCHIVED            Event Handler Archived

UPDATE_IND              UPDKZ_D                                     Update indicator

HDR_EXT

/SAPTRX/EH_HDR_EXT_DYN

/SAPTRX/EH_HDR_EXT_DYN

Significant fields:

EH_GUID                     /SAPTRX/EH_GUID                     Event Handler: Globally Unique ID

EXT_TABLE_TYPE     /SAPTRX/EXT_TABLE_TYPE      Extension Table Type

EXT_TABLE_ID           /SAPTRX/EXT_TABLE_ID            Extension Table Identifier

EXT_TABLE_NAME    /SAPTRX/EXT_TABLE_NAME     Extension Table Name

EXT_TABLE_LINE       /SAPTRX/EXT_TABLE_LINE       Extension Table Line

                                     This line has the type of your EH extension table

UPDATE_IND              UPDKZ_D                                     Update indicator

AUTHR

/SAPTRX/EH_AUTHR_TAB

/SAPTRX/EH_AUTHR_DYN

CNTRL

/SAPTRX/EH_CNTRL_TAB

/SAPTRX/EH_CNTRL_DYN

Significant fields:

EH_GUID                     /SAPTRX/EH_GUID                     Event Handler: Globally Unique ID

SEQ_NBR                    /SAPTRX/SEQUENCE_NBR        Sequence

PARAM_NAME            /SAPTRX/PARAMNAME               Parameter

PARAM_INDEX           /SAPTRX/INDEXCOUNTER        Index Counter

PARAM_VALUE           /SAPTRX/PARAMVALUE_60       Parameter Value of Length 60

PARAM_LENGTH       /SAPTRX/PARAMVALUELENGTH   Parameter Value Length

PARAM_TYPE             DATATYPE_D                              Data Type in ABAP Dictionary

LANGUAGE                 SPRAS                                          Language Key

UPDATE_IND              UPDKZ_D                                     Update indicator

EEHST

/SAPTRX/EH_EEHST_TAB

/SAPTRX/EH_EEHST_DYN

ERMSG

/SAPTRX/EH_ERMSG_TAB

EVMSG

/SAPTRX/EH_EVMSG_TAB

Significant fields:

EH_GUID                         /SAPTRX/EH_GUID                             Event Handler: Globally Unique ID

MSG_GUID                     /SAPTRX/EV_GUID                              Event: Globally Unique ID

EVENT_CODE                /SAPTRX/EVENT_CODE                     Internal Event Code

PROC_DATE                   /SAPTRX/PROCESSED_DATETIME   Processed Time Stamp

EARLIEST_MSG_DTE    /SAPTRX/EARLIEST_MSG_EXP_DATE      Earliest Expected Msg Date/Time

LATEST_MSG_DATE     /SAPTRX/LATEST_MSG_EXP_DATE Latest Message Expected Date/Time

MSG_EXP_TZONE         /SAPTRX/TIMEZONE                           Time Zone

MSG_RCVD_DATE         /SAPTRX/MSG_RCVD_DATETIME     Event Message Received Date/Time

MSG_RCVD_TZONE      /SAPTRX/TIMEZONE                           Time Zone

EARLIEST_EV_DATE     /SAPTRX/EARLIEST_EVT_EXP_DATE        Earliest Expected Event Date/Time

LATEST_EV_DATE         /SAPTRX/LATEST_EVT_EXP_DATE  Latest Event Expected Date/Time

EVENT_EXP_TZONE     /SAPTRX/TIMEZONE                           Time Zone

EVENT_DATE                 /SAPTRX/EVENT_DATETIME             Date/Time an Event Occurred

EVENT_TZONE              /SAPTRX/TIMEZONE                           Time Zone

MSG_DATE_UTC           /SAPTRX/MSG_RCVD_DATETIME     Event Message Received Date/Time

EVENT_DATE_UTC        /SAPTRX/EVENT_DATETIME             Date/Time an Event Occurred

SEQ_NBR                        /SAPTRX/SEQUENCE_NBR                Sequence

NOT_RELEVANT            /SAPTRX/MSG_NOT_RELEVANT      Message Not Relevant for Event Handler

BUILT_EH_HIER             /SAPTRX/BUILT_EH_HIER                  EH Hierarchy Built with Event Message

UPDATE_IND                  UPDKZ_D                                             Update indicator

EVMAD

/SAPTRX/EH_EVMAD_TAB

EXPEV

/SAPTRX/EH_EXPEV_TAB

Significant fields:

EH_GUID                         /SAPTRX/EH_GUID                       Event Handler: Globally Unique ID

SEQ_NBR                        /SAPTRX/EE_SEQ_NBR                Expected Event Sequence Number

GROUP_NBR                  /SAPTRX/EE_GRP_NBR               Expected Event Group

ITEM_NBR                       /SAPTRX/EE_ITEM_NBR               Expected Event Item

EVENT_CODE                /SAPTRX/EVENT_CODE               Internal Event Code

EVENT_GROUP             /SAPTRX/EVENT_CODE_GRP     Internal Event Code Group

EVENT_STATUS             /SAPTRX/EE_EVENT_STATUS     Event Status

MSG_STATUS                /SAPTRX/EE_MSG_STATUS        Event Message Status

PARTNER_ID_TYPE       /SAPTRX/EV_PARCOD                 Partner Code Set

PARTNER_ID                  /SAPTRX/EV_PARID                      Partner Code ID

LOC_ID_TYPE                /SAPTRX/EV_LOCCOD                 Location Code Set

LOC_ID_1                        /SAPTRX/EV_LOCID1                    Location Code ID, Part 1

LOC_ID_2                        /SAPTRX/EV_LOCID2                    Location Code ID, Part 2

MSG_EXP_DATE            /SAPTRX/MSG_EXP_DATETIME  Event Message Expected Date/Time

MSG_EXP_TZONE         /SAPTRX/TIMEZONE                     Time Zone

EARLIEST_MSG_DTE    /SAPTRX/EARLIEST_MSG_EXP_DATE      Earliest Expected Msg Date/Time

LATEST_MSG_DATE     /SAPTRX/LATEST_MSG_EXP_DATE          Latest Message Expected Date/Time

MSG_RCVD_DATE         /SAPTRX/MSG_RCVD_DATETIME              Event Message Received Date/Time

MSG_DATE_UTC           /SAPTRX/MSG_RCVD_DATETIME              Event Message Received Date/Time

MSG_RCVD_TZONE      /SAPTRX/TIMEZONE                     Time Zone

EVENT_EXP_DATE        /SAPTRX/EVENT_EXP_DATETIME             Date/Time Event Expected to Occur

EVENT_EXP_TZONE     /SAPTRX/TIMEZONE                     Time Zone

EARLIEST_EV_DATE     /SAPTRX/EARLIEST_EVT_EXP_DATE        Earliest Expected Event Date/Time

LATEST_EV_DATE         /SAPTRX/LATEST_EVT_EXP_DATE           Latest Event Expected Date/Time

EVENT_DATE                 /SAPTRX/EVENT_DATETIME       Date/Time an Event Occurred

EVENT_DATE_UTC        /SAPTRX/EVENT_DATETIME       Date/Time an Event Occurred

EVENT_TZONE              /SAPTRX/TIMEZONE                     Time Zone

DATACS                          /SAPTRX/DATA_CODE_SET        Data Code Set

DATAID                            /SAPTRX/DATA_CODE_ID            Data Code ID

INFO

/SAPTRX/EH_INFO_TAB

Significant fields:

EH_GUID                     /SAPTRX/EH_GUID                           Event Handler: Globally Unique ID

SEQ_NBR                    /SAPTRX/SEQUENCE_NBR              Sequence

PARAM_NAME            /SAPTRX/PARAMNAME                     Parameter

PARAM_INDEX           /SAPTRX/INDEXCOUNTER              Index Counter

PARAM_VALUE           /SAPTRX/PARAMVALUE_255           Parameter Value of Length 255

PARAM_LENGTH       /SAPTRX/PARAMVALUELENGTH    Parameter Value Length

PARAM_TYPE             DATATYPE_D                                    Data Type in ABAP Dictionary

LANGUAGE                 SPRAS                                                Language Key

QRYID

/SAPTRX/EH_QRYID_TAB

STAT

/SAPTRX/EH_STAT_TAB

Significant fields:

EH_GUID                   /SAPTRX/EH_GUID                             Event Handler: Globally Unique ID

STATUS_TYPE         /SAPTRX/STATUS_TYPE                    Status Attribute Name

CODE_TYPE             /SAPTRX/STATUS_CODE_TYPE       Status Attribute Type

MSG_TYPE               /SAPTRX/STATUS_MSG_TYPE          Status Attribute Message Type

STATUS_CODE        /SAPTRX/STATUS_CODE                   Status Attribute Value

STATUS_DATE         /SAPTRX/STATUS_DATETIME           Status Updated

STHST

/SAPTRX/EH_STHST_TAB

TASK

/SAPTRX/EH_TASK_TAB

TRKID

/SAPTRX/EH_TRKID_TAB

Significant fields:

MEASR

/SAPTRX/EH_MEASR_TAB

MEHST

/SAPTRX/EH_MEHST_TAB

HIER

/SAPTRX/EH_HIER_TAB

EVM_TABLES

/SAPTRX/EVM_TABLES

Significant fields:

Retrieving Event Message Detail

  DATA: l_model           TYPE REF TO /saptrx/cl_eh_event_msg_model,
      l_evm_data       
TYPE /saptrx/evm_tables.

* get Event Message data
l_model ?= i_eai
eh_model.
CALL METHOD l_model->evm_data
  
IMPORTING
     e_evm_data
= l_evm_data.

Tables in L_EVM_DATA

Component

Table Type

Row Type

HEADER

/SAPTRX/EVM_HDR_TABTYP

/SAPTRX/EVM_HDR_STR

Significant fields:

EVT_GUID             /SAPTRX/EV_GUID

EVTCOD                /SAPTRX/EV_EVTCOD

EVTID                     /SAPTRX/EV_EVTID

INT_EV_COD        /SAPTRX/EVENT_CODE

TRXCOD                /SAPTRX/TRXCOD

TRXID                    /SAPTRX/TRXID

IDOCID                  EDI_DOCNC3

EVTDAT                 /SAPTRX/EV_EVTDAT

EVTTIM                  /SAPTRX/EV_EVTTIM

EVTZON                 /SAPTRX/EV_EVTZON

REPDAT                /SAPTRX/EV_REPDAT

REPTIM                  /SAPTRX/EV_REPTIM

REPZON                /SAPTRX/EV_REPZON

PRCTST                 /SAPTRX/EV_PRCTST

SNDCOD               /SAPTRX/EV_SNDCOD

SNDID                    /SAPTRX/EV_SNDID

SNDNAM                /SAPTRX/EV_SNDNAM

LOCCOD               /SAPTRX/EV_LOCCOD

LOCID1                  /SAPTRX/EV_LOCID1

LOCID2                  /SAPTRX/EV_LOCID2

SRCCOD               /SAPTRX/EV_SRCCOD

SRCID                    /SAPTRX/EV_SRCID

SRCTX                   /SAPTRX/EV_SRCTX

DATACS                 /SAPTRX/DATA_CODE_SET

DATAID                  /SAPTRX/DATA_CODE_ID

SEQ_NUM_MULT /SAPTRX/SEQ_NUM

LOCATION_ID

/SAPTRX/EVM_LID_TABTYP

/SAPTRX/EVM_LID_STR

LOC_ADD_ID

/SAPTRX/EVM_LAI_TABTYP

/SAPTRX/EVM_LAI_STRU

PARTNER_ID

/SAPTRX/EVM_PID_TABTYP

/SAPTRX/EVM_PID_STRU

PTR_ADD_ID

/SAPTRX/EVM_PAI_TABTYP

/SAPTRX/EVM_PAI_STRU

EE_MODIFY

/SAPTRX/EVM_EEM_TTYP

/SAPTRX/EVM_EEM

Significant fields:

Event Detail:

EVT_GUID     /SAPTRX/EV_GUID

SEQ_NUM     /SAPTRX/SEQ_NUM

MODCNT       /SAPTRX/MODCNT

EVTCOD        /SAPTRX/EV_EVTCOD

EVTID             /SAPTRX/EV_EVTID

EVTACT         /SAPTRX/EV_UPDKZ

LOCCOD       /SAPTRX/EV_LOCCOD

LOCID1          /SAPTRX/EV_LOCID1

LOCID2          /SAPTRX/EV_LOCID2

DATACS         /SAPTRX/DATA_CODE_SET

DATAID          /SAPTRX/DATA_CODE_ID

Estimated Date / Time:

ETXDAT         /SAPTRX/EV_ETXDAT

ETXTIM          /SAPTRX/EV_ETXTIM

ETXZON        /SAPTRX/EV_ETXZON

Earliest Estimated Date / Time:

ETEADT         /SAPTRX/EV_ETEADT

ETEATI           /SAPTRX/EV_ETEATI

Latest Estimated Date / Time:

ETLTDT         /SAPTRX/EV_ETLTDT

ETLTTI           /SAPTRX/EV_ETLTTI

Estimated Event Message Date / Time / Zone:

MSGDAT        /SAPTRX/EV_MSGDAT

MSGTIM         /SAPTRX/EV_MSGTIM

MSGZON       /SAPTRX/EV_MSGZON

Earliest Estimated Event Message Date / Time:

MSEADT        /SAPTRX/EV_MSEADT

MSEATI          /SAPTRX/EV_MSEATI

Latest Estimated Event Message Date / Time:

MSLTDT         /SAPTRX/EV_MSLTDT

MSLTTI          /SAPTRX/EV_MSLTTI

EST_DEADL

/SAPTRX/EVM_EDL_TABTYP

/SAPTRX/EVM_EDL_STRU

CONF_STAT

/SAPTRX/EVM_CST_TABTYP

/SAPTRX/EVM_CST_STRU

NEXT_EVENT

/SAPTRX/EVM_NEV_TABTYP

/SAPTRX/EVM_NEV_STRU

NXT_EV_DEADL

/SAPTRX/EVM_NED_TABTYP

/SAPTRX/EVM_NED_STRU

FURTHER_REF

/SAPTRX/EVM_REF_TABTYP

/SAPTRX/EVM_REF_STRU

Significant fields:

EVT_GUID         /SAPTRX/EV_GUID

SEQ_NUM          /SAPTRX/SEQ_NUM

REFCOD            /SAPTRX/REFCOD

REFID                 /SAPTRX/REFID

REFUSAGE        /SAPTRX/FREFUSE

Q      Query ID
T       Tracking ID
A       Additional Reference
E       Add Event Handlers to Process
D       Document Reference ID
M      Multiple Tracking IDs

ACTION              /SAPTRX/FR_ACTION

<blank>   Leave unchanged
A             Activate
D             Deactivate

START_DATE    /SAPTRX/TID_START_DATE

START_TIME     /SAPTRX/TID_START_TIME

END_DATE        /SAPTRX/TID_END_DATE

END_TIME         /SAPTRX/TID_END_TIME

TIMZON             /SAPTRX/TID_TZONE

APPSYS            /SAPTRX/APPSYSTEMNAME

APPOBJTYPE    /SAPTRX/AOTYPE

APPOBJID          /SAPTRX/AOID

MEAS_RESULT

/SAPTRX/EVM_MER_TABTYP

/SAPTRX/EVM_MER_STRU

STATUS_ATTR

/SAPTRX/EVM_STA_TABTYP

/SAPTRX/EVM_STA_STRU

PARAMETERS

/SAPTRX/EVM_PAR_TABTYP

/SAPTRX/EVM_PAR_STRU

Significant fields:

EVT_GUID             /SAPTRX/EV_GUID

SEQ_NUM             /SAPTRX/SEQ_NUM

PARTYP                 /SAPTRX/ASPARTYP (C-Control, I-Info)

PARAM_NAME      /SAPTRX/PARAMNAME

PARAM_INDEX      /SAPTRX/INDEXCOUNTER

PARAM_VALUE     /SAPTRX/PARAMVAL200

ACTION                 /SAPTRX/ACTION (S-Set (create), C-Change, D-Delete, M-Check)

FILE_HEADER

/SAPTRX/EVM_AFH_TABTYP

/SAPTRX/EVM_AFH_STR

FILE_REFERENCE

/SAPTRX/EVM_AFR_TABTYP

/SAPTRX/EVM_AFR_STR

FILE_BIN

/SAPTRX/EVM_AFB_TABTYP

/SAPTRX/EVM_AFB_STR

FILE_CHAR

/SAPTRX/EVM_AFC_TABTYP

/SAPTRX/EVM_AFC_STR

TEXT_HDR

/SAPTRX/EVM_THD_TABTYP

/SAPTRX/EVM_THD_STRU

TEXT_LINES

/SAPTRX/EVM_TXL_TABTYP

/SAPTRX/EVM_TXL_STRU

HDR_EXT

/SAPTRX/EVM_HDR_EXT_TAB

/SAPTRX/EVM_HDR_EXT_DYN

Significant fields:

EVT_GUID                 /SAPTRX/EV_GUID

EXT_TABLE_TYPE    /SAPTRX/EXT_TABLE_TYPE

EXT_TABLE_ID         /SAPTRX/EXT_TABLE_ID

EXT_TABLE_NAME   /SAPTRX/EXT_TABLE_NAME

EXT_TABLE_LINE     /SAPTRX/EXT_TABLE_LINE

UPDATE_IND            UPDKZ_D

DOCUMENT_REF

/SAPTRX/EVM_DOC_TABTYP

/SAPTRX/EVM_DOC_STRU

Updating Data

Updating a Control Parameter

  DATAl_eh_data         TYPE /saptrx/eh_data,
      ls_cntrl          TYPE /saptrx/eh_cntrl_dyn,

             ls_bapi_cntrl     TYPE /saptrx/eh_cntrl_dyn.

  LOOP AT l_eh_datacntrl INTO ls_cntrl
  
WHERE param_name ‘ZEMC_UPDATE_QTY.

        ls_bapi_cntrlparam_value = lv_update_qty.
  
CONDENSE ls_bapi_cntrlparam_value.

      ls_bapi_cntrlupdate_ind  = ‘U’.
      ls_bapi_cntrl
eh_guid     = l_eh_datahdreh_guid.
     ls_bapi_cntrl
param_value = ls_cntrlparam_value.
     ls_bapi_cntrl
param_name  = ls_cntrlparam_name.
     ls_bapi_cntrl
param_index = ls_cntrlparam_index.
     ls_bapi_cntrl
seq_nbr     = ls_cntrlseq_nbr.
     ls_bapi_cntrl-language
       = sylangu.
     ls_bapi_cntrl
param_type  = ‘C’.
     ls_bapi_cntrl
param_length = ’15’.

* Add/change/delete control parameter
CALL METHOD i_eaieh_model->set_cntrl_parameter
  
EXPORTING
     i_eh_cntrl
= ls_bapi_cntrl
   RECEIVING
     result    
= lv_result.

  ENDLOOP.

To report this post you need to login first.

1 Comment

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

  1. Kevin Wilson Post author

    Vishnu, Steffen, Kinjal, Daniel and Zenon – Please feel free to edit the document and add other cool features of activity coding to it.

    (0) 

Leave a Reply