Académique Documents
Professionnel Documents
Culture Documents
http://www.riyaz.net/blog/beginners-guide-to-ale-and-idocs-a-step-by-step-approach/
This article will help you understand the basics of ALE and IDocs via a simple do-it-yourself example. We will
create a custom IDoc in one SAP system and then post some business data through it to another SAP system.
Business data will be picked up from custom data dictionary tables.
ALE – Application Link Enabling is a mechanism by which SAP systems communicate with each other and
with non-SAP EDI subsystems. Thus it helps integration of distributed systems. It supports fail-safe delivery
which implies that sender system does not have to worry about message not reaching the source due to
unavoidable situations. ALE can be used for migration and maintenance of master data as well as for
exchanging transactional data.
The messages that are exchanged are in the form of IDocs or Intermediate Documents. IDocs act like a
container or envelope for the application data. An IDOC is created as a result of execution of an Outbound
ALE. In an Inbound ALE an IDOC serves as an input to create application document. In the SAP system IDocs
are stored in the database tables. They can be used for SAP to SAP and SAP to non-SAP process
communication as long as the participating processes can understand the syntax and semantics of the data.
Complete documentation on IDOC is obtained by using transaction WE60.
Every IDoc has exactly one control record along with a number of data records and status records. Control
record has the details of sender/receiver and other control information. Data records contain the actual business
data to be exchanged while the status records are attached to IDoc throughout the process as the IDoc moves
from one step to other.
Now, let us understand the ALE Configuration by means of an example scenario below:
The Scenario
Go to WE81
Create a new Message type ZRZSO_MT
Save the object
Go to WE82 and create new entry
Assign the message type ZRZSO_MT to the basic type ZRZORDER
Also specify the Release Version
Save the object
Thus we have defined the IDoc structure which will hold the data to be transferred. In the next part of the article
we will understand the outbound settings, i.e. the settings to be done in the source system.
Beginner’s Guide to ALE and IDocs - Part II
In the previous part we created an IDoc structure which can carry our data from source system to target
system(s). In this part we will understand how to setup the source system to be able to generate and send an
outbound IDoc.
Outbound Settings
Define Logical Systems and Assign Client to Logical System – Transaction SALE
Create a new RFC destination for R/3 type connection for ALE and TCP/IP for EDI
Specify the target host on Technical settings tab
Provide the Logon credentials on the Logon/Security tab
Save the settings
To verify the settings, Click on Test connection or Remote logon
Logical system and RFC Destinations must have same name
Test connection(push button) and pop-up menu TEST-> AUTHORIZATION
We need to define a tRFC port for the partner system for ALE (for EDI must define a file port)
Click on Transactional RFC node
Create a new port
Provide a description
Specify the name of the target RFC destination (SM59)
Save the object
Click on Change
Create a new model view
Provide a Short text and Technical name to the model view
Add message type
Specify sender and receiver systems
Also, specify the message type that we created previously
Save the Distribution model
Create an executable program ZRZ_ORDER_IDOC in SE38. Below, I have described the program logic:
Fetch the data from the DDic tables ZCUSTOMERS, ZSOHEADERS and ZSOITEMS as per the
selection criteria
Fill the control record structure of type EDIDC
o Specify message type, Basic IDoc type, tRFC Port, Partner number and Partner type of the
receiver
Fill the data records
o Define structures like the IDoc segments
o Fill the structures with fetched data
o Pass the segment name and the above structure to the appropriate fields of EDIDD type structure
o Append the EDIDD structure to the EDIDD type internal table
Now, call the function module MASTER_IDOC_DISTRIBUTE and pass the IDoc control record
structure and data record table
Commit work if return code is zero
Function module returns a table of type EDIDC to provide the details about generated IDoc
Display appropriate log
You can see sample code for the above program here.
REPORT ZRZ_ORDER_IDOC .
***********************************************************************
* PURPOSE OF REPORT *
***********************************************************************
*Generats an Idoc for Customer Master, Sales Master and Sales item table
***********************************************************************
CONSTANTS :
C_ZRZSEG1 LIKE EDIDD-SEGNAM VALUE 'ZRZSEG1',
C_ZRZSEG2 LIKE EDIDD-SEGNAM VALUE 'ZRZSEG2',
C_ZRZSEG3 LIKE EDIDD-SEGNAM VALUE 'ZRZSEG3'.
***START-OF-SELECTION
START-OF-SELECTION.
PERFORM GENERATE_DATA_RECORDS.
PERFORM GENERATE_CONTROL_RECORD.
PERFORM SEND_IDOC.
***********************************************************************
*&---------------------------------------------------------------------*
*& Form generate_data_records
*&---------------------------------------------------------------------*
FORM GENERATE_DATA_RECORDS .
PERFORM FETCH_ZCUSTOMERS.
PERFORM FETCH_ZSOHEADERS.
PERFORM FETCH_ZSOITEMS.
PERFORM ARRANGE_DATA_RECORDS.
ENDFORM. " generate_data_records
*&---------------------------------------------------------------------*
*& Form fetch_zcustomers
*&---------------------------------------------------------------------*
FORM FETCH_ZCUSTOMERS.
SELECT *
FROM ZCUSTOMERS
INTO TABLE T_ZCUSTOMERS
WHERE KUNNR IN S_KUNNR.
IF SY-SUBRC NE 0.
MESSAGE E398(00) WITH 'No Customers Found'.
ENDIF.
ENDFORM. " fetch_zcustomers
*&---------------------------------------------------------------------*
*& Form fetch_zsoheaders
*&---------------------------------------------------------------------*
FORM FETCH_ZSOHEADERS.
SELECT *
FROM ZSOHEADERS
INTO TABLE T_ZSOHEADERS
WHERE VBELN IN S_VBELN
AND KUNNR IN S_KUNNR.
IF SY-SUBRC NE 0.
MESSAGE I398(00) WITH 'No Sales orders found'.
ENDIF.
ENDFORM. " fetch_zsoheaders
*&---------------------------------------------------------------------*
*& Form fetch_zsoitems
*&---------------------------------------------------------------------*
FORM FETCH_ZSOITEMS.
IF NOT T_ZSOHEADERS[] IS INITIAL.
SELECT *
FROM ZSOITEMS
INTO TABLE T_ZSOITEMS
FOR ALL ENTRIES IN T_ZSOHEADERS
WHERE VBELN = T_ZSOHEADERS-VBELN.
IF SY-SUBRC NE 0.
MESSAGE I398(00) WITH 'No Sales order items found'.
ENDIF.
ENDIF.
ENDFORM. " fetch_zsoitems
*&---------------------------------------------------------------------*
*& Form generate_control_record
*&---------------------------------------------------------------------*
FORM GENERATE_CONTROL_RECORD .
S_CTRL_REC-RCVPOR = C_RCVPOR. "Receiver Port
S_CTRL_REC-MESTYP = C_MESTYP. "Message type
S_CTRL_REC-IDOCTP = C_IDOCTP. "Basic IDOC type
S_CTRL_REC-RCVPRT = C_RCVPRT. "Partner type of receiver
S_CTRL_REC-RCVPRN = C_LOGSYS. "Partner number of receiver
*&---------------------------------------------------------------------*
*& Form send_idoc
*&---------------------------------------------------------------------*
FORM SEND_IDOC.
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
EXPORTING
MASTER_IDOC_CONTROL = S_CTRL_REC
TABLES
COMMUNICATION_IDOC_CONTROL = T_COMM_IDOC
MASTER_IDOC_DATA = T_EDIDD
EXCEPTIONS
ERROR_IN_IDOC_CONTROL = 1
ERROR_WRITING_IDOC_STATUS = 2
ERROR_IN_IDOC_DATA = 3
SENDING_LOGICAL_SYSTEM_UNKNOWN = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
COMMIT WORK.
LOOP AT T_COMM_IDOC.
WRITE:/ 'IDoc Generated - ', T_COMM_IDOC-DOCNUM.
ENDLOOP.
ENDIF.
ENDFORM. " send_idoc
*&---------------------------------------------------------------------*
*& Form arrange_data_records
*&---------------------------------------------------------------------*
FORM ARRANGE_DATA_RECORDS .
DATA: W_INDEX1 LIKE SY-TABIX,
W_INDEX2 LIKE SY-TABIX.
SORT T_ZCUSTOMERS BY KUNNR.
SORT T_ZSOHEADERS BY KUNNR VBELN.
SORT T_ZSOITEMS BY VBELN POSNR.
LOOP AT T_ZCUSTOMERS.
S_ZRZSEG1-KUNNR = T_ZCUSTOMERS-KUNNR.
S_ZRZSEG1-NAME1 = T_ZCUSTOMERS-NAME1.
S_ZRZSEG1-ORT01 = T_ZCUSTOMERS-ORT01.
S_ZRZSEG1-LAND1 = T_ZCUSTOMERS-LAND1.
T_EDIDD-SEGNAM = C_ZRZSEG1.
T_EDIDD-SDATA = S_ZRZSEG1.
APPEND T_EDIDD.
CLEAR T_EDIDD.
CLEAR W_INDEX1.
READ TABLE T_ZSOHEADERS WITH KEY KUNNR = T_ZCUSTOMERS-KUNNR BINARY SEARCH.
IF SY-SUBRC = 0.
W_INDEX1 = SY-TABIX.
LOOP AT T_ZSOHEADERS FROM W_INDEX1.
IF T_ZSOHEADERS-KUNNR NE T_ZCUSTOMERS-KUNNR.
EXIT.
ENDIF.
S_ZRZSEG2-VBELN = T_ZSOHEADERS-VBELN.
S_ZRZSEG2-KUNNR = T_ZSOHEADERS-KUNNR.
T_EDIDD-SEGNAM = C_ZRZSEG2.
T_EDIDD-SDATA = S_ZRZSEG2.
APPEND T_EDIDD.
CLEAR T_EDIDD.
CLEAR W_INDEX2.
READ TABLE T_ZSOITEMS WITH KEY VBELN = T_ZSOHEADERS-VBELN BINARY SEARCH.
IF SY-SUBRC = 0.
W_INDEX2 = SY-TABIX.
LOOP AT T_ZSOITEMS FROM SY-TABIX.
IF T_ZSOITEMS-VBELN NE T_ZSOHEADERS-VBELN.
EXIT.
ENDIF.
S_ZRZSEG3-VBELN = T_ZSOITEMS-VBELN.
S_ZRZSEG3-POSNR = T_ZSOITEMS-POSNR.
S_ZRZSEG3-MATNR = T_ZSOITEMS-MATNR.
S_ZRZSEG3-NETWR = T_ZSOITEMS-NETWR.
S_ZRZSEG3-ZMENG = T_ZSOITEMS-ZMENG.
T_EDIDD-SEGNAM = C_ZRZSEG3.
T_EDIDD-SDATA = S_ZRZSEG3.
APPEND T_EDIDD.
CLEAR T_EDIDD.
ENDLOOP.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.
ENDFORM. " arrange_data_records
Thus we have completed sender side configuration required for ALE. In the next part we will see how to
configure the receiving system to be able to receive and post the inbound IDoc.
In the receiving system, create a function module Z_IDOC_INPUT_ZRZSO_MT using SE37. Below, I have
described the logic for the same.
You can see the sample ABAP code for the above function module here.
FUNCTION Z_IDOC_INPUT_ZRZSO_MT.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD
*" VALUE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC
*" EXPORTING
*" VALUE(WORKFLOW_RESULT) LIKE BDWF_PARAM-RESULT
*" VALUE(APPLICATION_VARIABLE) LIKE BDWF_PARAM-APPL_VAR
*" VALUE(IN_UPDATE_TASK) LIKE BDWFAP_PAR-UPDATETASK
*" VALUE(CALL_TRANSACTION_DONE) LIKE BDWFAP_PAR-CALLTRANS
*" TABLES
*" IDOC_CONTRL STRUCTURE EDIDC
*" IDOC_DATA STRUCTURE EDIDD
*" IDOC_STATUS STRUCTURE BDIDOCSTAT
*" RETURN_VARIABLES STRUCTURE BDWFRETVAR
*" SERIALIZATION_INFO STRUCTURE BDI_SER
*" EXCEPTIONS
*" WRONG_FUNCTION_CALLED
*"----------------------------------------------------------------------
* Include File containing ALE constants
INCLUDE MBDCONWF.
TABLES : ZCUSTOMERS, "Cutomer Header
ZSOHEADERS, "Sales Header
ZSOITEMS. "Sales Items
***Data
DATA : W_ZRZSEG1 LIKE ZRZSEG1,
W_ZRZSEG2 LIKE ZRZSEG2,
W_ZRZSEG3 LIKE ZRZSEG3.
***********************************************************************
WORKFLOW_RESULT = C_WF_RESULT_OK.
LOOP AT IDOC_CONTRL.
IF IDOC_CONTRL-MESTYP NE 'ZRZSO_MT'.
RAISE WRONG_FUNCTION_CALLED.
ENDIF.
************************************************************************
* CUSTOMER HEADER *
************************************************************************
* SELECT *
* FROM zcustomers.
* ENDSELECT.
* IF sy-subrc NE 0.
* INSERT INTO zcustomers VALUES t_zcustomers.
* ELSE.
UPDATE ZCUSTHEAD FROM T_ZCUSTOMERS.
* ENDIF.
IF SY-SUBRC EQ 0.
IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
IDOC_STATUS-STATUS = '53'.
IDOC_STATUS-MSGTY = 'I'.
IDOC_STATUS-MSGID = 'YM'.
IDOC_STATUS-MSGNO = '004'.
IDOC_STATUS-MSGV1 = T_ZCUSTOMERS-KUNNR.
APPEND IDOC_STATUS.
CLEAR IDOC_STATUS.
ELSE.
IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
IDOC_STATUS-STATUS = '51'.
IDOC_STATUS-MSGTY = 'E'.
IDOC_STATUS-MSGID = 'YM'.
IDOC_STATUS-MSGNO = '005'.
IDOC_STATUS-MSGV1 = T_ZCUSTOMERS-KUNNR.
APPEND IDOC_STATUS.
CLEAR IDOC_STATUS.
WORKFLOW_RESULT = C_WF_RESULT_ERROR.
RETURN_VARIABLES-WF_PARAM = 'Error_Idocs'.
RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.
APPEND RETURN_VARIABLES.
CLEAR RETURN_VARIABLES.
ENDIF.
************************************************************************
* SALES HEADER *
************************************************************************
* SELECT *
* FROM zsoheaders.
* ENDSELECT.
* IF sy-subrc NE 0.
* INSERT INTO zsoheaders VALUES t_zsoheaders.
* ELSE.
UPDATE ZSOHEADERS FROM T_ZSOHEADERS.
* ENDIF.
IF SY-SUBRC EQ 0.
IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
IDOC_STATUS-STATUS = '53'.
IDOC_STATUS-MSGTY = 'I'.
IDOC_STATUS-MSGID = 'YM'.
IDOC_STATUS-MSGNO = '004'.
IDOC_STATUS-MSGV1 = T_ZSOHEADERS-VBELN.
APPEND IDOC_STATUS.
CLEAR IDOC_STATUS.
ELSE.
IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
IDOC_STATUS-STATUS = '51'.
IDOC_STATUS-MSGTY = 'E'.
IDOC_STATUS-MSGID = 'YM'.
IDOC_STATUS-MSGNO = '005'.
IDOC_STATUS-MSGV1 = T_ZSOHEADERS-VBELN.
APPEND IDOC_STATUS.
CLEAR IDOC_STATUS.
WORKFLOW_RESULT = C_WF_RESULT_ERROR.
RETURN_VARIABLES-WF_PARAM = 'Error_Idocs'.
RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.
APPEND RETURN_VARIABLES.
CLEAR RETURN_VARIABLES.
ENDIF.
************************************************************************
* SALES ITEM *
************************************************************************
* SELECT *
* FROM zsoitems.
* ENDSELECT.
* IF sy-subrc NE 0.
* INSERT INTO zsoitems VALUES t_zsoitems.
* ELSE.
UPDATE ZSOITEMS FROM T_ZSOITEMS.
* ENDIF.
IF SY-SUBRC EQ 0.
IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
IDOC_STATUS-STATUS = '53'.
IDOC_STATUS-MSGTY = 'I'.
IDOC_STATUS-MSGID = 'YM'.
IDOC_STATUS-MSGNO = '004'.
IDOC_STATUS-MSGV1 = T_ZSOITEMS-VBELN.
APPEND IDOC_STATUS.
CLEAR IDOC_STATUS.
ELSE.
IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
IDOC_STATUS-STATUS = '51'.
IDOC_STATUS-MSGTY = 'E'.
IDOC_STATUS-MSGID = 'YM'.
IDOC_STATUS-MSGNO = '005'.
IDOC_STATUS-MSGV1 = T_ZSOITEMS-VBELN.
APPEND IDOC_STATUS.
CLEAR IDOC_STATUS.
WORKFLOW_RESULT = C_WF_RESULT_ERROR.
RETURN_VARIABLES-WF_PARAM = 'Error_Idocs'.
RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.
APPEND RETURN_VARIABLES.
CLEAR RETURN_VARIABLES.
ENDIF.
************************************************************************
ENDLOOP.
ENDFUNCTION.
Inbound Settings
Define Logical Systems – Transaction SALE (Please refer to Outbound Settings discussed in previous
part)
Assign Client to Logical System – Transaction SALE (Please refer to Outbound Settings discussed in
previous part)
Maintain RFC Destinations – Transaction SM59 (Please refer to Outbound Settings discussed in
previous part)
Define Ports – Transaction WE21 (Please refer to Outbound Settings discussed in previous part)
Generate/Create Partner Profile – Transactions BD82/WE20 (Please refer to Outbound Settings
discussed in previous part)
Assign Function Module to Logical message – Transaction WE57
o Create a new entry
o Specify name of the Function Module as Z_IDOC_INPUT_ZRZSO_MT
o Also, specify Type as F, Basic IDoc type as ZRZORDER, Message type as ZRZSO_MT and
Direction as 2 (Inbound)
o Save the entry
Define Input method for Inbound Function Module – Transaction BD51
o Create a new entry
o Provide Function Module name as Z_IDOC_INPUT_ZRZSO_MT
o Specify the Input method as 2
o Save the entry
Create a Process Code – Transaction WE42
o Create a new Process Code ZPCRZ
o Select Processing with ALE Service
o Choose Processing type as Processing by function module
o Save the entry
o On the next screen, select your function module from the list
o Save the changes
o Now you will be taken to the next screen
o Double-click on Logical message
o In the Assignment to logical message, specify the message type ZRZSO_MT
o Save the changes
On the sender system, execute the IDoc Generation Program. Check the status of IDoc using transaction WE02.
Check the status of the IDoc in the receiver system using transaction WE02. You can also check the contents of
DDic tables to make sure that the records have been created in the receiver system.
Thus to summarize we have learned how to:
MM90 Interpretare mesaje din IDOCs (se ia mesajul de eroare din IDOC si se merge in tranzactie
unde se obtine un log al mesajului) se poate intra in eroarea din IDOC si de afiseaza detaliile
pe masaj si folosind procede se obtine acelasi log pentru mesaj
WE30 Tip de IDOC – defineste structura unui IDOC (include tip de mesaj)