Sap Abap Idoc Documents & Programs
Sap Abap Idoc Documents & Programs
Sap Abap Idoc Documents & Programs
What is IDOC?
IDOC is acronym for Intermediate Document, which is a standard data format of SAP to interchange data between two systems. IDOC enables connection between different
applications using a message based interface.
ALE
Application link enabling is a mechanism through which multiple SAP R/3 systems can communicate each other. Integration of distributed systems is possible with application
link enabling.
EDI
EDI stands for Electronic Data Interchange, which is used to exchange business documents between different systems with a standard data format over a communication
network, the systems can be SAP - SAP or SAP - Non-SAP.
Inbound Process
Outbound Process
Inbound process is the process of transferring data into a SAP system from an SAP R/3 system of Non-SAP system. The following steps will takes place in inbound IDOC
process.
Inbound IDOC process happens in the following steps:
Outbound IDOC is the process of transferring data from an SAP system to another SAP system or to Non-SAP system.
1. IDOC Generated
2. IDOC transferred SAP to EDI layer
3. IDOC converted to EDI format
4. Data transferred to partner
5. New status will be updated
Structure of IDOC
Basically IDOC flows with three types of records
1. Control Record
2. Data Record
3. Status Record
Control Record
Every IDOC has only one control record, it carries only one record with information related to port, partner of sender and receiver etc.
Data Record
This is the record which carries actual business data in the form of segment's example Material Master Data, Customer master data etc.
Status Record
This is the record, which stores the status of IDOC processing stages ex: application document posted, Document contains errors etc.
Developing and configuring IDOC using ALE to send and receive data from one SAP
system to another SAP system
A+ A-
As a pert or training, we don`t have many systems to work on multiple systems, we will develop ALE connection and data transfer between two clients with in the same system.
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.
This is the most confusing step in ALE configurations, try to understand carefully.
'Logical system' is used to identify an individual client in a system, for ALE communication between SAP systems. That's why you see a field for 'logical system' in the client
master data in SCC4 (table T000). You use logical systems in ALE configuration - this should be documented further in the IMG guide, or SALE transaction
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.
(Get logical system from t-code SALE ->Basic Settings ->Logical Systems -> assign logical system to client -> 810 (double click and copy logical system)).
Step 2: Go to SALE.
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 2: Go to SE37, provide function module name as IDOC_INPUT_MATMAS01, click on copy, provide function module name as function group and enter.
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.
Click Save, create a transport request. Select function module from drop down and save it in transport request.
Step 12: Check partner profiles for inbound.
Go to WE20, expand logical system and select logical system(Get logical system from t-code SALE ->Basic Settings ->Logical Systems -> assign logical system to client -> 800
(double click and copy logical system)).
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.
Go to 810 client and check table ZSTUDENTS for entries(entries should be created).
Step-by-Step Tutorials
Step-by-step guide to ALE and IDOCs (More details) HOT
ALE step by Step Configuration for Message type MATMAS (More details)
Configuring Message Control and understanding how Message Control works (More details)
Distributing Material Master Data using Standalone programs and Change Pointers (More details)
Extending the standard IDOC for Outbound delivery (VL02N) (More details)
Customer exit for passing extra fields in Master data distribution using SMD tool (Shared master data tool) (More details)
Automatic Master Data distribution using the change pointers for Material Master Data (More details)
Create Condition Records Using the Message Type COND_A for condition table A018 (More details) NEW