8/12/2019 Beginners Guide to ALE and IDocs
1/15
Beginners Guide to ALE and IDocs a step-by-step approachhttp://www.riya.net/b!og/beginners-guide-to-a!e-and-idocs-a-step-by-step-approach/techno!ogy/sap/"#/
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 A! system and then post some business data throu"h it to
another A! system. #usiness data will be pic$ed up from custom data dictionary tables.
ALE % Application Lin$ Enablin" is a mechanism by which A! systems communicate with each
other and with non-A! EDI subsystems. Thus it helps inte"ration of distributed systems. It supports
fail-safe delivery which implies that sender system does not have to worry about messa"e not
reachin" the source due to unavoidable situations. ALE can be used for mi"ration and maintenance
of master data as well as for exchan"in" transactional data.
The messa"es that are exchan"ed are in the form of IDocs or Intermediate Documents. IDocs act li$e
a container or envelope for the application data. An ID&' is created as a result of execution of an
&utbound ALE. In an Inbound ALE an ID&' serves as an input to create application document. In the
A! system IDocs are stored in the database tables. They can be used for A! to A! and A! to
non-A! process communication as lon" as the participatin" processes can understand the syntax
and semantics of the data. 'omplete documentation on ID&' is obtained by usin" transaction WE().
Every IDoc has exactly one control record alon" with a number of data records and status records.
'ontrol record has the details of sender*receiver and other control information. Data records contain
the actual business data to be exchan"ed while the status records are attached to IDoc throu"hout
the process as the IDoc moves from one step to other.
+ow, let us understand the ALE 'onfi"uration by means of an example scenario below
The Scenario
Data from custom tables created in customer
namespace/ is to be formatted into an IDoc and sent from
one A! 0*1 system to another usin" ALE service. We
need to have two instances of A! 0*1 systems or we cansimulate this on two clients of the same A! 0*1 system.
'reate three tables as shown below.
http://www.riyaz.net/blog/beginners-guide-to-ale-and-idocs-a-step-by-step-approach/technology/sap/18/http://www.riyaz.net/blog/beginners-guide-to-ale-and-idocs-a-step-by-step-approach/technology/sap/18/http://www.riyaz.net/blog/beginners-guide-to-ale-and-idocs-a-step-by-step-approach/technology/sap/18/http://www.riyaz.net/blog/beginners-guide-to-ale-and-idocs-a-step-by-step-approach/technology/sap/18/8/12/2019 Beginners Guide to ALE and IDocs
2/15
Creating Custom IDoc type and Message type
All the ob2ects created should be present on both source as well as tar"et systems/.
3. 'reate se"ments % Transaction WE13
'reate a se"ment 404E53
Add all fields of table 4'6T&7E0 to it
ave the se"ment
0elease it usin" the menu path Edit -8 et 0elease
imilarly create two more se"ments "iven below
e". 404E59 % to hold all fields of table 4&:EADE0
e". 404E51 % to hold all fields of table 4&ITE7
9. 'reate #asic IDoc type % Transaction WE1)
8/12/2019 Beginners Guide to ALE and IDocs
3/15
'reate a #asic type 404&0DE0
Add the created se"ments in the hierarchy shown
7aintain attributes for each of the se"ments
ave the ob2ect and "o bac$
0elease the ob2ect usin" the menu path Edit -8 et 0elease
1. 'reate*Assi"n 7essa"e type % Transactions WE;3*WE;9
5o to WE;3
'reate a new 7essa"e type 404&
8/12/2019 Beginners Guide to ALE and IDocs
4/15
Add a new entry
pecify the client, previously created lo"ical system and other attributes
ave the entry
Define a new lo"ical system to identify the partner system and save it
7aintain 0>' Destinations % Transaction 7?@
'reate a new 0>' destination for 0*1 type connection
pecify the tar"et host on Technical settin"s tab
!rovide the Lo"on credentials on the Lo"on*ecurity tab
ave the settin"s
To verify the settin"s, 'lic$ on Test connection or 0emote lo"on
Define !orts % Transaction WE93
We need to define a t0>' port for the partner system
'lic$ on Transactional 0>' node
'reate a new port
!rovide a description
pecify the name of the tar"et 0>' destination
ave the ob2ect
7aintain Distribution 7odel % Transaction #D(
'lic$ on 'han"e
'reate a new model view
!rovide a hort text and Technical name to the model view
Add messa"e type
pecify sender and receiver systems
Also, specify the messa"e type that we created previously
ave the Distribution model
5enerate*'reate !artner !rofile % Transactions #D;9*WE9)
8/12/2019 Beginners Guide to ALE and IDocs
5/15
To "enerate !artner profiles automatically you may use #D;9 or "o to #D( and use the menu path
Environment -8 5enerate partner profiles
&therwise, you may use transaction WE9) to create a partner profile
&n selection screen, specify the model view, tar"et system and execute
The result lo" will be displayed on the next screen
To verify the partner profile "o to WE9)
'hec$ the partner profile for the tar"et system
Distribute 7odel =iew % Transaction #D(
elect the 7odel =iew
5o to menu path Edit -8 7odel =iew -8 Distribute
0esult lo" will be displayed on the next screen
"utbound IDoc #eneration $rogram
'reate an executable pro"ram 404ill the control record structure of type EDID'
8/12/2019 Beginners Guide to ALE and IDocs
6/15
pecify messa"e type, #asic IDoc type, t0>' !ort, !artner number and !artner type of the
receiver
>ill the data records
Define structures li$e the IDoc se"ments
>ill the structures with fetched data
!ass the se"ment name and the above structure to the appropriate fields of EDIDD type
structure
Append the EDIDD structure to the EDIDD type internal table
+ow, call the function module 7ATE0unction module returns a table of type EDID' to provide the details about "enerated IDoc
Display appropriate lo"
Cou can download sample code for the above pro"ram here.
*&---------------------------------------------------------------------**& Report ZRZ_ORDER_IDOC **& **&---------------------------------------------------------------------*
REPORT ZRZ_ORDER_IDOC .
************************************************************************ PURPOSE OF REPORT ************************************************************************* Generats an Idoc for Custoer !aster" Sa#es !aster* and Sa#es $te ta%#e.***********************************************************************
T'(ES ) ZCUSTO!ERS" Cutoer +eader ZSO+EDERS" Sa#es +eader ZSOITE!S. Sa#es Ites
DT ) S_CTR(_REC (I,E EDIDC" Idoc Contro# Record S_ZRZSEG (I,E ZRZSEG" CUSTO!ER +eader Data S_ZRZSEG (I,E ZRZSEG" S(ES +EDER Data S_ZRZSEG/ (I,E ZRZSEG/. S(ES Deta$# Data
DT ) T_ZCUSTO!ERS (I,E ZCUSTO!ERS OCCURS 0 1IT+ +EDER (I2E.DT ) T_ZSO+EDERS (I,E ZSO+EDERS OCCURS 0 1IT+ +EDER (I2E.DT ) T_ZSOITE!S (I,E ZSOITE!S OCCURS 0 1IT+ +EDER (I2E.DT ) T_EDIDD (I,E EDIDD OCCURS 0 1IT+ +EDER (I2E.Data RecordsDT ) T_CO!!_IDOC (I,E EDIDC OCCURS 0 1IT+ +EDER (I2E.Generated Coun$cat$on IDOc
http://cdn.riyaz.net/blog/files/ZRZ_ORDER_IDOC.txthttp://cdn.riyaz.net/blog/files/ZRZ_ORDER_IDOC.txt8/12/2019 Beginners Guide to ALE and IDocs
7/15
CO2ST2TS )C_ZRZSEG (I,E EDIDD-SEG2! 3(UE 4ZRZSEG4"C_ZRZSEG (I,E EDIDD-SEG2! 3(UE 4ZRZSEG4"C_ZRZSEG/ (I,E EDIDD-SEG2! 3(UE 4ZRZSEG/4.
CO2ST2TS) C_IDOCTP (I,E EDIDC-IDOCTP 3(UE 4ZRZORDER4.
*** Se#ect$on ScreenSE(ECT-OPTIO2S ) S_,U22R FOR ZCUSTO!ERS-,U22R O'(IGTOR5" S_3'E(2 FOR ZSO+EDERS-3'E(2.PR!ETERS ) C_!EST5P (I,E EDIDC-!EST5P DEFU(T 4ZRZSO_!T4" !essa6e T7pe C_RC3PRT (I,E EDIDC-RC3PRT DEFU(T 4(S4" Partner t7pe of rece$8er C_(OGS5S (I,E EDIDC-RC3PR2 DEFU(T 45904" C_RC3POR (I,E EDIDC-RC3POR DEFU(T 4000000:4" C_S2DPR2 (I,E EDIDC-S2DPR2 DEFU(T 4(SSE2DS4" C_S2DPRT (I,E EDIDC-S2DPRT DEFU(T 4(S4.Dest$nat$on S7ste
***STRT-OF-SE(ECTIO2STRT-OF-SE(ECTIO2. PERFOR! GE2ERTE_DT_RECORDS. PERFOR! GE2ERTE_CO2TRO(_RECORD. PERFOR! SE2D_IDOC.
***********************************************************************
*&---------------------------------------------------------------------**& For 6enerate_data_records*&---------------------------------------------------------------------*
FOR! GE2ERTE_DT_RECORDS . PERFOR! FETC+_ZCUSTO!ERS. PERFOR! FETC+_ZSO+EDERS. PERFOR! FETC+_ZSOITE!S. PERFOR! RR2GE_DT_RECORDS.E2DFOR!. 6enerate_data_records
*&---------------------------------------------------------------------**& For fetc;_00? 1IT+ 42o Custoers Found4. E2DIF.E2DFOR!. fetc;_
8/12/2019 Beginners Guide to ALE and IDocs
8/15
*&---------------------------------------------------------------------*FOR! FETC+_ZSO+EDERS. SE(ECT * FRO! ZSO+EDERS I2TO T'(E T_ZSO+EDERS 1+ERE 3'E(2 I2 S_3'E(2 2D ,U22R I2 S_,U22R. IF S5-SU'RC 2E 0. !ESSGE I/9=>00? 1IT+ 42o Sa#es orders found4. E2DIF.
E2DFOR!. fetc;_00? 1IT+ 42o Sa#es order $tes found4. E2DIF. E2DIF.E2DFOR!. fetc;_
8/12/2019 Beginners Guide to ALE and IDocs
9/15
OT+ERS B . IF S5-SU'RC 0. !ESSGE ID S5-!SGID T5PE S5-!SGT5 2U!'ER S5-!SG2O 1IT+ S5-!SG3 S5-!SG3 S5-!SG3/ S5-!SG3. E(SE. CO!!IT 1OR,. (OOP T T_CO!!_IDOC. 1RITE)H 4IDoc Generated - 4" T_CO!!_IDOC-DOC2U!. E2D(OOP. E2DIF.
E2DFOR!. send_$doc
*&---------------------------------------------------------------------**& For arran6e_data_records*&---------------------------------------------------------------------*FOR! RR2GE_DT_RECORDS . DT) 1_I2DE (I,E S5-T'I" 1_I2DE (I,E S5-T'I. SORT T_ZCUSTO!ERS '5 ,U22R. SORT T_ZSO+EDERS '5 ,U22R 3'E(2. SORT T_ZSOITE!S '5 3'E(2 POS2R.
(OOP T T_ZCUSTO!ERS. S_ZRZSEG-,U22R B T_ZCUSTO!ERS-,U22R. S_ZRZSEG-2!E B T_ZCUSTO!ERS-2!E. S_ZRZSEG-ORT0 B T_ZCUSTO!ERS-ORT0. S_ZRZSEG-(2D B T_ZCUSTO!ERS-(2D. T_EDIDD-SEG2! B C_ZRZSEG. T_EDIDD-SDT B S_ZRZSEG. PPE2D T_EDIDD. C(ER T_EDIDD.
C(ER 1_I2DE. RED T'(E T_ZSO+EDERS 1IT+ ,E5 ,U22R B T_ZCUSTO!ERS-,U22R 'I2R5 SERC+.
IF S5-SU'RC B 0. 1_I2DE B S5-T'I. (OOP T T_ZSO+EDERS FRO! 1_I2DE. IF T_ZSO+EDERS-,U22R 2E T_ZCUSTO!ERS-,U22R. EIT. E2DIF. S_ZRZSEG-3'E(2 B T_ZSO+EDERS-3'E(2. S_ZRZSEG-,U22R B T_ZSO+EDERS-,U22R. T_EDIDD-SEG2! B C_ZRZSEG. T_EDIDD-SDT B S_ZRZSEG. PPE2D T_EDIDD. C(ER T_EDIDD.
C(ER 1_I2DE. RED T'(E T_ZSOITE!S 1IT+ ,E5 3'E(2 B T_ZSO+EDERS-3'E(2 'I2R5 SERC+. IF S5-SU'RC B 0. 1_I2DE B S5-T'I. (OOP T T_ZSOITE!S FRO! S5-T'I. IF T_ZSOITE!S-3'E(2 2E T_ZSO+EDERS-3'E(2. EIT. E2DIF. S_ZRZSEG/-3'E(2 B T_ZSOITE!S-3'E(2. S_ZRZSEG/-POS2R B T_ZSOITE!S-POS2R. S_ZRZSEG/-!T2R B T_ZSOITE!S-!T2R. S_ZRZSEG/-2ET1R B T_ZSOITE!S-2ET1R. S_ZRZSEG/-Z!E2G B T_ZSOITE!S-Z!E2G.
8/12/2019 Beginners Guide to ALE and IDocs
10/15
T_EDIDD-SEG2! B C_ZRZSEG/. T_EDIDD-SDT B S_ZRZSEG/. PPE2D T_EDIDD. C(ER T_EDIDD. E2D(OOP. E2DIF. E2D(OOP. E2DIF. E2D(OOP.E2DFOR!. arran6e_data_records
Thus we have completed sender side confi"uration reuired for ALE. In the next partwe will see how
to confi"ure the receivin" system to be able to receive and post the inbound IDoc.
Beginners Guide to ALE and IDocs $art IIIhttp://www.riyaz.net/blog/beginners-guide-to-ale-and-idocs-part-iii/technology/sap/20/
In the previous parts we learned how to create a custom IDocand set up the source system to send
an outbound IDoc. In this part we will learn how to confi"ure the receivin" A! 0*1 system to be able
to receive and post the inbound IDoc.
Inbound IDoc $osting %unction Module
In the receivin" system, create a function module 4. This include contains predefined ALE constants.
Loop at EDID' table
'hec$ if the messa"e type is 404&0DE0. &therwise raise W0&+56+'TI&+
8/12/2019 Beginners Guide to ALE and IDocs
11/15
8/12/2019 Beginners Guide to ALE and IDocs
12/15
************************************************************************* CUSTO!ER +EDER ************************************************************************** SE(ECT ** FRO!
8/12/2019 Beginners Guide to ALE and IDocs
13/15
PPE2D IDOC_STTUS. C(ER IDOC_STTUS. 1OR,F(O1_RESU(T B C_1F_RESU(T_ERROR. RETUR2_3RI'(ES-1F_PR! B 4Error_Idocs4. RETUR2_3RI'(ES-DOC_2U!'ER B IDOC_CO2TR(-DOC2U!. PPE2D RETUR2_3RI'(ES. C(ER RETUR2_3RI'(ES. E2DIF.************************************************************************* S(ES ITE! *
************************************************************************* SE(ECT ** FRO!
8/12/2019 Beginners Guide to ALE and IDocs
14/15
7aintain 0>' Destinations % Transaction 7?@ !lease refer to &utbound ettin"s discussed in
previous part/
Define !orts % Transaction WE93 !lease refer to &utbound ettin"s discussed in previous part/
5enerate*'reate !artner !rofile % Transactions #D;9*WE9) !lease refer to &utbound ettin"s
discussed inprevious part/
Assi"n >unction 7odule to Lo"ical messa"e % Transaction WE?
'reate a new entry
pecify name of the >unction 7odule as 4unction 7odule name as 4
8/12/2019 Beginners Guide to ALE and IDocs
15/15
Send and recei&e data
&n the sender system, execute the IDoc 5eneration !ro"ram. 'hec$ the status of IDoc usin"
transaction WE)9.
'hec$ the status of the IDoc in the receiver system usin" transaction WE)9. Cou can also chec$ the
contents of DDic tables to ma$e sure that the records have been created in the receiver system.
Thus to summariBe we have learned how to
'reate a custom IDoc
Write an &utbound IDoc 5eneration !ro"ram
Write Inbound >unction 7odule to post Inbound IDoc
'onfi"ure and test ALE scenario to transmit data between systems distributed across the networ$
http://www.riyaz.net/blog/beginners-guide-to-ale-and-idocs-a-step-by-step-approach/http://www.riyaz.net/blog/beginners-guide-to-ale-and-idocs-part-ii/http://www.riyaz.net/blog/beginners-guide-to-ale-and-idocs-a-step-by-step-approach/http://www.riyaz.net/blog/beginners-guide-to-ale-and-idocs-part-ii/