Ale Scenario Development Procedure
Ale Scenario Development Procedure
Ale Scenario Development Procedure
Version 1
Page 1 of 16
TABLE OF CONTENTS
1. INTRODUCTION TO ALE DEVELOPMENT ....................................................................................... 3 1.1. ALE Example ........................................................................................................................................... 3 2. OUTBOUND PROCESSING ..................................................................................................................... 5 2.1. Create IDoc type (WE30) Client independent .......................................................................................... 5 2.2. Create message type (WE81) Client independent .................................................................................... 6 2.2.1. 2.2.2. Link message to IDoc type (WE82 & BD69) Client independent .................................................. 6 Maintain object type for message type (BD59) Client independent ............................................... 6
2.3. Configuring the Distribution Model ......................................................................................................... 7 2.3.1. 2.3.2. Manual Configuration (BD64) Client dependent ............................................................................ 7 Distribute customer model (BD71) Client dependent ..................................................................... 7
2.4. Populate & distribute IDoc using ABAP .................................................................................................. 8 2.4.1. 3. Example code.................................................................................................................................. 8
INBOUND PROCESSING ....................................................................................................................... 11 3.1. Create Function Module ......................................................................................................................... 11 3.1.1. Debugging inbound FM ................................................................................................................ 14
3.2. Maintain ALE attributes ......................................................................................................................... 15 3.2.1. 3.2.2. 3.2.3. Link Message Type to Function Module (WE57) Client independent ......................................... 15 Define FM settings (BD51) Client independent ........................................................................... 15 Maintain process codes (WE42) Client dependent ....................................................................... 15
3.3. Create inbound partner profile................................................................................................................ 16 3.3.1. Maintain receiving system partner profile (WE20) Client dependent .......................................... 16
TABLE OF FIGURES
Figure 1: ALE Scenario model ............................................................................................................................... 3 Figure 2: Example Purchasing & Selling scenario ................................................................................................. 4 Figure 3: IDoc type ZINVRV01 ............................................................................................................................. 5 Figure 4: Outbound processing example code ........................................................................................................ 9 Figure 5: Inbound processing example code ........................................................................................................ 14
Version 1
Page 2 of 16
1.
INTRODUCTION TO ALE DEVELOPMENT To develop a new custom ALE scenario, comprises 5 steps: 1. Design and develop the custom IDoc with its segments and a new message type 2. Configure the ALE environment with the new IDoc and message type (customer model, partner profiles and linking IDoc to message type) 3. 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 4. Configure the ALE inbound side (partner profiles with inbound process code) 5. 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 pictorial representation of the flow of a complete ALE scenario from the sending system to the receiving system.
Application
Populate master IDoc
Sending System
ALE Layer
ALE Layer
Database C o m m u n i c a t i o n L a y e r
Receiving System
IDoc status
Application
Post application doc Process IDoc
MASTER_IDOC_DISTRIBU TE IDoc necessary creation ? Yes Create master IDoc M IDoc Determine receiver Segment filtering Field conversion Version conversion C CC IDoc C IDoc IDoc IDoc
Serialisatio n A IDoc Delivery control Version conversion Field conversion Segment filtering C IDoc
Database
Control data
Custom developed
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 providers system.
Version 1
Page 3 of 16
Transfer
Purchase Order
Confirmation
Release
Sales Order change Invoice
or
Cancel invoice
Credit memo
We will develop a custom IDoc to carry the billing number from the Service Receivers system to the Service Providers 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. Requirements Working ALE environment - See ALE Basis Configuration Guide; ALE scenario design together with the business requirement; Development access; and ALE configuration access. NOTES: 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. 3. Extensive knowledge of IDocs and ALE basis configuration is required in order to understand this guide.
Version 1
Page 4 of 16
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 1 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: ZINVRV01 Purchasing and Selling - Invoice receipt reversal Z1INVRV P&S - Segment 1 Segment fields LIFNR XBLNR
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).
Version 1
Page 5 of 16
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
Version 1
Page 6 of 16
Version 1
Page 7 of 16
Version 1
Page 8 of 16
DATA:
C_INVREV_SEGNAME(7) TYPE C VALUE 'Z1INVRV', C_INVREV_MESTYPE(6) TYPE C VALUE 'ZINVRV', C_INVREV_IDOC_TYPE(8) TYPE C VALUE 'ZINVRV01', Z1INVRV LIKE Z1INVRV, C_INVREV_DOCTYPE LIKE BKPF-BLART VALUE 'YY', IDOC_CONTROL LIKE EDIDC, T_COMM_CONTROL LIKE EDIDC OCCURS 0 WITH HEADER LINE, IDOC_DATA LIKE EDIDD OCCURS 0 WITH HEADER LINE.
*--- Move the document header into a structure LOOP AT DOC_HEAD_TAB INTO DOC_HEAD. ENDLOOP.
*--- Move the document item data into a structure LOOP AT DOC_ITEM_TAB INTO DOC_ITEM WHERE NOT ( LIFNR IS INITIAL ). ENDLOOP.
*--- Populate the IDoc segments field with the required data CLEAR Z1INVRV. Z1INVRV-LIFNR = DOC_ITEM-LIFNR. Z1INVRV-XBLNR = DOC_HEAD-XBLNR. IDOC_DATA-SEGNAM = C_INVREV_SEGNAME. IDOC_DATA-SDATA = Z1INVRV. APPEND IDOC_DATA. Store vendor number for filter Billing number Segment name Segment data Populate IDoc internal table
*--- Move the control data info required for the distribution IDOC_CONTROL-MESTYP = C_INVREV_MESTYPE. IDOC_CONTROL-DOCTYP = C_INVREV_IDOC_TYPE.
*--- Call the distribute function with the required parameters CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE' IN UPDATE TASK EXPORTING MASTER_IDOC_CONTROL TABLES COMMUNICATION_IDOC_CONTROL = T_COMM_CONTROL MASTER_IDOC_DATA EXCEPTIONS ERROR_IN_IDOC_CONTROL ERROR_WRITING_IDOC_STATUS ERROR_IN_IDOC_DATA SENDING_LOGICAL_SYSTEM_UNKNOWN OTHERS =1 =2 =3 =4 = 5. = IDOC_DATA = IDOC_CONTROL
Version 1
Page 9 of 16
NOTE: For debugging purposes, use transaction WE05 (IDoc overview) to see check your IDoc status, or to see whether an IDoc was created/
Version 1
Page 10 of 16
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 Import parameters INPUT_METHOD MASS_PROCESSING Export Parameters WORKFLOW_RESULT APPLICATION_VARIABLE IN_UPDATE_TASK CALL_TRANSACTION_DONE Table Parameters IDOC_CONTRL IDOC_DATA IDOC_STATUS RETURN_VARIABLES SERIALIZATION_INFO Exceptions WRONG_FUNCTION_CALLED 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. Reference field BDWFAP_PAR-INPUTMETHD BDWFAP_PAR-MASS_PROC Reference field BDWFAP_PAR-RESULT BDWFAP_PAR-APPL_VAR BDWFAP_PAR-UPDATETASK BDWFAP_PAR-CALLTRANS Reference field EDIDC EDIDD BDIDOCSTAT BDWFRETVAR BDI_SER Optional Y/N Opt Y/N N N Opt Y/N N N N N
Version 1
Page 11 of 16
*---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.
*--- 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. APPEND BDC_TAB. *--- OK Code for screen 109 CLEAR BDC_TAB. BDC_TAB-FNAM = 'BDC_OKCODE'. BDC_TAB-FVAL = 'SICH'. APPEND BDC_TAB. "Billing document number
*--- 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.
Version 1
Page 12 of 16
CALL FUNCTION 'BDC_OPEN_GROUP' EXPORTING CLIENT = SY-MANDT GROUP = 'ZINVRV' USER = C_ALE_USER KEEP = 'X'. CALL FUNCTION 'BDC_INSERT' EXPORTING TCODE TABLES DYNPROTAB = BDC_TAB. CALL FUNCTION 'BDC_CLOSE_GROUP' EXCEPTIONS NOT_OPEN =1 = C_TCODE
QUEUE_ERROR = 2 OTHERS ELSE. 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. UPDATE JEST. C_EXISTS = 'Y'. "I.E. An entry is already in table "Make pending the active status = 3. "No problems
ELSEIF JEST-INACT = C_UNCHECKED AND JEST-STAT NE C_US_PENDING. JEST-INACT = C_CHECKED. UPDATE JEST. ENDIF. ENDSELECT. IF C_EXISTS = 'N'. "I.E. Pending has never been a status before "Make everything else inactive
JEST-OBJNR = VBAP-OBJNR. JEST-STAT = C_US_PENDING. JEST-INACT = C_UNCHECKED. INSERT JEST. ENDIF. ENDSELECT. ENDIF. ENDFORM. " REV_INV "Select from VBRP (Billing document table) "Make pending the active status
Version 1
Page 13 of 16
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
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.
Version 1
Page 14 of 16
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
Version 1
Page 15 of 16
Version 1
Page 16 of 16