Skip to Content
Author's profile photo Kevin Wilson

Processing sequence when posting a SAP EM event using BAPI /SAPTRX/BAPI_EH_ADDEVENTMSG_02

I’ve been asked many times over when things are processed as an event get’s posted in to SAP EM. E.g. When does event validation occur and what does it cover? When is event pre-processing called or EH generation?

  1. Check authorizations
    1. Check SNDCOD and SNDID are in table /SAPTRX/AUTH_SND – If not then continue checking
    2. Authority-check: Object X_EM_EVM: (/SAPTRX/CS, /SAPTRX/CD, ACTVT=32) (See 2.1.1)
  2. Data Pre-Processing
    1. Create EVM and BatchGUID (See 2.2.1)
    2. Convert data to upper case
    3. Convert Tracking IDs (If configured in table /SAPTRX/CONVUSE)
  3. Fill data tables
    1. Assign Header
      1. Assign internal event code using table /SAPTRX/EVENTS
      2. Assign internal reason code using table /SAPTRX/SRCODES
        1. Retrieve reason code text from table /SAPTRX/SRCODEST or /SAPTRX/SRINTCDT
        2. Check that the reason code is assigned to the event using table /SAPTRX/EVC_RC
      3. Assign message mode (MSGMOD) – Created artificially = B
      4. Save mode determination using table /SAPTRX/EVM_SAVE (See 2.3.1)
    2. Assign Location
      1. Map external to internal location codes using function module /SAPTRX/CODE_MAPPING (See 2.2.3)
    3. Assign Partner
      1. Map external to internal partner codes using function module /SAPTRX/CODE_MAPPING (See 2.2.3)
    4. Assign EE Modify
      1. Map external to internal location and partner codes using function module /SAPTRX/CODE_MAPPING (See 2.2.3)
    5. Assign Confirmation Status Table
      1. Map external to internal partner codes using function module /SAPTRX/CODE_MAPPING (See 2.2.3)
    6. Assign Further References
      1. Special case: If REFUSAGE = D then get document type from table /SAPTRX/EXDOC
    7. Assign Measurements
      1. Map external to internal partner codes using function module /SAPTRX/CODE_MAPPING (See 2.2.3)
    8. Assign Status Attribute
    9. Assign Parameters
    10. Create Event Message Header Extension table
      1. Call function /SAPTRX/EXEC_EVM_EXT_PAR_MAP (See 2.2.4)
        1. Maps parameters
        2. Creates Event Message extension table
    11. Assign Attached files
    12. Assign Text header
  4. Set flag for processing by inactive EH
    1. Select from table /SAPTRX/EVMPRIN
  5. Save files to the file system or DB?
    1. Select from table /SAPTRX/MSG_FATD (Message buffering filter)
    2. If file system then generate file name and path
      1. Save ASC (Text) or BIN (Binary) file
  6. Event Message Input Validation
    1. Perform function /SAPTRX/EVTMSGCHECK_02 if BAPI-SKIPCHECK <> X (See 2.2.1)
      1. Assign missing time zones (HDR, EEM, CST, MER)
      2. Ensure MSG and Batch GUID are created
      3. Check event exists in table /SAPTRX/EVCODE -> Error
      4. Check reason code exists in table /SAPTRX/SRINTCOD -> Error
      5. Check TRXCOD is not initial -> Error
      6. Check TRXID is not initial -> Error
      7. Call function /SAPTRX/CHECK_DATETIME to check the date and time (See 2.2.5)
        1. Assigns user’s local time zone if none are filled in
      8. If reporting Date / Time are not entered then assign system values
      9. Delete file tables if no binary or ascii files are found
      10. Check on ATTACHED FILE tables: if mime type is missing, table SDOKMIME and SDOKMIME_C are queried with the file-extension.  Table SDOKMIME is the standard table that contains MIME content type for file name extension; SDOKMIME_C is a customizing table with the same purpose
  7. BAPI override for Event Message Pre-Processing
    1. If BAPI-PREPROCESS_MODE = A then call pre-processing function BAPI-PREPROCESS_FUNCTION
      1. Function module template check: /SAPTRX/EVM_PPF_TEMPL
  8. Prevent processing on error
    1. If BAPI-BLOCKONERRORIN = X then stop processing if an error was found in the validation check
  9. Message Buffering
    1. Call function /SAPTRX/SPLIT_MESSAGE_TABLE_O2
      1. If BAPI-BUFFER_MODE = A (All messages buffered) -> Move to buffer table
      2. If BAPI-BUFFER_MODE =N (No messages buffered) -> Do nothing
      3. Otherwise check buffering table /SAPTRX/MSG_BUFF
    2. Save buffered messages to the database using asynchronous call to function module /SAPTRX/UPDATE_MSG_DB_02
      1. Increase EVM counter for SAP EM licensing audit check using function module SLIM_CNT_INCREASE_COUNTER (See 2.2.6)
      2. Save to the database
        1. Check saving mode from table /SAPTRX/EVM_SAVE
          • <blank>  Entire message is regularly saved in the event message DB
          • N               Event message is not saved
          • L                Only last event message is saved, accounting for evtid, trxcod, trxid, tipcod, tipid.
          • R               Event message is saved with reduced size
          • S                Only last event message is saved, Current message will be inserted in DB, but previous message(s) for the same EH will be deleted. The deletion is accounting for event code, sender and location as specified in /SAPTRX/EVM_SAVE.
          • H               Only the header entry of the event message is saved
        2. Save tables to the database
  10. Process non-buffered messages
    1. If SYNCHRONOUS = X then process now
      1. ELSE process in update task
    2. Set processing timestamp
    3. Update database tables with call to function module /SAPTRX/UPDATE_MSG_DB_02 (Unless in simulation mode)
    4. If reduce message flag is set (Call FM /SAPTRX/SET_REDUCE_MSGS_FLAG explicitly before each BAPI call to reduce the message) then call function /SAPTRX/REBUILD_MSGS
      1. Rebuilt event messages from information in further references if requested in cases only Tracking ID differs in event messages to reduce the disk space
    5. Process the event messages using function /SAPTRX/PROCESS_MESSAGES_02
      1. Check and process EH Generation
        1. If BAPI-GENERATION_MODE = A then call function BAPI-GENERATION_FUNCTION to process events
          1. Template: /SAPTRX/EH_GEN_TEMPL
          2. Call BAPI /SAPTRX/BAPI_EH_POST
        2. ELSE if BAPI-GENERATION_MODE = N = Do Noting
        3. ELSE check customizing table /SAPTRX/EVMEHGEN
      2. Process events using method PROCESS_EVENTS of class /SAPTRX/CL_EVENT_MSG_PROCESSOR
        1. Check buffering
        2. Find EHs -> Method: FIND_EVENT_HANDLERS
          1. If no EH is found save as an unprocessed message
          2. If found then process event for that EH using method: PROCESS_EVENT_MSGS for class /SAPTRX/CL_EH_EVENT_MSG_MODEL
            1. Enqueue EH using AO System, ID Type, ID
              1. Fail -> Log locked EH
            2. Process message
              1. Get rule set
              2. Fill last event date in header
              3. Get EH type
                1. If Change docs are on then write to the buffer before data is changed
              4. Process rules for event 1 at a time
                1. Commit BAPIs
              5. If flag for processing unprocessed messages is set in the rule set then process unprocessed events using method: process_unprocessed_msgs
            3. Dequeue EH, EH Set and Doc Flow

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Prajakta Sonawane
      Prajakta Sonawane


      Thanks for this valuable information.

      We have a question on step # 5 above ('Save files to file system or DB'). Note 1355699 dt. 15.09.2009 indicates 'do not use this function'. However, when we check BAPI, code seems to be active. Just wanted to check if this note is correct and have you used this feature recently?

      Thanks in advance for your clarification.

      Best regards,


      Author's profile photo Anuj Kumar
      Anuj Kumar

      Hi Kevin,


      Thank you for sharing the detailed processing sequence.

      In our system we are sending GR data from SAP ECC to SAP EM system. In our case one GR has data for multiple PO's. Thus the parameter table ( step 3 i, j )  contains multiple parameters with different values e.g. for PO1 it will have say value X for parameter PR1 and for PO2 it will have say value Y for parameter PR1. Now when in loops at it_bapi_hdr and walks through each PO it ends up overwriting PO1 parameter PR1 with value Y i.e. value from second PO.


      Can you review above information and let me know if I am missing anything or if I am doing anything wrong.


      Best Regards,

      Anuj Kumar