SAP Tech Pro

SAP Technical Blog
Topprice Price Comparison

Inbound processing in ALE IDOCS (SAP ABAP)

Inbound processing in ALE IDOCS (SAP ABAP)

 

1. Create Function Module

This function module is called when a message type, of type ZINVRV, comes into the receiving system. This needs to be configured and is dealt with later in this section.

Example code

The code displayed below does the following:

  • Populates a BDC table with the IDoc info.
  • Calls the transaction via a BDC call, and
  • Updates the IDoc status according to the BDC error status.

Function Module - z_idoc_input_zinvrv.

*--- Declaration of local variables
DATA: c_segnam(10) TYPE c VALUE 'Z1INVRV'.

*-Loop through the IDOCs
LOOP AT idoc_contrl.
*---Loop through the data for the IDOC
  LOOP AT idoc_data WHERE docnum = idoc_contrl-docnum.
    CASE idoc_data-segnam.
      WHEN c_segnam.
*       Here we get the info from the idoc table
        it_z1invrv = idoc_data-sdata.
    ENDCASE.
    PERFORM rev_inv.
  ENDLOOP.
  PERFORM update_idoc_status.
ENDLOOP.

FORM rev_inv.      "Reverse invoice form
*--- Local variables & constants
DATA: c_tcode LIKE bkpf-tcode VALUE 'VF11'.  "BDC transaction code

*--- Now we can build the bdc table to call the reversal transaction start of screen 109
  CLEAR bdc_tab.
  bdc_tab-program  = 'SAPMV60A'.
  bdc_tab-dynpro   = '109'.
  bdc_tab-dynbegin = 'X'.
  APPEND bdc_tab.
*--- Document number
  CLEAR bdc_tab.
  bdc_tab-fnam = 'KOMFK-VBELN(01)'.
  bdc_tab-fval = it_z1invrv-xblnr.     "Billing document number
  APPEND bdc_tab.
*--- OK Code for screen 109
  CLEAR bdc_tab.
  bdc_tab-fnam = 'BDC_OKCODE'.
  bdc_tab-fval = 'SICH'.
  APPEND bdc_tab.

*--- Now we can call transaction 'VF11' with the populated bdc table. The transaction is called inside the idoc-contrl loop, so a transaction will be called for every idoc (journal). the transaction is called in no-display mode ('N') because this code
  runs in background as it is called by ale.  the update is specified to be synchronous ('S') because we have to wait for the result to update the idoc status correctly.
  CALL TRANSACTION c_tcode USING bdc_tab MODE 'N' UPDATE 'S'.

*--- Store the return code for use in another form (status update)
  return_code = sy-subrc.

*--- Here we check the return code, if there was an error, we put the transaction in a bdc session for the user to review and correct.
  IF sy-subrc NE 0.
    CALL FUNCTION 'BDC_OPEN_GROUP'
      EXPORTING
        client = sy-mandt
        group  = 'ZINVRV'
        user   = c_ale_user
        keep   = 'X'.
    CALL FUNCTION 'BDC_INSERT'
      EXPORTING
        tcode     = c_tcode
      TABLES
        dynprotab = bdc_tab.
    CALL FUNCTION 'BDC_CLOSE_GROUP'
      EXCEPTIONS
        not_open    = 1
        queue_error = 2
        OTHERS      = 3.
  ELSE.           "No problems
    c_exists = 'N'.
*   Select from the billing document table to get sales doc number
    SELECT * FROM vbrp WHERE vbeln = it_z1invrv-xblnr.
*     Select from the sales document table to get user status number
      SELECT SINGLE * FROM vbap WHERE vbeln = vbrp-aubel AND
        posnr = vbrp-aupos.
*     Select from the status table to change the user status to pending
      SELECT * FROM jest WHERE objnr = vbap-objnr AND
        stat LIKE c_user_status.
        IF jest-stat = c_us_pending.   "User status is pending
          jest-inact = c_unchecked.    "Make pending the active status
          UPDATE jest.
          c_exists = 'Y'.            "I.E. An entry is already in table
        ELSEIF jest-inact = c_unchecked AND jest-stat NE c_us_pending.
          jest-inact = c_checked.      "Make everything else inactive
          UPDATE jest.
        ENDIF.
      ENDSELECT.
      IF c_exists = 'N'.    "I.E. Pending has never been a status before
        jest-objnr = vbap-objnr.
        jest-stat  = c_us_pending.
        jest-inact = c_unchecked.      "Make pending the active status
        INSERT jest.
      ENDIF.
    ENDSELECT.       "Select from VBRP (Billing document table)
  ENDIF.
ENDFORM.                               " REV_INV

FORM update_idoc_status.
*--- Now we check the CALL TRANSACTION return code and set IDOC status
  CLEAR idoc_status.
  IF return_code = 0.
    workflow_result = '0'.
    idoc_status-docnum = idoc_contrl-docnum.
    idoc_status-status = '53'.
    idoc_status-uname = sy-uname.
    idoc_status-repid = sy-repid.
    idoc_status-msgty = sy-msgty.
    idoc_status-msgid = sy-msgid.
    idoc_status-msgno = sy-msgno.
    idoc_status-msgv1 = sy-msgv1.
    idoc_status-msgv2 = sy-msgv2.
    idoc_status-msgv3 = sy-msgv3.
    idoc_status-msgv4 = sy-msgv4.
    return_variables-wf_param = 'Processed_IDOCs'.
    return_variables-doc_number = idoc_contrl-docnum.
    APPEND return_variables.
  ELSE.
    workflow_result = '99999'.
    idoc_status-docnum = idoc_contrl-docnum.
    idoc_status-status = '51'.
    idoc_status-uname = sy-uname.
    idoc_status-repid = sy-repid.
    idoc_status-msgty = sy-msgty.
    idoc_status-msgid = sy-msgid.
    idoc_status-msgno = sy-msgno.
    idoc_status-msgv1 = sy-msgv1.
    idoc_status-msgv2 = sy-msgv2.
    idoc_status-msgv3 = sy-msgv3.
    idoc_status-msgv4 = sy-msgv4.
    return_variables-wf_param = 'ERROR_IDOCS'.
    return_variables-doc_number = idoc_contrl-docnum.
    APPEND return_variables.
  ENDIF.
  APPEND idoc_status.
ENDFORM.                               " UPDATE_IDOC_STATUS

 

2. Maintain ALE attributes

The inbound function module needs to be linked to the message type and the message type needs to be linked to the appropriate inbound process code at the partner profile level before the scenario is enabled. These steps are described below in detail.

2.1. Link Message Type to Function Module (WE57) Client independent

To link a message (ZINVRV) type to a function module (Z_IDOC_INPUT_ZINVRV) follow these steps:

  • Enter transaction WE57 (ALE -> Extensions -> Inbound -> Allocate function module to logical message)
  • Select an entry (EG. IDOC_INPUT_ORDERS) and copy
  • Type in module name Z_IDOC_INPUT_ZINVRV
  • Type in basic IDoc type as ZINVRV01
  • Type in message type as ZINVRV
  • Type object type as IDOCINVOIC (Invoice document) - Used for workflow
  • Direction should be set to 2 for inbound
  • Enter and save
2.2. Define FM settings (BD51) Client independent
  • Enter transaction BD51 (ALE -> Extensions -> Inbound -> Define settings for input modules)
  • Click on New entries
  • Type in the name of the new function module Z_IDOC_INPUT_ZINVRV
  • Enter 0 for mass processing in the output column
  • Save and Exit

2.3 Maintain process codes (WE42) Client dependent

A process code needs to be maintained on each client. It then needs to be linked to the message via the partner profiles on each client. This allows the various clients to use a unique function module for the same message type.

To maintain the process code follow these steps:

  • Log on to the appropriate receiving system client
  • Execute WE42 (ALE -> Extensions -> Inbound -> Maintaining process codes inbound)
  • Choose Inbound with ALE service
  • Choose Processing with function module
  • Click on Processing with function module and choose create icon
  • Click on New Entries
  • Type in process code ZINR and give it a description and save
  • Now you are asked to Please maintain codes added in ALE entry methods, enter and choose Z_IDOC_INPUT_FIRVSL and copy it. You should choose a FM similar to your one.
  • Enter your process code ZINR
  • Enter your function module Z_IDOC_INPUT_ZINVRV

 

2.4. Create inbound partner profile

For each message type you need to maintain the inbound partner profiles.

Maintain receiving system partner profile (WE20) Client dependent

To maintain inbound partner profiles read the document ALE configuration procedure:

  • Add the message type ZINVRV with process code ZINR.
  • Enter the output mode (background, immediately) for inbound processing and NO message code.

2.5. Test

Use transaction WE19 to test inbound function module in debugging mode. Also use WE05 to view the IDocs and their statuses.

Add comment

Before Buying, Compare Prices at Topprice.in

Topprice.in