Vous êtes sur la page 1sur 69

IDOCs

IDOCS

IDOCs

Objective: To understand what is an IDOC. The need for using IDOCs Uses of IDOCs Creating a Custom IDOC Enhancing an existing IDOC Programming Logic for IDOC interface

IDOCs

What is an IDOC ?
The term IDOC stands for Intermediate Document. Its not a process. An IDOC is simply a data container that is used to exchange information between any two processes that can understand the syntax and semantics of the data. An IDOC is created as a result of execution of an outbound ALE or EDI process. In an inbound ALE or EDI process, an IDOC serves as an input to create application document.

IDOCs

IDOCs are independent of sending and receiving system. They can be used for SAP to SAP and SAP to non-SAP process communications as long as the participating processes can understand the syntax and semantics of the data.

IDOCs

IDOCs are independent of the direction of data exchange.An IDOC can be used by an inbound as well as an outbound process. For e.g the ORDERS01 IDOC is used by the purchasing module to send a purchase order and is also used by the sales and distribution module to accept a sales order. This avoids creating redundant IDOC types for the same information.

IDOCs
Asynchronous Document-related

System 1
SAP Document

System 2 IDoc * Document * Transaction * Message

< R/3 System

< EDI subsystem < R/3 System < R/2 System < 3rd party software

Outbound Data Flow

SAP application
Document

Message Control (NAST)


NAST Record Document

IDoc Interface & ALE Services


IDoc

System 2, e.g. EDI subsystem

Inbound Data Flow

System 2, e.g. EDI subsystem


IDoc

IDoc Interface & ALE Services


IDoc + Process

SAP Business Workflow


Document

IDoc + Function Module

SAP application

Advantages of using IDOCs

For e.g Standard IDOC MATMAS01 is used to exchange material master information with the legacy system in version 3.1G. Now the company decides to go in for a version upgrade to 3.1H in which MATMAS01 has been enhanced .You can continue to use the older version and then decide to switch to the enhanced IDOC later.

Advantages of using IDOCs

Ability to create and enhance IDOCs Using the standard tools ( IDOC editor and segment editor ) you can either enhance standard SAP IDOCs or create new IDOCs in the system to support custom interface. The newly developed IDOCs integrate seamlessly into the standard ALE/ EDI interface because they are developed using standard tools provided by the system. They also become available in the standard list of SAP IDOCs and can take advantage of all the tools are designed like IDOC monitoring, error handling and archiving.

Advantages of using IDOCs

Following are the benefits of IDOCs over Flat files. Independence from Applications The biggest advantage of using the IDOC interface is that its an open interface i.e independent of the internal structure used by SAP to store data and independent of sending and receiving applications.

Advantages of using IDOCs

Communication with Back-Level IDOCs The standard IDOCs and the segments within the IDOC have a version associated with them.Each time a standard IDOC or a segment is enhanced, the system assigns it a newer version. Partner applications that were developed using a previous version of the IDOCs are fully supported. SAP can generate and process back-level IDOCs. This version management technology offers backward compatibility.

Advantages of using IDOCs

Custom IDOCs are distinguished from SAP IDOCs by their names, as they start with Z. Standard Monitoring Tools Several tools are available to monitor the state of the system. They range from simple IDOC display to IDOC statistics.

Advantages of using IDOCs

IDOC type Documentation Each IDOC in the system is thoroughly documented .The usage is detailed down to the field level with possible values for each field and how it affects the process. The documentation of any IDOC can be obtained using transaction WE60. Archiving Tools Tools are available for miscellaneous tasks such as archiving , data cleanup and restoring information back into SAP.

Use of IDOCs

EDI integration EDI is electronic exchange of business documents between SAP and non-SAP systems.Several applications ( purchasing, sales or shipping ) in SAP are enabled for EDI. To use EDI first the application document viz.. purchase order is created. EDI interface layer converts the application document into an IDOC which is transferred to an EDI subsystem.The EDI subsystem translates the IDOC into an industry-standard format and then transfers it to a business partner over a network.

Use of IDOCs

ALE Integration ALE (Application Link Enabling) enables the exchange of data between two SAP systems.This system allows SAP business processes and applications to be distributed across multiple SAP systems.ALE ensures integration in a distributed SAP environment.

Use of IDOCs

OCR Application integration OCR( Optical Character Recognition ) is a technology that scans and interprets printed matter using pattern recognition. You can integrate an OCR application with SAP via IDOCs. Documents in a standard format can be scanned to generate IDOCs, which then can be transferred to the SAP system for processing. ICR Application integration Bar-code system is an example ICR ( Intelligent Character Recognition ) technology. Data encoded using bar-codes can be captured and stored as an IDOC, which then can be passed to SAP for further processing.

Comparing Flat File Structure to IDOC Structure

Comparison
The best way to explain the IDOC architecture is to compare your legacy world to how SAP implements the same concept in IDOC lingo.

Lname(10)

Fname(10)

SSN(11)

DOB(8)

Employee header occurs once mandatory

Week no(1) Hrs worked(3) Total hrs(3) Total amount(10)

Hrly rate(3)

Client site(20) Work des.(50) Weekly details multiple

Summary once

Assume that you have an application that records an employees weekly hours .At the end of the month, a file containing the monthly report data for each is sent to external system. This application has been replaced by the SAP system ,and a standard IDOC has been developed to support the process.

Comparison

Following are some properties of the file: It has three types of records: employee header information, weekly details and monthly summaries. Each record type has certain properties ,such as whether its optional or mandatory, number of times it can be repeated, field names, data type for each field, and length of each field. The client site and work description in the weekly details is not always available.

IDOC version of the flat file

ZMREPT01
Lname

Segments
Fname SSN Dob

Z1EMHDR (M,1,1) Z1WKDET (O,1,99999) Z1CLDET (O,1,1) Z1SUMRY (O,1,1)


Tot hrs Tot amount Week no Hrly Rate Tot Hrs

Clsite

Work desc.

Comparison

Smith 1 2 3 4

John 30 30 30 50

123-45-6789 102668 40 Houston Brewery 40 Network Computers 50 Network Computers 60 DSP Systems

Beer Testing High Level Consulting Programming EDI Programming

140

6900

An example of the monthly report file for one particular employee

IDOC Definition Components


Name: A basic IDOC type can be assigned up to a thirty-character name in release 4.0 onwards. To encompass all releases we have used an 8 character name ZMREPT01. Custom IDOC types always start with Z the last two character represents the version number.After a basic IDOC type is released and you move to a newer version of the SAP system, any changes to the structure of the basic IDOC type will create a new basic IDOC type i.e the version number is incremented by 1. Thus ZMREPT02 represents an enhanced version of this IDOC. Segments of a previous version are never deleted. This is necessary to maintain backward compatibility.

IDOC Definition Components

List of permitted segments: These segments make up the IDOC structure. The current example has four segments: Z1EMHDR, Z1WKDET , Z1CLDET and Z1SUMRY. Arrangement of segments: Arrangement specifies the physical sequence and any parentchild relationship in the segments. A parent-child relationship signifies that the child segment cannot exist without the parent and is commonly used for text segments. It gives an IDOC type a hierarchical structure.

IDOC Definition Components

Mandatory versus Optional segments: When used in an IDOC type,each segment has an attribute that defines whether the segment is optional or mandatory. In the example given, Z1EMHDR is a mandatory segment because the monthly report will not make sense without the employees basic information.

IDOC Definition Components

Minimum / Maximum range for each segment: Each segment has an attribute that defines the minimum and the maximum number of times a data record corresponding to a segment can exist in an IDOC. In the example given, data records corresponding to the Z1WKDET segment can occur multiple times.

IDOC Definition Components

SEGMENTS A segment defines the format and structure of a data record. Segments are reusable components, which means they can be used in more than one IDOC type. A segment consists of various fields that represent data in a data record.

IDOC Definition Components

Segment Components A segment in the SAP system is technically implemented as three physically separate pieces. Segment type This is version independent name of the segment. SAP provided segment types begin with E1, whereas custom-defined segment types begin with Z1. In the example Z1EMPHDR and Z1WKDET are segment types.

IDOC Definition Components


Segment definition This is version dependent definition of a segment where you specify the fields that belong to the segment. SAP segment definitions start with E2, whereas customer segment definitions start with Z2. The name of a segment definition is 10 characters long and is automatically assigned by the system from the name of the segment type. For e.g for the segment type E1EDKA1, the segment definition is E2EDKA1. The last three characters represent the version of the segment. The first segment definition has spaces in last three characters. The last three characters are incremented by 1 to reflect the new definition.

IDOC Definition Components


Segment definitions Z2TEST Z2TEST001 Z2TEST002

Field 1 Field 2 Field 3 Field 4

Field 1 Field 2 Field 3 Field 4 Field 5

Field 1 Field 2 Field 3 Field 4 Field 5 Field 6

IDOC Definition Components

3) Segment Documentation This represents the data dictionary documentation for each field in the segment definition.Segment documentation of SAP-provided segments begins with E3, whereas the segment documentation of customer-defined segment types with Z3. There is only one segment documentation per segment.

IDOC Run-Time Components

Although there are several records in an IDOC, they are still classified as one of the three record type. Control Record Data Record Status Record At run time the following events occur:A unique IDOC number is allocated. One control record is attached to the IDOC. Segments translate into data records. Status records are attached. Syntax rules are checked.

IDOC Run-Time Components

Control Record

IDoc-ID Sender-ID Receiver-ID IDoc type and logical message External structure IDoc-ID Sequence/Hierarchy Segment Format definition for
header data item data

Data Record

Status Record

IDoc-ID Status information

IDOC Run-Time Components

Transaction WE02 0r WE05 ( IDOC Display )

IDOC Run-Time Components


Control Record As the name suggests contains all of the control information about an IDOC, this basically includes IDOC number, sender and receiver information such as the message type it represents and the IDOC type. A control record can be compared to an envelope of a letter, by looking at the envelope,you can identify the sender and the recipient. It has following characteristics There is one and only one control record per IDOC. The structure of the control record is the same for all Idocs and is defined by SAP. It is stored in EDIDC table

IDOC Run-Time Components

Control Record as viewed by IDOC display tool

IDOC Run-Time Components

Data Records In an IDOC, data records contain the application data.The employee header information,weekly details,client details and summary information reside in data records. A data record has two parts: an administrative section and a data section. Administrative section contains the segment name, segment number and hierarchy level. Data section is where the actual data resides. This is mapped to a segment type. Data records are stored in the EDID2 table. The complete documentation of the data record can be viewed by using transaction WE61.

IDOC Run-Time Components


Status Record These are attached to an IDOC throughout the process as the IDOC achieves different milestones. At every milestone a status code,date and time are assigned. The latest status code is also maintained in the control record. Status records have following characteristics: Multiple status records are usually attached to an IDOC. In outbound processes, after the IDOC is passed from SAP to the subsystem,the subsystem generates the status records and passes them to SAP. For inbound processes,SAP generates the status records.

List of status code and there details can be seen by executing transaction WE47.

IDOC Run-Time Components

Details of a status code WE47

Extending / Creating an IDOC

Extending IDOCS You extend a basic IDOC type when it meets most of your requirements. You have extended the SAP screens to include custom field,such as in the material master and customer master.The master data is to be distributed across several SAP systems using ALE.This situation is a perfect candidate and obvious choice for IDOC extension. Your business partner sends you additional information or expects additional information on an EDI document.This again should be taken as a case of IDOC extension.

Extending / Creating an IDOC

Advantages of Extensions

The standard code of processing is still in use. Developments and corrections of standard code are available automatically. Extensions are much less effort than developments.

Extending / Creating an IDOC Creating IDOCS You create a new basic IDOC type when the standard basic IDOC types do not meet your business needs as is or by extending them. You want to synchronize master data between two SAP systems,and this master data s not supported in the standard system. New basic IDOC types are developed especially for interface to legacy systems or third-party products using ALE.Data to be exchanged with Legacy system is usually in a proprietary format and does not map one to one with a standard SAP business process.

Creating a New IDOC type


Design guidelines to be followed during the creation of an IDOC Develop an IDOC type for a function,not for a specific application. For example,the ORDERS02 IDOC is designed for the order process and not specifically for the sales order entry applications. This IDOC is used for several documents such as purchase order, sales order, order response and order change. Organize the document to contain header information,detail information and summary information. Do not repeat a segment type in an IDOC definition. For example, consider the monthly report IDOC type ZMREPT01, if it was asked to add client information to the summary as well, our instinct would be to attach the Z1CLDET segment to summary segment Z1SUMRY.SAP does not permit placing a segment type more than once in an IDOC definition.

Creating a New IDOC type


Use the parent-child relationship when you are going to permit several entries of the same type in one IDOC. Avoid having too many mandatory segments.Having extra mandatory segments reduces the reusability of the IDOC. For example in monthly report IDOC,the weekly details segment seems to be mandatory.Consider another process that could make use of this IDOC to send just employee header information and summary information.If the weekly segment were mandatory, then the IDOC would not be reusable in that way. Create segments that can be reused by other IDOCs. Do not make segments larger then 1,000 bytes. Try to split the segments into functionally separate segments when a segment definition exceeds 1,000 bytes.

Creating a New IDOC type

Steps for creating a Basic IDOC type


Step 1: Data analysis Step2: Create Data Elements Step3: Create Segments Step4: Create Basic IDOC type Sep5: Release the segment type and Basic IDOC type Step6: Transport Segments and Basic IDOC types

Data Analysis
In this stage you analyze data that needs to be exchanged between the two processes.Develop the conceptual picture of the IDOC on a piece of paper. Follow a top-down approach if you are starting a businessdocument level.Break the documents into segments and group the segments that belong together into a segment group.Identify fields in a segment and their data type.Identify any parent-child relationships. Follow a bottom-up approach if you are starting at the field level. You have been given a docment that contain various values that must be exchanged between two segments. Group the fields that are functionally related into segment.Group those segments in a segment group and arrange them in an IDOC type.Identify any parent-child relationship.

Create Data Elements


The need to create new data elements is minimal because if you are extracting data from SAP to put into an IDOC, the data already exists in the database and is represented by a data element. You need to create new data elements in following cases: A data element in SAP does not use one of the allowed data types for IDOC segments. Here is a list of allowed data types: 1> CHAR 2> CLNT 3> CUKY 4> DATS 5> LANG 6> NUMC 7> TIMS Character Strings Client Currency key Date field ( YYYYMMDD ) stored as char(8) Language key Character fields with only digits Time field ( HHMMSS) stored as char(6)

Create Data Elements

A field in SAP is smaller in length than the industry standard ( this occurrence is rare ). Create data elements as already covered in Data workbench section.

Create Segments
Segments are created by using Segment Editor tool.This can be started by executing the transaction WE31. Follow these steps to create a segment: 1) Execute transaction WE31.Enter the name for your segment type ( it must start with Z1 ) and click on create icon. The system prompts you with the name of the development class it uses for the segment. But you can override the default value. 2) Enter the values in the various fields.You are now maintaining the first segment definition.The system automatically assigns a name to the segment definition based on segment type. 3) Save your values and generate the segment definition.Once you save your segment return to the previous screen and enter a description for your segment type.Click on save and you are done.

Create Segments

WE31 to create Segments

Create Segments

Create Basic IDOC type


Once you have developed all the needed segment types you are ready to create the basic IDOC type.You use IDOC editor transaction WE30. Follow these steps to create a basic IDOC type: Execute transaction WE30,enter name for your basic IDOC type (it must start with Z ),select Basic IDOC type button and click Create icon. On the next screen,select the create New option and enter a description.Press Enter. Click on the IDOC name and click on the create icon.The system prompts you to enter a segment type and its attributes. Choose appropriate values and press Enter.The system transfers name of segment type to IDOC editor.

Create Basic IDOC type

WE30 to create Basic IDOC types

Create Basic IDOC type

Create Basic IDOC type


4) To add additional segments, click on the segment created in step 3 and repeat the procedure described in step 3. Note that after you create the first segment, the system prompts you for the level ( same level or child ) at which you want to create the next new segment.

5> Save your basic IDOC type.

Release the Segment type and Basic IDOC type


When you are satisfied with your IDOC structure and segments, you can release them formally to signify their completion and make them available for transport to test and production systems. First you release the segments,and then you release the basic IDOC types. To release a segment,execute WE31,enter segment type and choose Goto, Release. The system enables a check box in the segment definitions block. You can select the check box and save your entry. To release a basic IDOC type,execute transaction WE30. Enter the basic IDOC type in the Obj.Name field and choose Extras, Release Type.Confirm the entry,and basic IDOC type is released. This step prevents further modification to basic IDOC type

Release the Segment type and Basic IDOC type

Release Segment type

Release the Segment type and Basic IDOC type

Release Basic IDOC type

Transport Segments and Basic IDOC types

Changes to basic IDOC type and segments are automatically recorded in a change request.After you transport the objects, you can also manually retransport them from the segment editor and IDOC editor screens by choosing Segment, Transport and Development Object,Transport respectively. Transporting a segment, transports all the segment definitions and documentation, but transporting an IDOC does not automatically transport all the segments. Note:If you release a basic IDOC type without releasing its segments and then, by transporting the basic IDOC type,the segments are not transported.

Extending a Basic IDOC type


To extend a basic IDOC type,you also need to understand what is permitted and what is not.The concept of extending a basic IDOC type means adding one or more custom segments to one or more existing SAP segments of a basic IDOC type. The formal procedure of extending a basic IDOC type is as follows: 1) Start with data analysis.Identify a segment in the basic IDOC type that needs to be extended. 2) Create a custom segment with your fields. 3) Create an IDOC extension that ties the custom segment to the SAP segment which is to be extended. 4) Tie the extension to a basic IDOC type to create an IDOC type.

Extending a Basic IDOC type


Assume that you have extended the customer master screen to include additional sales data information about your customer. This includes two custom fields delivery priority and customer ranking.In order to distribute customer master data between two SAP systems, you need to also distribute information in the two custom fields. The basic IDOC type for customer master is DEBMAS01. Step 1: Data Analysis In this step you analyze the basic IDOC type and identify segments that need to be extended.In this example standard SAP segment E1KNVVM contains the sales data information and Z1KNVVM is a custom segment that contains userdefined fields. Thus DEBMAS01 is extended by extending the E1KNVVM segment. The segment to be extended is called reference segment.

Extending a Basic IDOC type


Step 2: Create Custom Segments In this step you create the custom segment Z1KNVVM. This segment contains two fields and required data elements: ZZDELPRTY ( Delivery priority ) and ZZRANK ( Customer Rank ). Step 3: Create an IDOC extension You use the IDOC editor transaction WE30 to create an IDOC extension. (a)Enter the name for your IDOC extension in the Obj.Name field. This entry can be any meaningful name and does not have to start with Z. Click on Extension type radio button and then on Create icon. (b)On the next screen, click on the create New button and enter a description for your extension and linked basic type. Press Enter.

Extending a Basic IDOC type

Create an IDOC extension

Extending a Basic IDOC type


(c) Select the extension type E1KNVVM and say Create.The system informs you that the segment is added as a child segment. Confirm the entry and the system prompts you with a dialog box to enter the name of the custom segment and various attributes such as maximum number and mandatory versus optional.Enter the appropriate values and press Enter.

Specify attributes of custom segment

Extending a Basic IDOC type

(d) Save your extension.The system my prompt you for a change request if the changes to Repository Objects option is turned on.

Extending a Basic IDOC type

Programming in IDOC Interface


The programming tasks in the IDOC interface can be categorized as follow: Program for custom IDOCs These programs are specifically written for new basic IDOC types developed for your process. A separate program is written for outbound process and inbound process. Programs for IDOC extensions These programs are written specifically for extended IDOCs. Standard user exits are available in the outbound and inbound IDOC process for populating data and reading data in the extended segments. Program to enhance the process These programs are written to enhance the process flow for existing IDOCs and add custom checks to the IDOC interface.

Programming in IDOC Interface


IDOC generation Program for custom IDOC with Selection Screen The program logic contains the following blocks: Provide a selection screen to allow a user to specify the various objects for which IDOCs are to be generated. Determine the key of the application document from the object specified in step 1. Select application data from the database using the object key identified in step 2. Populate control record information. Populate an internal table of type EDIDD with data records for various segments. Call the ALE service layer( MASTER_IDOC_DISTRIBUTE) to create the IDOCs in the database. Commit work.

Programming in IDOC Interface


Inbound Program for Custom Basic IDOC types The program logic contains the following blocks: 1. Read control record information. Verify control information (message type). If the message type is incorrect, then raise the exception. 2. Read the IDOC data for an IDOC. 3. Parse through each data record. If using the call transaction,then build the BDC data table;if not, build internal tables. 4. Call the posting program and capture the results. 5. Populate return parameters. 6. Return from the function module.The results of execution are passed o the ALE layer.

Vous aimerez peut-être aussi