SAP EM Newsletter

Subscribe for SAP EM related news
Banner
Banner

Attention: open in a new window. PDFPrintE-mail

2008
10
Nov

Calling SAP EM BAPI to add event

  data :

* Event Message data

         ls_trackingheader type /saptrx/bapi_evm_header,

         ls_trackeemodify  type /saptrx/bapi_evm_ee_modify,

         lv_evtcnt type /saptrx/bapi_evm_header-evtcnt,

         lv_modcnt type /saptrx/bapi_evm_header-evtcnt,

* BAPI Structures

         lt_bapi_evm_header type standard table of /saptrx/bapi_evm_header,

         lt_trackeemodify   type standard table of /saptrx/bapi_evm_ee_modify,

         lt_bapireturn      type standard table of bapiret2,

* Working variables

         new_date type sy-datum,

         new_time type sy-uzeit,

* BAPI Calling structures

         v_last_digit,

         v_queue type trfcqout-qname,

         lt_trxserv type standard table of /saptrx/trxserv,

         lw_trxserv type /saptrx/trxserv.

 

*** SET HEADER DATA FOR EVENT ***

*   Tracking ID = <Sales Order><Line>

  concatenate vbeln posnr into ls_trackingheader-trxid.

  ls_trackingheader-trxcod  = 'SO_LINE'.

*   Event ID = Unexpected or expected event code

  ls_trackingheader-evtid   = 'DEL_PGI'.

*   Event Count = Unique number donating instance of the event.

  lv_evtcnt = lv_evtcnt + 1.

  ls_trackingheader-evtcnt  = lv_evtcnt.

*   Event Reported actual Event Date / Time / Timezone

  ls_trackingheader-repdat = ls_trackingheader-evtdat  = sy-datum.

  ls_trackingheader-reptim = ls_trackingheader-evttim  = sy-uzeit.

  ls_trackingheader-repzon = ls_trackingheader-evtzon  = 'MSTNO'.

*   Language

  ls_trackingheader-language = sy-langu.

  append ls_trackingheader to lt_bapi_evm_header.

 

*** MODIFY EXPECTED EVENT ENTRY ***

  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.

 

*** CHANGE QUEUE NAME FOR OUTBOUND COMMUNICATION TO EVENT MANAGER ***

  v_last_digit = vbeln+9(1).

 

  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.

  endcase.

 

  condense v_queue.

 

  call function 'TRFC_SET_QUEUE_NAME'

    exporting

      qname                    = v_queue

   exceptions

     invalid_queue_name       = 1

     others                   = 2 .

 

  if sy-subrc <> 0.

    Message i999(b1) with ‘Failed to change queue name!’.

  endif.

 

*** CALL BAPI ***

* Get tracking servers

  select * from /saptrx/trxserv into table lt_trxserv.

  if sy-subrc <> 0.

    message w021(/saptrx/asc).

  endif.

 

  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

        exporting

          simulate           = space

          synchronous        = space

          eh_generation_mode = 'N'

        tables

          trackingheader     = lt_bapi_evm_header

          trackeemodify      = lt_trackeemodify

          return             = lt_bapireturn.

 

* Set queue for the Commit as well

      call function 'TRFC_SET_QUEUE_NAME'

        exporting

          qname                    = v_queue

       exceptions

         invalid_queue_name       = 1

         others                   = 2 .

 

      if sy-subrc <> 0.

    Message i999(b1) with ‘Failed to change queue name!’.

      endif.

 

      call function 'BAPI_TRANSACTION_COMMIT'

        in background task

        destination lw_trxserv-rfcdest.

    endif.

 

    refresh lt_bapi_evm_header.

    refresh lt_trackeemodify.

    refresh lt_bapireturn.

 

  endloop.

 

Login to download a word version of this document

Last Updated (Thursday, 06 November 2008 23:48)
Banner
Free software downloads