Idoc

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 48

What is an IDoc? An IDoc Type is SAP's format for data being moved between applications.

Essentially, SAP has defined what a sales order, financial statement, invoice, etc will look like electronically. This includes how fields are grouped together (segments), the order and hierarchy of these groupings, and the format of each individual field. If you're familiar with EDI at all, then an IDoc will look very familiar to you. Nearly everything you're used to is there: from segment name to allowable codes to min/max occurs. It is important to note that an IDoc Type is really just a structure defined on the system and given a name (i.e., ORDERS04). An actual IDoc, however, consists of data, which fits within the defined structure of the IDoc Type. This IDoc is identified by a number rather than by a type. IDoc Structure The "only once" rule It is valuable to note that SAP only allows one occurence of each segment type within the IDoc structure. For instance, the E1EDKA1 segment may only exist once within the IDoc type. Now, does that mean you can only have one E1EDKA1 segment in an actual IDoc? Of course not. Segments may occur multiple times if the "max occurs" setting for that segment is greater than one. This is how the E1EDKA1 segment can appear multiple times in the ORDERS04 IDoc. This isn't a big deal if you're just using canned IDocs from SAP; but it is a useful consideration if you need to extend an existing IDoc substantially or create your own. Generic Structure Data within an IDoc is divided into three sections 1. Control Record, which contains (Table EDIDC) 1. Key Fields (for inbound) 1. Receiving Partner Type/ID (RCVPRT, RCVPRN) 2. Logical Message Type 3. Test Flag 2. Other Fields 1. IDoc Number (DOCNUM) 2. Direction (1=Outbound; 2=Inbound) 3. Sending Partner Type/ID (SNDPRT, SNDPRN) 4. Status 5. Receiver/Sender Port 6. Created Timestamp 7. Changed Timestamp 3. etc. Data Records (Table EDID4 in 4.6C) 1. Admin Data (39 bytes) 1. IDoc Number (DOCNUM) 2. Segment Number 3. Segment Name (SEGNAM) (e.g., E1EDK01, E1EDK03, etc) 4. etc 2. Actual Data (SDATA 1,000 bytes) Status Records (Table: EDIDS) 1. IDoc Number (DOCNUM) 2. Counter (COUNTR) 3. Status (STATUS) 4. etc

2.

3.

Additional Considerations 1. Data record table is version-specific. EDID4 is valid for the current release of SAP R/3 and may change in future versions.

2. 3. 4. 5. 6. 7. 8. 9.

The control record is common across all transactions and is used for routing the IDoc to the correct port in external processing, or to the correction function module or workflow item for inbound processing. Each IDoc may have several data records, which are arranged hierarchically. The data segment table (EDID4) contains this nesting information in the hierarchy field, etc. Each IDoc may have several status records, which are arranged in sequence. Segment Types begin with E1. This is the internal SAP format. Segment Definitions begin with E2. This is a fixed, version-specific format which defines how the outside world sees the segment. Segment Documentation records begin with E3. Outbound IDocs are created directly by a function module, or may be created via message control. Most outbound documents within OTC are created by message control. The global IDoc Administrator is defined in transaction OYEA.

Status Codes Outbound Codes 00 Not used, only R/2 01 IDoc created

Inbound Codes 50 IDoc added 51 Error: Application document not posted 52 Application document not fully posted 53 Application document posted 54 Error during formal application check 55 Formal application check OK 56 IDoc with errors added 57 Test IDoc: Error during application check 58 IDoc-Copy from an R/2 connection 59 Not used 60 Error during syntax check of IDoc (inbound) 61 Processing despite syntax error (inbound) 62 IDoc passed to application 63 Error passing IDoc to application 64 IDoc ready to be transferred to application 65 Error in ALE service

02 Error passing data to port

03 Data passed to port OK 04 Error within control information of EDI subsystem 05 Error during translation 06 Translation OK 07 Error during syntax check

08 Syntax check OK 09 Error during interchange handling 10 Interchange handling OK

11 Error during dispatch

12 Dispatch OK 13 Retransmission OK 14 Interchange Acknowledgement positive 15 Interchange Acknowledgement negative 16 Functional Acknowledgement positive

66 IDoc is waiting for predecessor IDoc (serialization)

17 Functional Acknowledgement negative 18 Triggering EDI subsystem OK 19 Data transfer for test OK 20 Error triggering EDI subsystem

67 Not used

68 Error - no further processing 69 IDoc was edited 70 Original of an IDoc which was edited 71 IDoc reloaded from archive

21 Error passing data for test

22 Dispatch OK, acknowledgement still 72 Not used, only R/2 due 23 Error during retransmission 24 Control information of EDI subsystem OK 73 IDoc archived 74 IDoc was created by test transaction

25 Processing despite syntax error (outbound) 26 Error during syntax check of IDoc (outbound) 27 Error in dispatch level (ALE service) 28 Not used 29 Error in ALE service 30 IDoc ready for dispatch (ALE service) 31 Error - no further processing 32 IDoc was edited 33 Original of an IDoc which was edited 34 Error in control record of IDoc 35 IDoc reloaded from archive 36 Electronic signature not performed (timeout) 37 IDoc added incorrectly 38 IDoc archived 39 IDoc is in the receiving system (ALE service) 40 Application document not created in receiving system 41 Application document created in receiving system 42 IDoc was created by test transaction

Structure SAP Auto-ID Infrastructure utilizes the following types of IDocs.

IDoc Description Operational IDoc EPC Serial Number Range IDoc Material Master Data IDoc Create and Change Material Master Data (Retail) IDoc Archiving IDoc Request IDoc SAP EM Event Message Input IDoc Extended Delivery Interface IDoc Step-by-step guide to ALE and IDOCs Introduction to EDI and ALE:

IDoc Type AIDOP01 AIDNR01 MATMAS01 ARTMAS01 AIDAR01 AIDRQ01 EVMSTA02 DELVRY04

Message Type AIDOPMSG AIDNRMSG AIDMATMAS ARTMAS AIDARCMSG AIDRQMSG EVMSTA AIDDESADV

EDI (Electronic Document interchange) - EDI is the electronic exchange of business documents between the computer systems of business partners, using a standard format over a communication network. EDI is also called paperless exchange. Advantages: Reduced Data entry errors Reduced processing time Availability of data in electronic form Reduced paperwork Reduced Cost Reduced inventories and better planning Standard means of communications Better business process EDI has two process 1. Outbound process 2. Inbound process Outbound Process: 1.Application document is created. 2. IDOC is generated 3.Idoc is transferred from SAP to Operating system layer 4.Idoc is converted into EDI standards 5.Edi document is transmitted to the business partner 6.The Edi Subsystem report status to SAP Inbound Process: 1.EDI transmission received 2.EDI document is converted into an IDOC 3.IDOC is transferred to the SAP layer 4.The application document is created 5.The application document can be viewed. IDOC: IDOC is a container that can be used to exchange data between any two processes. Each IDOC is assigned a unique number for tracking and future reference. IDOC consists of several segments, and segments contain several fields. IDOC contains the following three types of records... 1. One Control Record.

2. One or many Data Record 3. One or many Status record. In IDOCs the following terms are to be known. PORT: Port is used in the outbound process to determine the name of the EDI subsystem program, the directory path where the IDOC file will be created at the operating system level, the IDOC file names and the RFC destinations. RFC Destination: Used to define the characteristics of communication links to a remote system on which a functions needs to be executed. Partner Profile: Partner profile specified the various components used in an outbound process (Partner number, IDOC type, message type, Port, Process code), the mode in which it communicates with the subsystem (batch or immediate) and the person to be notified in case of errors. Message Control Used in pricing, account determination, material determination, and output determination. The message control component enables you to encapsulate business rules with out having to write ABAP programs. TO Process IDOCS the following TCODES will be used. On both sides: Logical System Names SALE Setup RFC destinations SM59 Port Destinations WE21 In Source system: Segment Creation WE31 Basic IDOC Type Creation WE30 Message Type Creation WE81 Assign Message Type To Basic IDOC Type WE82 Distribution Model BD64 Writing Report Program SE38 Partner Profile WE20 Message control NACE Check IDOCs WE02, WE05 In Destination System: Creating FM SE37 Assign FM to Logical Message WE57 Define I/P method for Inbound FM BD51 Create Process Code WE42

Generate Partner Profile BD64 IDOC processing in the same instance of R/3 Clients. For example two clients in the same R/3 instance. Client 900. Client 800. To transfer the data between two clients the table structures and their data types should be match. In this example, Client 900 is Source system, and Client 800 is destination system. In Client 900 I have created a customized table and inserted some records. In Client 800 I have created only table. Common Steps in Both Clients: Creating the Logical System Names and Assigning to Clients: Go to TCODE SALE. IMG path IDoc Interface / Application Link Enabling (ALE) -> Basic Settings -> Logical Systems -> Define Logical System

Click on Display / Change Button

Click on New Entries

Specify the Logical System name and description. Note: Logical System Naming convention is <SID>CLNT<NNN>

Click on Save and Back buttons Now you will come back to the IMG path screen. Click on Assign Logical System to client.

Click on Display / Change Button

Click on New Entries

Click on Save and Back. Creating the RFC Connection Names: Go to TCODE SALE. Direct TCODE SM59 IMG Path IDoc Interface / Application Link Enabling (ALE) -> Communication -> Create RFC Connections

Click on Create button.

Specify all the details in RFC connection screen

Click on Logon Security tab and specify the details.

Click on the Special options tab and specify the details which you want.

Now click on Test Connection button

It show the connection log in next screen

Click on Back Click on Remote Logon Button

Depends upon your settings the destination client will open. If you check the Current user option under Logon/ Security tab, then it will show the screen directly without asking the user name and password details.

Creating RFC ports: Go to TCODE WE21 Select the Transactional RFC in left side tree and click on Create button

In dialog box you can select either Generate port name or own port name. If you select Generate Port name system will generate automatically. Here I selected Own port name. Click on continue.

Specify the description and RFC destination name.

Click on Save.

In Client 900 steps:

Creating table structure: Go to TCODE SE11. Specify table name as ZSTUDENTS. In Delivery and Maintenance tab set attributes as Display Maintenance Allowed The table fields are.

Insert some records in table.

Creating IDOC Segments: Go to TCODE WE31. Specify a name and Click on Create Button.

Here specify all the ZSTUDENTS table fields and their types as shown below.

Click on SAVE button, then it will show dialog box with user name, press continue.

Specify your package name and click on save.

Specify your request and press Continue.

Click on Back button, and then you will see the created segment.

Creating Basic IDOC Type: Go to TCODE WE30 Specify a name to your IDOC and click on create button.

In next dialog box select create new option and specify the description of IDOC and click on continue.

Click on Create segment in the screen.

In dialog box specify the segment name which you created and check mandatory check box.

Click on SAVE and BACK button.

Go to menu EDIT ->Click Set Release

In next dialog box, click on Yes.

Creating Message Type: Go to TCODE WE81. Click on Display / Change button.

Click on New Entries button.

Specify a message type name and Description and click on SAVE button.

Click on Back and Save

Assign Message Type to Basic IDOC Type: Go to TCODE WE82 Click on Display / Change Button

Click on New Entries, Specify the Message Type and Basic IDOC Type and Release version. Click on Save.

Click on Back. Note: Here the Release version you can find in this way Creating Model View and Distributing and Generating Partner profile: Go to TCODE BD64 Click on Display/ Change button

Click on Edit menu -> Model View -> Create

Specify description of model view and technical name in dialog box and press continue.

Select your model view and click on Edit menu -> Add Message type

In dialog box specify the sender, receiver, message type and click on continue.

Now your Model View looks like

Click on Environment Menu -> Generate Partner profile

It will show the following screen, click on execute.

It will show the partner profile log in next screen.

Click on Back button 2 times, it will take back to Distribution Model screen.

Click on Edit Menu -> Model View -> Distribute.

In displayed dialog box select the partner system and click continue

Then it will show the Log of Model View Distribution.

Click on Back button. To check partner profile Go to TCODE WE20 In displayed screen select the partner system in left side tree under Partner Type LS.

Write a Report Program in SE38 to create IDOC control records and transfer it to destination partner system. The following is the program to generate the IDOC control records and process it. *&---------------------------------------------------------------------* *& Report ZSHAN_IDOC_STUD *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZSHAN_IDOC_STUD. TABLES: ZSTUDENTS. DATA : S_CTRL_REC LIKE EDIDC, "Idoc Control Record S_ZSHSTUSEG LIKE ZSHSTUSEG. "CUSTOMER Header Data DATA : T_ZSTUDENTS LIKE ZSTUDENTS OCCURS 0 WITH HEADER LINE. DATA : T_EDIDD LIKE EDIDD OCCURS 0 WITH HEADER LINE. "Data Records DATA : T_COMM_IDOC LIKE EDIDC OCCURS 0 WITH HEADER LINE. "Generated Communication IDOc CONSTANTS :C_ZSHSTUSEG LIKE EDIDD-SEGNAM VALUE 'ZSHSTUSEG'. CONSTANTS: C_IDOCTP LIKE EDIDC-IDOCTP VALUE 'ZSHSTUDIDOCS'. *** Selection Screen

SELECT-OPTIONS : S_STUID FOR ZSTUDENTS-ZSTUID OBLIGATORY. PARAMETERS : C_MESTYP LIKE EDIDC-MESTYP DEFAULT 'ZSHSTUDMT', "Message Type C_RCVPRT LIKE EDIDC-RCVPRT DEFAULT 'LS', "Partner type of receiver C_LOGSYS LIKE EDIDC-RCVPRN DEFAULT 'IT3CLNT800', C_RCVPOR LIKE EDIDC-RCVPOR DEFAULT 'PORTSH800', C_SNDPRN LIKE EDIDC-SNDPRN DEFAULT 'IT3CLNT900', C_SNDPRT LIKE EDIDC-SNDPRT DEFAULT 'LS'. "Destination System ***START-OF-SELECTION START-OF-SELECTION. PERFORM GENERATE_DATA_RECORDS. PERFORM GENERATE_CONTROL_RECORD. PERFORM SEND_IDOC. *&---------------------------------------------------------------------* *& Form GENERATE_DATA_RECORDS *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM GENERATE_DATA_RECORDS . SELECT * FROM ZSTUDENTS INTO TABLE T_ZSTUDENTS WHERE ZSTUID IN S_STUID. IF SY-SUBRC NE 0. MESSAGE E398(00) WITH 'No Students Found'. ENDIF. PERFORM ARRANGE_DATA_RECORDS. ENDFORM. " GENERATE_DATA_RECORDS *&---------------------------------------------------------------------* *& Form GENERATE_CONTROL_RECORD *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* 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 S_CTRL_REC-SNDPRT = C_SNDPRT. "Sender Partner type S_CTRL_REC-SNDPRN = C_SNDPRN. "Sender Partner Number ENDFORM. " GENERATE_CONTROL_RECORD *&---------------------------------------------------------------------* *& Form SEND_IDOC *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM SEND_IDOC . CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE' EXPORTING MASTER_IDOC_CONTROL = S_CTRL_REC * OBJ_TYPE = '' * CHNUM = '' 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 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM ARRANGE_DATA_RECORDS . DATA: W_INDEX1 LIKE SY-TABIX, W_INDEX2 LIKE SY-TABIX. SORT T_ZSTUDENTS BY ZSTUID. LOOP AT T_ZSTUDENTS. S_ZSHSTUSEG-ZSTUID = T_ZSTUDENTS-ZSTUID. S_ZSHSTUSEG-ZSNAME = T_ZSTUDENTS-ZSNAME. T_EDIDD-SEGNAM = C_ZSHSTUSEG. T_EDIDD-SDATA = S_ZSHSTUSEG. APPEND T_EDIDD. CLEAR T_EDIDD. ENDLOOP. ENDFORM. " ARRANGE_DATA_RECORDS Now execute the program, and specify the range of records to transfer

Go to TCODE WE02 to check the generated IDOC control records. Click on Execute

In Client 800 Steps:

Function Module Creation: Create a Function Module to update the table from the IDOC segments Go to SE37 Specify a name and click on create.

In dialog box specify function group and description, and click on save.

Specify the Import parameters in Import tab

Specify the Export parameters in Export tab

Specify the Table parameters in Tables tab

Specify the Exceptions in Exception tab

Click on Source code Tab.

Write the following code in Source code tab. FUNCTION ZSHAN_IDOC_ZSHSTUDMT. *"-------------------------------------------------------------------*"*"Local Interface: *" IMPORTING *" REFERENCE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD *" REFERENCE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC *" EXPORTING *" REFERENCE(WORKFLOW_RESULT) LIKE BDWF_PARAM-RESULT *" REFERENCE(APPLICATION_VARIABLE) LIKE BDWF_PARAM-APPL_VAR *" REFERENCE(IN_UPDATE_TASK) LIKE BDWFAP_PAR-UPDATETASK *" REFERENCE(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 : ZSTUDENTS. DATA : W_ZSHSTUSEG LIKE ZSHSTUSEG. DATA : T_ZSTUDENTS LIKE ZSTUDENTS OCCURS 0 WITH HEADER LINE. WORKFLOW_RESULT = C_WF_RESULT_OK. LOOP AT IDOC_CONTRL. IF IDOC_CONTRL-MESTYP NE 'ZSHSTUDMT'. RAISE WRONG_FUNCTION_CALLED. ENDIF. * Before reading a new entry, clear application buffer

LOOP AT IDOC_DATA WHERE DOCNUM EQ IDOC_CONTRL-DOCNUM. W_ZSHSTUSEG = IDOC_DATA-SDATA. MOVE-CORRESPONDING W_ZSHSTUSEG TO T_ZSTUDENTS. INSERT INTO ZSTUDENTS VALUES T_ZSTUDENTS. ENDLOOP. UPDATE ZSTUDENTS FROM T_ZSTUDENTS. 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_ZSTUDENTS-ZSTUID. 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_ZSTUDENTS-ZSTUID. 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. Click on Save and Activate. Assign FM to Logical Message: Go to TCODE WE57 Click on Display / Change button.

Click on New Entries Button

Specify created FM name, Function Type, Basic Type (IDOC), Message Type, and Direction and click on SAVE button.

Click on Back button. Define Input Method for Inbound Function Module: Go to TCODE BD51 Click on Display / Change button

Click on New Entries

Specify FM name and Input Types as 2. And Click on Save and Back buttons.

Creating Process Code: Go to TCODE WE42 Click on Display / Change Button

Click on New Entries button

Specify a process code name, Description and select the options processing with ALE services, Processing by Function Module.

Click on save button In next screen select the FM name and click on SAVE button and Click on BACK button.

It will take to you previous screen. Double Click on Logical Message in left side tree.

Click on Display / Change button

Click on New Entries button

Specify the Message Type and Click on Save button

Click on Back button

Generating the Partner Profile: Go to TCODE BD64. Select the Model View which you distributed in client 900.

Click on Environment Menu -> Generate Partner Profile

It will show the next screen, in that click on Execute button

It will show the Partner Profile details

To check the partner profile details. Go to TCODE WE20. Select the partner system name.

Transferring the IDOC control records from Client 900 to 800: In source system, go to TCODE SE38. (In client 900) Execute the Report program which you created.

Check in Destination System: (Here client 800) Go to TCODE WE02

Check in ZSTUDENTS table in SE11.

You might also like