Skip to Content

The Process

Describing the IDoc SAP EM Process

1.    PO is created and an ORDERS Idoc is generated in status 03

2.    The ORDERS Idoc is sent to GXS for translation into an X12 850 EDI message

3.    The status of the translation can either be successful or unsuccessful

  a.    Unsuccessful translation refers to technical compliance issues for the X12 standard used. E.g. Mandatory segments or fields missing

  b.    If the translation is successful then the 850 is sent to the Partner for translation as an 850 message

4.    On completion of the translation GXS produces a STATUS IDoc that is sent to SAP for processing

5.    The partner profile points to inbound process code ZSTA2 which in turn points to function module ZIDOC_INPUT_STATUS for processing the IDoc status message

  a.    It’s in this function module that we wish to insert our logic as follows:

      i.    Retrieve status from Idoc field E1STATS-STATUS
      ii.    If E1STATS-STATUS is one of 05,06,15,16 then check the type of IDoc as follows
      iii.    Retrieve E1STATS-DOCNUM and check it’s corresponding EDIDC-MESTYP and EDIDC-DIRECT values
      iv.    If EDIDC-MESTYP = “ORDERS” and EDIDC-DIRECT = “1” then proceed to check the partner is one that is relevant for SAP EM
      v.    Take EDIDC-SNDPRN and check against MN04 (ZEMP) entries
      vi.    If it exists then this Idoc status change is relevant for sending to SAP EM
      vii.    If relevant then call the BAPI /SAPTRX/BAPI_EH_ADDEVENTMSG_02 to add the events as follows:
           1.    If E1STATS-STATUS = 05 then EVTID = “PO_SEND_ERR”
           2.    If E1STATS-STATUS = 06 then EVTID = “PO_SEND”
           3.    If E1STATS-STATUS = 15 then EVTID = “PO_VENDOR_ERR”
           4.    If E1STATS-STATUS = 16 then EVTID = “PO_VENDOR”

6.    The original ORDERS IDoc is then updated with the status as sent in the STATUS IDoc. (See red rectangles below)

7.    The Vendor translates the 850

8.    The status of the vendor translation is sent back to GXS in the form of a 997 message

9.    GXS receives the 997 message and generates the STATUS Idoc with the applicable status (Either 15 or 16)

10.    The STATUS Idoc is sent to SAP for processing

11.    Similarly to Step 5 the IDoc is processed for statuses 15 or 16

12.    Similarly to step 6 the status is posted against the original ORDERS Idoc

Outpound ORDERS Idoc

ORDERS Idoc

Inbound STATUS Idoc

STATUS Idoc

Example Function to send Event to SAP EM

FUNCTION zem_idoc_status.
*”———————————————————————-
*”*”Local Interface:
*”  IMPORTING
*”     VALUE(STATUS) TYPE  EDIDC-STATUS
*”     VALUE(IDOC_NUMBER) TYPE  EDIDC-DOCNUM
*”———————————————————————-

  TABLES: edidc, edid4.

  DATA :
* Event Message data
         ls_trackingheader TYPE /saptrx/bapi_evm_header,
         lv_evtcnt TYPE /saptrx/bapi_evm_header-evtcnt,
* BAPI Structures
         lt_bapi_evm_header
           TYPE STANDARD TABLE OF /saptrx/bapi_evm_header,
         lt_bapireturn
           TYPE STANDARD TABLE OF bapiret2,
* Working variables
         new_date TYPE sy-datum,
         new_time TYPE sy-uzeit,
         lv_po LIKE ekko-ebeln,
         lv_lifnr LIKE ekko-lifnr,
         lv_bsart LIKE ekko-bsart,
         e1edk01 TYPE e1edk01,
* BAPI Calling structures
         v_last_digit,
         v_queue TYPE trfcqout-qname,
         lt_trxserv TYPE STANDARD TABLE OF /saptrx/trxserv,
         lw_trxserv TYPE /saptrx/trxserv.
  DATA:
*   System Timezone
        lv_timezone        TYPE timezone.

  CHECK NOT idoc_number IS INITIAL.
  CHECK status = ’05’ OR
        status = ’06’ OR
        status = ’15’ OR
        status = ’16’.

* From the IDoc number get ORDERS details
  SELECT SINGLE mestyp direct
    INTO (edidc-mestyp, edidc-direct)
    FROM edidc
    WHERE docnum = idoc_number.

  IF sy-subrc = 0 AND
     edidc-mestyp = ‘ORDERS’ AND
     edidc-direct = ‘1’.

* Get PO Number
    SELECT SINGLE sdata INTO edid4-sdata
      FROM edid4
      WHERE docnum = idoc_number AND
            segnam = ‘E1EDK01’.

    IF sy-subrc = 0.
      e1edk01 = edid4-sdata.
      lv_po = e1edk01-belnr.
    ENDIF.

    CHECK NOT lv_po IS INITIAL.

* Now check if our vendor is valid

    SELECT SINGLE bsart lifnr
      INTO (lv_bsart, lv_lifnr)
      FROM ekko
      WHERE ebeln = lv_po.

    CHECK NOT lv_bsart IS INITIAL AND
          NOT lv_lifnr IS INITIAL.

    SELECT SINGLE * FROM b025 WHERE kappl = ‘EF’         AND
                               kschl = ‘ZEMP’            AND
                               bsart = lv_bsart  AND
                               lifnr = lv_lifnr.

    IF sy-subrc = 0.  “Relevant for SAP EM event

      ls_trackingheader-trxcod  = ‘PO_NO’.
      ls_trackingheader-trxid = lv_po.
      ls_trackingheader-evtdat  = sy-datum.
      ls_trackingheader-evttim  = sy-uzeit.
*   Get System TimeZone
      CALL FUNCTION ‘GET_SYSTEM_TIMEZONE’
        IMPORTING
          timezone            = lv_timezone
        EXCEPTIONS
          customizing_missing = 1
          OTHERS              = 2.
      ls_trackingheader-evtzon  = lv_timezone.
      lv_evtcnt                 = lv_evtcnt + 1.
      ls_trackingheader-evtcnt  = lv_evtcnt.

*     Event ID
      CASE status.

        WHEN ’05’.   “Translation error
          ls_trackingheader-evtid   = ‘PO_SEND_ERR’.

        WHEN ’06’.   “Translation OK
          ls_trackingheader-evtid   = ‘PO_SEND’.

        WHEN ’15’.   “Functionally acknowledged with error
          ls_trackingheader-evtid   = ‘PO_VENDOR_ERR’.

        WHEN ’16’.   “Functionally Acknowledged
          ls_trackingheader-evtid   = ‘PO_VENDOR’.

      ENDCASE.

      APPEND ls_trackingheader TO lt_bapi_evm_header.

      CALL FUNCTION ‘TRFC_SET_QUEUE_NAME’
        EXPORTING
          qname              = ‘EM_ESC_PURPORD’
        EXCEPTIONS
          invalid_queue_name = 1
          OTHERS             = 2.

      IF sy-subrc <> 0.
        MESSAGE i099(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
              return             = lt_bapireturn.

* Set queue for the Commit as well
          CALL FUNCTION ‘TRFC_SET_QUEUE_NAME’
            EXPORTING
              qname              = ‘EM_ESC_PURPORD’
            EXCEPTIONS
              invalid_queue_name = 1
              OTHERS             = 2.

          IF sy-subrc <> 0.
            MESSAGE i099(b1) WITH ‘Failed to change queue name!’.
          ENDIF.

          CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
            IN BACKGROUND TASK
            DESTINATION lw_trxserv-rfcdest.
        ENDIF.
      ENDLOOP.
      REFRESH lt_bapi_evm_header.
      REFRESH lt_bapireturn.

    ENDIF.

  ENDIF.

ENDFUNCTION.

To report this post you need to login first.

Be the first to leave a comment

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

Leave a Reply