ALE Between Two SAP Systems
ALE Between Two SAP Systems
systems
Developing and configuring IDOC using ALE to send and receive data from one SAP
system to another SAP system
A+ A-
In practice versions we have two clients 800 and 810, for practice purpose we will
send data to 810 client from 800 client using ALE IDOCS.
By the end of this lesson you will be able to understand ALE and IDOC
implementation and you will be able to develop a real-time communication network
between two systems to send and receive data using ALE network by using IDOC.
As per practice/training purpose we assume 800 and 810 clients are different
systems (If you don`t have 800 and 810 clients in your system, use any other
clients).
Assume client 800 is source system and client 810 is destination system.
Requirement: All the students data will be created in 800 client and same will be
send to 810 client using IDOCS.
Steps to be done in 800 client
Just click enter if you find any information message and add fields as below.
This is the most confusing step in ALE configurations, try to understand carefully.
In a blind way logical system assigned in target system client(in our example 810
client) should be in logical system definition in source client.
Check for logical system existence(which we get from 810 client) if it is there, no
need to add, if it is not there add it.
Click on logon and security tab, provide client, user name, password and save.
Click on connection test to test connection.
Save.
Go to WE20, expand partner type logical system and search for logical system (Get
logical system from t-code SALE ->Basic Settings ->Logical Systems -> assign
logical system to client -> 810 (double click and copy logical system)).
If logical system is already available in partner profiles in WE20, we don`t need to
create partner profile again instead we will add message type at out bound
parameters level. In my case, logical system is already available in partner profiles
so I will add ZSTUDENT message type to it. To add message type, select logical
system, click on add icon (see below image).
Provide message type, receiver port (which we have created in step9), select
transfer IDOC immediately, basic type and save.
If logical system is not available in partner profile in WE20, select partner type logical
system and click on create.
Provide partner no as T90CLNT810 (Get logical system from t-code SALE ->Basic
Settings ->Logical Systems -> assign logical system to client -> 810 (double click
and copy logical system). Save and add message type at out bound partner level.
Every inbound IDOC will have process code, every process code is associated with
a inbound process ex: Function Module or Work Flow Task.
Step 3: Add your own code in function module. Go to Se37, provide name as
ZSAPN_IDOC_INPUT_STUDENT, click on change. Remove all code and add below
code.
FUNCTION ZSAPN_IDOC_INPUT_STUDENT.
*"---------------------------------------------------------------------
-
*"*"Local Interface:
*" IMPORTING
*" VALUE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD
*" VALUE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC
*" VALUE(NO_APPLICATION_LOG) LIKE SY-DATAR OPTIONAL
*" VALUE(MASSSAVEINFOS) LIKE MASSSAVINF STRUCTURE MASSSAVINF
*" OPTIONAL
*" VALUE(KZ_TEST) LIKE MDAT1-KZ_TEST DEFAULT SPACE
*" VALUE(ONLY_MAPPING) LIKE MDAT1-KZ_TEST DEFAULT SPACE
*" 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
*"---------------------------------------------------------------------
-
SORT IDOC_DATA BY DOCNUM.
SORT IDOC_CONTRL BY DOCNUM.
DATA : T_EDIDD TYPE STANDARD TABLE OF EDIDD,
"Data Record
T_EDIDC TYPE STANDARD TABLE OF EDIDC,
"Control Record
T_EDIDS TYPE STANDARD TABLE OF BDIDOCSTAT.
"Status Record
*----------*Global Work Area Declarations *------------------------*
DATA : W_EDIDC LIKE EDIDC,
W_EDIDD TYPE EDIDD,
W_EDIDS TYPE BDIDOCSTAT.
DATA: W_IDOC_DATA TYPE EDIDD.
DATA : L_INDX TYPE SYTABIX.
DATA: IT_STUDENT TYPE TABLE OF ZSTUDENT.
DATA : WA_STUDENT TYPE ZSTUDENT.
DATA : ERROR_MESSAGE TYPE STRING.
DATA : T_STUDENTS TYPE TABLE OF ZSTUDENTS.
DATA : W_STUDENTS TYPE ZSTUDENTS.
DATA : ERROR_FLG TYPE CHAR1.
* Go through all IDocs
LOOP AT IDOC_CONTRL.
CLEAR W_EDIDC.
W_EDIDC = IDOC_CONTRL.
READ TABLE IDOC_DATA INTO W_IDOC_DATA WITH KEY DOCNUM =
IDOC_CONTRL-DOCNUM BINARY SEARCH.
IF SY-SUBRC = 0.
L_INDX = SY-TABIX.
LOOP AT IDOC_DATA FROM L_INDX.
IF IDOC_DATA-DOCNUM = IDOC_CONTRL-DOCNUM.
APPEND IDOC_DATA TO T_EDIDD.
CLEAR IDOC_DATA.
ELSE.
RETURN.
ENDIF.
ENDLOOP.
ELSE.
CONTINUE.
ENDIF.
SORT T_EDIDD.
CLEAR W_EDIDD.
LOOP AT T_EDIDD INTO W_EDIDD.
IF W_EDIDD-SEGNAM = 'ZSTUDENT'.
CLEAR WA_STUDENT.
WA_STUDENT = W_EDIDD-SDATA.
IF WA_STUDENT IS NOT INITIAL.
APPEND WA_STUDENT TO IT_STUDENT.
ENDIF.
CONTINUE.
ENDIF.
ENDLOOP.
IF IT_STUDENT IS NOT INITIAL. "if data is there in segment
LOOP AT IT_STUDENT INTO WA_STUDENT.
MOVE-CORRESPONDING WA_STUDENT TO W_STUDENTS.
MODIFY ZSTUDENTS FROM W_STUDENTS. "update data base table
IF SY-SUBRC <> 0.
ERROR_FLG = 'X'.
ERROR_MESSAGE = 'Error occured in updating ZSTUDENT table'.
ENDIF.
ENDLOOP.
ENDIF.
IF ERROR_FLG = 'X'. "add error status to IDOC
IDOC_STATUS-STATUS = '51'.
IDOC_STATUS-DOCNUM = W_EDIDC-DOCNUM.
IDOC_STATUS-MSGTY = 'E'.
IDOC_STATUS-MSGID = '00'.
IDOC_STATUS-MSGNO = '398'.
IDOC_STATUS-MSGV1 = ERROR_MESSAGE+0(25). "t_return_ecm-message
IDOC_STATUS-MSGV2 = ERROR_MESSAGE+25(25).
IDOC_STATUS-MSGV3 = ERROR_MESSAGE+50(25).
IDOC_STATUS-MSGV4 = ERROR_MESSAGE+75(25).
CLEAR ERROR_MESSAGE.
APPEND IDOC_STATUS TO IDOC_STATUS .
CLEAR IDOC_STATUS .
else. "add success status to IDOC
IDOC_STATUS-STATUS = '53'.
IDOC_STATUS-DOCNUM = W_EDIDC-DOCNUM.
APPEND IDOC_STATUS TO IDOC_STATUS .
CLEAR IDOC_STATUS .
ENDIF.
ENDLOOP.
ENDFUNCTION.
Save and activate.
IMP Note: If you don`t find change icon or if you find a message like 'You are not
allowed to cross client customization' log on to 800 client and do this step.
IMP Note: If you don`t find change icon or if you find a message like 'You are not
allowed to cross client customization' log on to 800 client and do this step.
Save it in a transport request.
REPORT ZSEND_STUDENTS.
START-OF-SELECTION.
SELECT * FROM ZSTUDENTS INTO TABLE ZSTUDENTS WHERE STUDENT_ID IN
S_STD.
LOOP AT ZSTUDENTS INTO WA_STUDENTS. "send students on eby one
MOVE-CORRESPONDING WA_STUDENTS TO ZSTUDENT.
CLEAR T_EDIDD.
T_EDIDD-SEGNAM = 'ZSTUDENT'. "segment name
T_EDIDD-SDATA = ZSTUDENT. "IDOC data record
APPEND T_EDIDD.
* Fill control record
CLEAR F_EDIDC.
F_EDIDC-MESTYP = 'ZSTUDENT'. "Message type
F_EDIDC-DOCTYP = 'ZSTUDENT'. "IDOC type
F_EDIDC-RCVPRT = 'LS'. "Partner type
F_EDIDC-RCVPRN = 'T90CLNT810'. "Receiver partner
COMMIT WORK.
CLEAR : WA_STUDENTS, ZSTUDENT.
REFRESH : T_EDIDD.
ENDLOOP.
Execute the above program and provide students ids to send.
Now go to WE09 and check status in 800 client.
Go to 810 client and check table ZSTUDENTS for entries(entries should be created).