Skip to Content

You can use Supply Chain Event Management (SCEM) to manage the statuses of your business processes. To communicate with SCEM you need to send it events. There are several ways of sending events to SCEM including via IDoc, BAPI call, RFC call and XML call.
The syntax for sending an event using the BAPI /SAPTRX/BAPI_EH_ADDEVENTMSG_02 is described in detail below.
In addition to showing you how to call the BAPI it also shows how to call the BAPI using a specific outbound queue name.

Here is the extract of ABAP code dealing with calling /SAPTRX/BAPI_EH_ADDEVENTMSG_02:

  data :

** Event Message data<br />         ls_trackingheader type /saptrx/bapi_evm_header,<br />         ls_trackeemodify  type /saptrx/bapi_evm_ee_modify,<br />         lv_evtcnt type /saptrx/bapi_evm_header-evtcnt,<br />         lv_modcnt type /saptrx/bapi_evm_header-evtcnt,<br /><br />* BAPI Structures<br />         lt_bapi_evm_header type standard table of /saptrx/bapi_evm_header,<br />         lt_trackeemodify   type standard table of /saptrx/bapi_evm_ee_modify,<br />         lt_bapireturn      type standard table of bapiret2,<br /><br />* Working variables<br />         new_date type sy-datum,<br />         new_time type sy-uzeit,<br /><br />* BAPI Calling structures<br />         v_last_digit,<br />         v_queue type trfcqout-qname,<br />         lt_trxserv type standard table of /saptrx/trxserv,<br />         lw_trxserv type /saptrx/trxserv. <br /><br />*** SET HEADER DATA FOR EVENT **<br />   Tracking ID = **** MODIFY EXPECTED EVENT ENTRY **<br />  ls_trackeemodify-evtcnt = lv_evtcnt.
  ls_trackeemodify-evtact = ‘I’.   “Insert, U=Update, D=Delete
  ls_trackeemodify-language = sy-langu.

**   Set new message and actual Event Date / Time / Timezone
*  New_date = sy-datum + 1.
  New_time = sy-uzeit.
  ls_trackeemodify-etxdat = ls_trackeemodify-msgdat = new_date.
  ls_trackeemodify-etxtim = ls_trackeemodify-msgtim = new_time.
  ls_trackeemodify-evtid    = ‘INV_CREATED’.
  lv_modcnt = lv_modcnt + 1.
  ls_trackeemodify-modcnt = lv_modcnt.
  append ls_trackeemodify to lt_trackeemodify.

  case v_last_digit.
    when 1 or 2.
      concatenate ‘Z_SORDER’ ‘A’ into v_queue.
    when 3 or 4.
      concatenate ‘Z_SORDER’ ‘B’ into v_queue.
    when 5 or 6.
      concatenate ‘Z_SORDER’ ‘C’ into v_queue.
    when 7 or 8.
      concatenate ‘Z_SORDER’ ‘D’ into v_queue.
    when 9 or 0.
      concatenate ‘Z_SORDER’ ‘E’ into v_queue.
  condense v_queue.

  call function ‘TRFC_SET_QUEUE_NAME’
      qname                    = v_queue
     invalid_queue_name       = 1
     others                   = 2 .

  if sy-subrc <> 0.
    Message i999(b1) with ‘Failed to change queue name!’.

**** CALL BAPI **<br /> Get tracking servers
*  select * from /saptrx/trxserv into table lt_trxserv.
  if sy-subrc <> 0.
    message w021(/saptrx/asc).

  loop at lt_trxserv into lw_trxserv.

    if not lt_bapi_evm_header[] is initial.

      call function ‘/SAPTRX/BAPI_EH_ADDEVENTMSG_02’
        in background task
        destination lw_trxserv-rfcdest
          simulate           = space
          synchronous        = space
          eh_generation_mode = ‘N’
          trackingheader     = lt_bapi_evm_header
          trackeemodify      = lt_trackeemodify
          return             = lt_bapireturn.

** Set queue for the Commit as well
*      call function ‘TRFC_SET_QUEUE_NAME’
          qname                    = v_queue
         invalid_queue_name       = 1
         others                   = 2 .

      if sy-subrc <> 0.
    Message i999(b1) with ‘Failed to change queue name!’.

      call function ‘BAPI_TRANSACTION_COMMIT’
        in background task
        destination lw_trxserv-rfcdest.

     refresh lt_bapi_evm_header.
    refresh lt_trackeemodify.
    refresh lt_bapireturn.


To report this post you need to login first.


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

  1. Former Member
    Heyy Kevin, Thanks a lot for this blog.

    Being new to SCEM I was searching some documentation, this will definetly help a lot.

    Again Thanks,

  2. Christopher Solomon
    Kevin, it’s always nice to read your blogs….always good stuff. Question for you on SCEM that is slightly off topic to this blog…..why/where would you choose SCEM? What components make up SCEM? Why not just use some assemblage of XI along with Workflow? How are the capabilities different/same?
    1. Former Member Post author
      Great question. Got that same one from a potential client last week and they ended up sold on SCEM….
      SCEM measures a process against a plan. You could possibly equate the deadline functionality in workflow to the expected event overdue monitor capability in SCEM but SCEM has far more flexibility and depth. I’ll tell you more after the next point. The 2nd point is that SCEM is made for status reporting. i.e. You receive an event, SCEM processes it to the correct process instance and updates it’s status. Then, through standard tools, it’s immediately available to the world via web reporting or SAP reporting or BW.
      Regarding workflow and SCEM the BIG differentiating fact is that SCEM tracks both the event dates / times as well as the event message date and time. Workflow has no concept of this. A good way to describe this is through an example.

      E.g. In EDI we hope to receive an ASN back from our vendor stating that they sent our package to our customer at 3PM. We expect them to notify us within 1 hour that they have sent the package. At least that is the plan.

      In SCEM we can track, measure, report on and act on the following possibilities:
      – The Vendor sends the package at 3PM but only sends us the message at 5PM (1 hour after we planned to receive the MESSAGE). The message states that the package was sent on time i.e. THE EVENT itself was on time, but the EVENT MESSAGE was late. We can choose to react to the lateness of this message by sending an alert, starting a workflow, sending an email, running some ABAP….
      – The vendor could send us an ASN at 4PM telling us that they sent the package at 3:50PM. i.e. the event is late but the message was on time….
      – The day goes by and no event is received. The overdue monitor picks up on this and reacts according to the code that you configure… i.e. It can do about anything again.

      In SCEM you can specify the interval that is acceptable for an expected event or message to arrive. Based on when the event arrives and what data it contains we can react any way we choose.

      Workflow is good, at an operational level ensuring that thinks flow smoothly and that work is distributed evenly amongst a team and helps ensure quality but it’s not a good tool to show status of a process or processes. That’s what SCEM does. It shows the status of your process or processes and allows you to easily analyze the steps between them to see if you need to tweak the process. (The tweaking doesn’t happen in SCEM, that happens in the application system and workflow is good for that)

      SCEM is also the bomb when it comes to exception handling wrt events and event messages that occur outside our predefined SLAs.

      I hope that helps out a little.


  3. Former Member
       I am using BAPI ‘/SAPTRX/BAPI_EH_ADDEVENTMSG_02’for updating the expected event times for a particular Event id by populating the structure trackeemodify. But i am failing to do so. Can you please explain where i am going wrong.
    Thanks for the blog, it really helped me. I have done the same way as u had shown in the program for populating the  trackeemodify structure.

    Abhishek Raj.

  4. Former Member
    Hi and thanks for some really useful information on SCEM.
    One question/comment with regards to the WLC, how can this be installed and communication to SCEMbackend to gurantee high security? My customer does not accept http-calls through the firewall but would prefer safer ways such as XML or RFC/BAPI calls to update the information entered in the WCL. Do you have any experience / ideas on how to achieve this? I have looked desperately for information about this and quality answers will be rewarded.
    All the best, Fredrik

    1. Former Member Post author
      The WCL runs on the SCM server itself. I’m not sure there is even an option to decouple it from the SCEM back-end like you can with the ITS W-Gate as an example.

      Also, the WCL does not contain any data, it’s merely a presentation layer. The data is housed in the SCEM database. You can access the data using RFC, BAPI, XML, IDoc, no problem.

      We wrote a flex application calling BAPIs to get the data out of SCEM. The new version 5.1 has added a Web Dynpro application as a UI option as well as the WCL to support those that use it.

        1. Former Member Post author
          Sure Mario,
          We have a SAP EM group going where are discussing all things SAP EM. You’ve been invited to be a member there and you can post your specific question there to be answered by several other SAP EM consultants including myself.
    2. Former Member Post author
      We have started a SAP Event Management forum for consultants and customers involved with the topic. If you’d like to be a part of the group then send me an email kevin (at) requesting to be added as it’s by invitation only.
  5. Martin Reiner Elsner
    Hi Kevin,

    some questions concerning this topic (I thought it would be helpful to post it here instead of the forum):

    1. Why do you choose different queues for sending the event? Is it only meant as example?

    2. As far as I understand the EM implementation, in standard SAP events are always created out of the fu /SAPTRX/EVENT_MGR_COMMUNICATE which uses all the customizing settings to decide which events have to be sent to EM. So there are two ways to send events, one very direct (described above) and the big and customizable way that also handles Event Handler creation. So what should be the best way to use? I think /SAPTRX/EVENT_MGR_COMMUNICATE is only useful if there’s not yet a handler created, else the small BAPI call should be used.

    Best regards

    1. Former Member Post author
      1) No, it helps with performance to split the queues for parallel processing. also if a transaction dumps for any reason only that queues entries are delayed until the dump is removed but all the other queues move along. This is why you have to make sure that all the relevant messages for an EH all go to the same queue. This maintains the integrity of each EH
      2) These are 2 of the ways yes. There are more like XML and IDoc that you can use. I would use the configuration option as my first choice. It in fact also ends up calling that BAPI. The only reason to use the config as apposed to the BAPI would be that it’s easier to support. More people can understand and support configuration whereas the BAPI option all lies in a developers hands with very specialized knowledge.
      What ends up happening at an implementation is a combination of both and sometimes the IDocs as well (for EDI related docs like the 214 and POD).
      No concrete answer is there, just a preference.
  6. Former Member
    Hi Kevin
    Your blogs are very helpful for a person like who is just starting off on SAP EM.

    Can you throw some light as to how SAP EM integrates with SAP BPM or 3rd party BPM engines?

    Vijay Swaminathan


Leave a Reply