cancel
Showing results for 
Search instead for 
Did you mean: 

Posting Events with /SAPTRX/BAPI_EH_POST

georg_puscher
Explorer
0 Kudos

Hello,


I want to post events in Transportation Management for ‘Freight Order/Booking with an own program. I’m using BAPI “/SAPTRX/BAPI_EH_POST”.


Business Requirement is:

Creating Event (e.g. DEPARTURE) for a freight order/booking with event date.


The program does not insert/change the event (in tab "EXECUTION” of freight order)


Remark: we are not using an own system for SAP EM.

SAP TM and SAP EM are running in the same system

I’m using the following settings

In freight order type application object "ODT30_TO" is assigned, allowed events for the order types are:

ARRIV_DEST

COUPLING

DECOUPLING

DEPARTURE

LOAD_BEGIN

LOAD_END

POD

POPU

UNLOAD_BEGIN

UNLOAD_END

The program has the following coding:

Some information to the coding:

  • Application Object ID: “56EAB2E0CCBC5D91E1000000AC101684” is the DB-Key of table /SCMTMS/D_TORROT
  • Control value: 4100000351 is the TOR_ID of table /SCMTMS/D_TORROT

** Fill table prior to BAPI call.

* Mandatory Data

refresh lt_applobjects.

ls_applobjects-appsys     = 'TMXCLNT700'.                                              .

ls_applobjects-appobjtype = 'ODT30_TO'.                                                

ls_applobjects-appobjid   = '56EAB2E0CCBC5D91E1000000AC101684'.     "Freight Order!!!

ls_applobjects-busproctype = 'TMS_TOR'.                                               

ls_applobjects-update_indicator = 'I'.

APPEND ls_applobjects TO lt_applobjects.

*Controldata

refresh lt_controldata.

ls_controldata-appsys     = 'TMXCLNT700'.                           

ls_controldata-appobjtype = 'ODT30_TO'.                             

ls_controldata-appobjid   = '56EAB2E0CCBC5D91E1000000AC101684'.     " Freight Order!!!

ls_controldata-paramname  = 'FREIGHT_ORDER'.

ls_controldata-value      = '4100000351'.                                                    "Freight Order ls_appob.

*ls_controldata-value = ls_prio.

APPEND ls_controldata TO lt_controldata.

*trackingid

ls_trackiddata-appsys     = 'TMXCLNT700'.                         

ls_trackiddata-appobjtype = 'ODT30_TO'  .                        

ls_trackiddata-appobjid   = '56EAB2E0CCBC5D91E1000000AC101684'.    

ls_trackiddata-trxcod     = 'DEPARTURE'.                                                "Event      !!!!!

ls_trackiddata-trxid      = '56EAB2E0CCBC5D91E1000000AC101684'.       "Freight Order

ls_trackiddata-START_DATE = sy-datum - 1.                        

ls_trackiddata-msrid      = 'X'.

*ls_trackiddata-msrid = 'X'.

APPEND ls_trackiddata TO lt_trackiddata.

*

CALL FUNCTION '/SAPTRX/BAPI_EH_POST'

EXPORTING

   simulate       = ls_sim

   TABLES

     applobjects            = lt_applobjects

     controldata            = lt_controldata

     infodata               = lt_infodata

     milestonedata          = lt_milestones

     trackiddata            = lt_trackiddata

*   INFOOBJDATA            =

*   EXTENSIONIN            =

*   EXTENSIONOUT           =

     RETURN                 = lt_return

           .

if ls_sim is initial.

   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

endif.

loop at lt_return into ls_return.

   write: / ls_return-TYPE   ,

            ls_return-ID     ,

            ls_return-NUMBER ,

            ls_return-MESSAGE.

endloop.


the BAPi return message looks like

S /SAPTRX/TS_APP       704 EM TMXCLNT700: Using mapping profile ODT30_TOR for application object type ODT30_TO

I /SAPTRX/APP_LOG      020 Posting data from appl. sys TMXCLNT700, appl. object ODT30_TO/56EAB2E0CCBC5D91E1000000AC101684, status = 1

I /SAPTRX/APP_LOG      022 Updating event handler

.... but freight order has not changed

Is there a missing functionality to that the event handler has to start?????

Thanks in advance

Georg

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi George,

To post an event, you have to use /SAPTRX/BAPI_EH_ADDEVENTMSG_02  and not /SAPTRX/BAPI_EH_POST.


Here is the sample and modify it to your needs:

REPORT ZZTEST.
data: lt_hdr type STANDARD TABLE OF /SAPTRX/BAPI_EVM_HEADER,
       ls_hdr type /SAPTRX/BAPI_EVM_HEADER,
       lt_ret type STANDARD TABLE OF BAPIRET2.

ls_hdr-EVTCNT = '1'.
ls_hdr-EVTID  = 'DEPARTURE'.
ls_hdr-TRXCOD = 'TO'. "  Use TOR_TEC if TO doesn't work.
ls_hdr-TRXID = '00000000004100000351'. " Complete FO number
ls_hdr-EVTDAT = sy-datum.
ls_hdr-EVTTIM = sy-uzeit.
ls_hdr-EVTZON = sy-zonlo.
append ls_hdr to lt_hdr.


CALL FUNCTION '/SAPTRX/BAPI_EH_ADDEVENTMSG_02'
  EXPORTING
*   SIMULATE                     = p_sim
*   BLOCKONERRORIN               =
*   SKIPCHECK                    =
     SYNCHRONOUS                  = 'X'
*   BUFFER_MODE                  =
*   EH_GENERATION_MODE           =
*   EH_GENERATION_FUNCTION       =
*   PREPROCESS_MODE              =
*   PREPROCESS_FUNCTION          =
* IMPORTING
*   ERROROCCURRED                =
   TABLES
     trackingheader               = lt_hdr
     return                       = lt_ret
           .

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

------------


Also, have you tried using Event Types in Application Interface instead of the custom code?


Thanks,

Vishnu

georg_puscher
Explorer
0 Kudos

Hi Vishnu,

thanks for your quick answer. I've implemented the program (I used TRXCOD = "TOR_TEC") as you recommended it. But I'm getting the following messages.

I /SAPTRX/MSIO         058 Event message has been posted to SAP Event Management

I /SAPTRX/APP_LOG      058 Processing event messages for event handler ODT30_TO / 00000000004100000370

I /SAPTRX/APP_LOG      093 Message processing aborted. Not in list of allowed unexp. event codes

When checking my events in transaction "/SAPTRX/EVM_STATUS" I can see that the status in "green" (Processed). but in NWBC-function "Display ROAD FREIGTH" in tab "EXECUTION" the events are not reported.

I also can see that the program has created an entries in table /SAPTRX/EVM_HDR not /SAPTRX/EH_HDR.

When I compare entries in /SAPTRX/EVM_HDR which are posted manual in NWBC and with program I see that the manual posing has filled other fields like "SNDNAM", "LODID1" and also some others.

Is there some other parameter missing??

Georg

Former Member
0 Kudos

Hi Georg,

The messages are informational only and not errors.

>>>"I also can see that the program has created an entries in table /SAPTRX/EVM_HDR not /SAPTRX/EH_HDR."

That's correct. You are posting events which will show up in EVM_HDR and not in EH_HDR. Event Handlers will show up EH_HDR though.


For SNDNAM and LOCID1, you need to populate them in the bapi which I gave you( /SAPTRX/BAPI_EH_ADDEVENTMSG_02).


SNDNAM will be in " TRACKINGHEADER " structure and LOCID1 will be in TRACKLOCATION structure.


In order for events to show up in EXECUTION tab, you need to have setup proper config between TM and EM and event handlers should be getting created for your TM objects like FO/BO/FU etc.



Thanks,

Vishnu


former_member190756
Active Contributor
0 Kudos

Hello Georg,

you have to enter the event code in your Event Handler Type as Allowed Unexpected Event Code or disable the check if you don't need to restrict unexpected event codes:

Best regards,

Steffen

georg_puscher
Explorer
0 Kudos

Hello,

thanks for your helpful information. We have considered it in our development

Georg

Former Member
0 Kudos

Hi Georg,

You can see event message with event handler link in table /SAPTRX/EH_EVMSG.

1. Go to table /SAPTRX/EVM_MSG and give tracking id and get GUI ID.

2. Pass event message GUID in table /SAPTRX/EH_EVMSG to check event message posted against event handler correctly.

If /SAPTRX/EH_EVMSG-NOT_RELEVANT marked as "X" for reported event message, then it is not posted correctly and it won't be visible in EH LIST against event handler.

Regards


GGOPII

georg_puscher
Explorer
0 Kudos

Hi Gopi,

ok thanks, that a good help.

Best regards

Georg

anabel_moreno
Discoverer
0 Kudos

Hola a todos.

Estoy enla version EM HANA 2020. Aqui no tengo esos Modulos de funciones disponibles. Que aplicaria aqui para la Publicacion de eventos.

Si pudieras ayudarme lo agradeceria.

Answers (1)

Answers (1)

anabel_moreno
Discoverer
0 Kudos

Hola a todos.

Estoy enla version EM HANA 2020. Aqui no tengo esos Modulos de funciones disponibles. Que aplicaria aqui para la Publicacion de eventos.

Si pudieras ayudarme lo agradeceria.