ALE Scenario Development Guide for SAP XI

1. Introduction to ALE development

Developing a new custom ALE scenario comprises 5 steps:

  • Design and develop the custom IDoc with its segments and a new message type
  • Configure the ALE environment with the new IDoc and message type (customer model, partner profiles and linking IDoc to message type)
  • Develop the outbound process which does the following:
    • Populates the custom IDoc with control info and functional data
    • Sends the IDoc to the ALE layer for distribution
    • Updates status and handles errors
  • Configure the ALE inbound side (partner profiles with inbound process code)
  • Develop the inbound process which does the following:
    • Reads the IDoc into a BDC table; selects other data that is required
    • Runs transaction using call transaction or BDC session
    • Updates status and handles errors

Below is a visual representation of the flow of a complete ALE scenario from the sending system to the receiving system.

Figure 1: ALE Scenario model

1.1. ALE Example

For the purposes of this example we will develop a small ALE scenario. This scenario is described below.
"The receiver of an internal service must be able to reverse (cancel) the invoice receipt which will then cancel the applicable billing document automatically on the service provider's system."

Figure 2: Example Purchasing & Selling scenario

We will develop a custom IDoc to carry the billing number

    Requires Free Membership to View

from the Service Receiver's system to the Service Provider's system. We will populate the IDoc in a user exit on the sending side and we will process the transaction on the receiving side using a custom function module and a BDC transaction call. No rule conversion, segment filtering or version conversion will be implemented in the model as described in Figure 1.


  • Working ALE environment - See ALE Basis Configuration Guide;
  • ALE scenario design together with the business requirement;
  • Development access; and
  • ALE configuration access.


1. All IMG references to transactions are located in the transaction SALE which is the ALE portion of the IMG
2. This is one way of developing a scenario where no message control exists. If message control exist (EG. On purchase orders) then NAST can be used to call an outbound function module that would create the required IDocs.

2. Outbound processing

2.1. Create IDoc type (WE30) Client independent

The IDoc type refers to the IDoc structure that you will require for your development. In our case the IDoc type is called ZINVRV01. This IDoc type will have one segment called Z1INVRV with 2 fields, LIFNR & XBLNR, in this segment. If you require many segments or nested segments then they are also created using the same procedure.

We will create the IDoc of the following structure:

Figure 3: IDoc type ZINVRV01

To create the IDoc type, follow these next few steps:

  • Enter transaction WE30 (ALE -> Extensions -> IDoc types -> Maintain IDoc type)
  • Type in ZINVRV01 and click on Basic IDoc type, click the Create icon
  • Click on Create new (we are creating an IDoc from scratch but you may want to copy another IDoc if it is similar to your requirements) and enter a description, and press enter
  • Click on ZINVRV01 and then on the Create icon
  • Enter Z1INVRV as the segment type (must start with Z1), check mandatory if the segment must exist (in this case check it), enter 1 in minimum number and 1 as maximum number. (Make the maximum number 9999999999 if there are going to be many of these segments in each IDoc. IE. When line items are passed via IDocs), click on Segment editor
  • Enter a description for your segment type and create
  • Enter a description for your segment, enter each field required in your IDoc, in our case type LIFNR across for Field name, DE structure and DE documentation, repeat for XBLNR and press enter to validate.
  • Save and generate, press back
  • To release the segment choose Goto, Release from the menu
  • Check the box on the line of your new segment
  • Save, back and enter
  • Your IDoc type structure should be displayed with your new segment
  • Save and back
  • To release the IDoc type choose Extras, Release type from the menu and Yes

Your IDoc is now ready for use. If you need to add fields or segments to your IDoc type, you will need to cancel the release of the IDoc type as well as the segment release using a similar procedure followed above (except now you uncheck the release box for the segment and you choose cancel release for the IDoc type).

2.2. Create message type (WE81) Client independent

To create a new message type, follow these next few steps:

  • Enter transaction WE81 (ALE -> Extensions -> IDoc types -> Maintain message type for intermed. Structure -> Create logical message type)
  • Choose Create logical message type by double clicking on it
  • Click on change icon to enter change mode
  • Click on New entries to add a new type
  • Enter the required message type, in our case it is ZINVRV and an appropriate description
  • Save and exit.

Your message type has now been created. The next step will be to link it to the IDoc.

2.2.1. Link message to IDoc type (WE82 & BD69) Client independent

To link the message type to the IDoc type follow these next few steps:

  • Enter transaction WE82 (ALE -> Extensions -> IDoc types -> Maintain message type for intermed. Structure -> EDI: Message Types and Assignment to IDoc Types)
  • Click on change icon to enter change mode
  • Click on New entries to create the link
  • Enter the message type ZINVRV and the BasicIDoc type as ZINVRV01
  • Save and exit
  • Enter transaction BD69 (ALE -> Extensions -> IDoc types -> Maintain message type for intermed. Structure -> Assign message type to IDoc for ALE)
  • Click on change icon to enter change mode
  • Click on New entries to create the link
  • Enter the message type ZINVRV and the BasicIDoc type as ZINVRV01
  • Save and exit

Your IDoc is now linked to your message type. We still need to link object types and add the message to the model before we can use the message.

2.2.2. Maintain object type for message type (BD59) Client independent

The ALE objects are used to create links between IDocs and applications objects, to control the serialisation, to filter messages in the customer model and to use listings. For our own message type and IDoc you must maintain object types for the links. If you want to check the serialisation for the message type, then you must maintain object types for the serialisation. If no serialisation object has been maintained for a given message type, then the serialisation will not be checked for this message type.

To add an object type to our message type, follow these next few steps:

Enter transaction BD59 (ALE -> Extensions -> ALE object maintenance -> Maintain object types)

  • Type in your message type ZINVRV and press enter
  • Click on New entries
  • Enter your object type, LIFNR (We need to use the vendor as a filter object), the segment name where LIFNR resides, Z1INVRV, a number 1 for the sequence followed by the actual field name LIFNR
  • Save and exit.

    You have now created an object that we'll use as a filter object in the customer model to direct the flow of messages to the various logical systems based on the vendors in the filter of the message type ZINVRV. We now need to add our new message type to the distribution model.

    2.3. Configuring the Distribution Model

    This task is performed on your ALE reference client.

    2.3.1. Manual Configuration (BD64) Client dependent

    To manually configure the customer distribution model, read the ALE configuration procedure, and follow these steps:

    • Perform the Maintain customer distribution model directly function. (ALE -> Distribution customer model -> Maintain customer distribution model directly)
    • Specify the customer model you want to maintain and the logical system that is to be the sender of the messages OR create a new model. (Create model ALE with logical system ALELS1C400)
    • Choose the receiving systems to which the sending system must forward message type ZINVRV to.
    • For each receiving logical system allocate the message type necessary for communication to the receiving systems as per ALE configuration procedure.
    • Create filter objects (in our case LIFNR as the object type with the associated vendor number, 0000018001 with leading zeros, in the object area) for the message types.
    • Save the entries.


    You cannot maintain a message type between the same sender and receiver in more than one customer distribution model. Only the owner is authorised to modify the model. To change the owner of a model, choose the 'Maintain ownership of customer distribution model' function. Make sure that all changes will be distributed to all systems that know the corresponding model. To do so, you can use the correction and transport system. To transport the customer distribution model you should use the Distribute customer model function of the IMG as described below.

    2.3.2. Distribute customer model (BD71) Client dependent

    After the customer model has been created centrally, it must be distributed to the other remote systems. This entails first of all setting up the communication for the distributed systems and then sending the model. Distribute Model (BD71) Client dependent

    This task is performed on your ALE reference client. To distribute the customer distribution model, read the ALE configuration procedure and follow these steps:

    • Make the settings for the communication with the other decentral systems, you have not set them yet.
    • Define the RFC destination for R/3 connections whose names correspond to the name of the corresponding logical system.
    • Create the output partner profile.
    • Distribute the customer model
    • Specify the name of the customer model.
    • You must specify the target system to which you want to distribute the customer model.
    • You must repeat this function for every distributed logical system.


    In later versions of SAP you distribute the Distribution model from the Distribution Model editor using BD64. You perform this task from the menu option within the model you wish to distribute and you can distribute it to as many systems as you wish in one action. Maintain sending system partner profile (WE20) Client dependent

    With this function, you define the partner profiles for all outbound and inbound messages on the basis of the customer distribution model. After you have defined and distributed the customer model, you will have to maintain the partner profiles locally. To do this read the ALE configuration procedure.

    * Enter the output mode (background, immediately) and the package size for outbound processing.


    • The customer model must be maintained.
    • RFC destinations must be maintained.
    • The customer model must be distributed.
    • To ensure that the appropriate persons in charge are informed if a processing error occurs, you must make settings in: Error processing Maintain organisational units.

    2.4. Populate & distribute IDoc using ABAP

    An IDoc consists of a control record with structure edidc and one or more data records with structure edidd. The control record contains the sender and recipient of the IDoc, as well as information on the type of message.

    To be able to pass an IDoc to the ALE layer, you must set up a field string with structure edidc and an internal table with structure edidd. They are used to call function module master_idoc_distribute, which performs the save to the database and triggers the dispatch if necessary.

    2.4.1. Example code

    The code displayed below does the following:

    • populates our IDoc segment Z1INVR with the 2 fields XBLNR and LIFNR, populates the segment name and appends this to an internal table used to store the IDoc data;
    • populates the control record info with the message type and IDoc type; and
    • calls the MASTER_IDOC_DISTRIBUTE function module which distributes the IDoc as configured in the customer distribution model.

    <br />
    *--- Data declaration statements<br />
      Z1INVRV LIKE Z1INVRV,<br />
    <br />
    *--- Move the document header into a structure<br />
    ENDLOOP.<br />
    <br />
    *--- Move the document item data into a structure<br />
    ENDLOOP.<br />
    <br />
    *--- Populate the IDoc segment's field with the required data<br />
    CLEAR Z1INVRV.<br />
    Z1INVRV-LIFNR = DOC_ITEM-LIFNR.  "Store vendor number for filter<br />
    Z1INVRV-XBLNR = DOC_HEAD-XBLNR.  "Billing number<br />
    IDOC_DATA-SEGNAM = C_INVREV_SEGNAME. "Segment name<br />
    IDOC_DATA-SDATA = Z1INVRV.   "Segment data<br />
    APPEND IDOC_DATA.    "Populate IDoc internal table<br />
    <br />
    *--- Move the control data info required for the distribution<br />
    <br />
    *--- Call the distribute function with the required parameters<br />
      EXPORTING<br />
      TABLES<br />
      EXCEPTIONS<br />
       ERROR_IN_IDOC_CONTROL   = 1<br />
       ERROR_IN_IDOC_DATA   = 3<br />
       OTHERS     = 5.


    For debugging purposes, use transaction WE05 (IDoc overview) to see whether an IDoc was created and to check on it's status.

    3. Inbound processing

    3.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. The function module is passed the IDoc as a parameter.

    Example parameters

    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.

    <br />
    <br />
    *--- Declaration of local variables<br />
    <br />
    *-Loop through the IDOCs<br />
    *---Loop through the data for the IDOC<br />
       WHEN C_SEGNAM.<br />
    *    Here we get the info from the idoc table<br />
        IT_Z1INVRV = IDOC_DATA-SDATA.<br />
      ENDCASE.<br />
      PERFORM REV_INV.<br />
     ENDLOOP.<br />
     ENDLOOP.<br />
    <br />
    FORM REV_INV   "Reverse invoice form<br />
    *--- Local variables & constants<br />
    DATA: C_TCODE LIKE BKPF-TCODE VALUE 'VF11'.  "BDC transaction code<br />
    <br />
    *--- Now we can build the bdc table to call the reversal transaction start of screen 109<br />
    CLEAR BDC_TAB.<br />
    BDC_TAB-PROGRAM  = 'SAPMV60A'.<br />
    BDC_TAB-DYNPRO   = '109'.<br />
    BDC_TAB-DYNBEGIN = 'X'.<br />
    APPEND BDC_TAB.<br />
    *--- Document number<br />
    CLEAR BDC_TAB.<br />
    BDC_TAB-FNAM = 'KOMFK-VBELN(01)'.<br />
    BDC_TAB-FVAL = IT_Z1INVRV-XBLNR.     "Billing document number<br />
    APPEND BDC_TAB.<br />
    *--- OK Code for screen 109<br />
    CLEAR BDC_TAB.<br />
    BDC_TAB-FNAM = 'BDC_OKCODE'.<br />
    BDC_TAB-FVAL = 'SICH'.<br />
    APPEND BDC_TAB.<br />
    <br />
    *--- 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.<br />
    <br />
    *--- Store the return code for use in another form (status update)<br />
    <br />
    *--- 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.<br />
    IF SY-SUBRC NE 0.<br />
      EXPORTING<br />
       CLIENT = SY-MANDT<br />
       GROUP  = 'ZINVRV'<br />
       USER   = C_ALE_USER<br />
       KEEP   = 'X'.<br />
      EXPORTING<br />
       TCODE     = C_TCODE<br />
      TABLES<br />
       DYNPROTAB = BDC_TAB.<br />
      EXCEPTIONS<br />
       NOT_OPEN    = 1<br />
       QUEUE_ERROR = 2<br />
       OTHERS      = 3.<br />
    ELSE.      "No problems<br />
     C_EXISTS = 'N'.<br />
    *   Select from the billing document table to get sales doc number<br />
    *     Select from the sales document table to get user status number<br />
       POSNR = VBRP-AUPOS.<br />
    *     Select from the status table to change the user status to pending<br />
       IF JEST-STAT = C_US_PENDING.   "User status is pending<br />
        JEST-INACT = C_UNCHECKED.    "Make pending the active status<br />
        UPDATE JEST.<br />
        C_EXISTS = 'Y'.            "I.E. An entry is already in table<br />
        JEST-INACT = C_CHECKED.      "Make everything else inactive<br />
        UPDATE JEST.<br />
       ENDIF.<br />
      ENDSELECT.<br />
      IF C_EXISTS = 'N'.    "I.E. Pending has never been a status before<br />
       JEST-OBJNR = VBAP-OBJNR.<br />
       JEST-STAT  = C_US_PENDING.<br />
       JEST-INACT = C_UNCHECKED.      "Make pending the active status<br />
       INSERT JEST.<br />
      ENDIF.<br />
     ENDSELECT.       "Select from VBRP (Billing document table)<br />
    ENDIF.<br />
    ENDFORM.                               " REV_INV<br />
    <br />
    FORM UPDATE_IDOC_STATUS.                                               <br />
    *--- Now we check the CALL TRANSACTION return code and set IDOC status <br />
     CLEAR IDOC_STATUS.                                                   <br />
     IF RETURN_CODE = 0.                                                  <br />
      WORKFLOW_RESULT = '0'.                                             <br />
      IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.                           <br />
      IDOC_STATUS-STATUS = '53'.                                         <br />
      IDOC_STATUS-UNAME = SY-UNAME.                                      <br />
      IDOC_STATUS-REPID = SY-REPID.                                      <br />
      IDOC_STATUS-MSGTY = SY-MSGTY.                                      <br />
      IDOC_STATUS-MSGID = SY-MSGID.                                      <br />
      IDOC_STATUS-MSGNO = SY-MSGNO.                                      <br />
      IDOC_STATUS-MSGV1 = SY-MSGV1.                                      <br />
      IDOC_STATUS-MSGV2 = SY-MSGV2.<br />
      IDOC_STATUS-MSGV3 = SY-MSGV3.                         <br />
      IDOC_STATUS-MSGV4 = SY-MSGV4.                         <br />
      RETURN_VARIABLES-WF_PARAM = 'Processed_IDOCs'.        <br />
      APPEND RETURN_VARIABLES.                              <br />
     ELSE.                                                   <br />
      WORKFLOW_RESULT = '99999'.                            <br />
      IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.              <br />
      IDOC_STATUS-STATUS = '51'.                            <br />
      IDOC_STATUS-UNAME = SY-UNAME.                         <br />
      IDOC_STATUS-REPID = SY-REPID.                         <br />
      IDOC_STATUS-MSGTY = SY-MSGTY.                         <br />
      IDOC_STATUS-MSGID = SY-MSGID.                         <br />
      IDOC_STATUS-MSGNO = SY-MSGNO.                         <br />
      IDOC_STATUS-MSGV1 = SY-MSGV1.<br />
      IDOC_STATUS-MSGV2 = SY-MSGV2.                          <br />
      IDOC_STATUS-MSGV3 = SY-MSGV3.                          <br />
      IDOC_STATUS-MSGV4 = SY-MSGV4.                          <br />
      RETURN_VARIABLES-WF_PARAM = 'ERROR_IDOCS'.             <br />
      APPEND RETURN_VARIABLES.                               <br />
     ENDIF.                                                   <br />
     APPEND IDOC_STATUS.                                      <br />
    ENDFORM.                               " UPDATE_IDOC_STATUS

    Figure 5: Inbound processing example code

    3.1.1. Debugging inbound FM

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

    3.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.

    3.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

    3.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

    3.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

    NOTE: The next 6 steps are used in workflow error handling.

    • Enter IDPKFIDCMT in object type
    • Enter MASSINPUTFINISHED in End event
    • Enter IDOCINVOIC in IDoc object type
    • Enter INPUTERROROCCURREDFI in IDoc start event
    • Enter INPUTFINISHEDFI in IDoc End event
    • Enter IDOCINVOIC in Application object type

    You will need to determine the task associated with object IDOCINVOIC, and then assign the appropriate position to it. This position will then receive the application error messages via workflow.

    To set up the workflow area please consult the Workflow config guide.

    3.3. Create inbound partner profile

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

    3.3.1. 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.
    • Enter the position S and choose the ALE administrator 50000085. This position will then receive all the technical ALE errors via workflow.

    3.4. Test

    Once the inbound function module has been debugged the scenario should be ready to test in its entirety. If problems occur, read through the relevant areas of this document to check your configuration or code.

    Kevin Wilson is a senior interface consultant for QData USA Inc. and founder of SAPGenie.com

    This content is reposted from the SAP Developer Network.
    Copyright 2006, SAP Developer Network

    SAP Developer Network (SDN) is an active online community where ABAP, Java, .NET, and other cutting-edge technologies converge to form a resource and collaboration channel for SAP developers, consultants, integrators, and business analysts. SDN hosts a technical library, expert blogs, exclusive downloads and code samples, an extensive eLearning catalog, and active, moderated discussion forums. SDN membership is free.

    Want to read more from this author? Click here to read Kevin Wilson's Weblog. Click here to read more about ABAP on SDN.

    This was first published in November 2006

  • There are Comments. Add yours.

    TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

    REGISTER or login:

    Forgot Password?
    By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
    Sort by: OldestNewest

    Forgot Password?

    No problem! Submit your e-mail address below. We'll send you an email containing your password.

    Your password has been sent to:

    Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.