What Are IDocs? Last edited:
IDocs are structured ASCII files (or a virtual equivalent) that adhere to some well-defined conventions. These conventions are known to sender and receiver. IDocs are by no means anything special. They are IDocs Are SAP's physically ASCII data streams like simple simple flat files with Implementation of lines of text where the lines are str!ct!red into data fields. Structured Text Files The typical str!ct!red file has records where each record starts with a leading string which identifies the record type eg. if it is a header record or an item record. The only precondition for an IDoc is that the meaning of e"ery field m!st be recogni#able witho!t interpreting the contents so that the data can be mapped into a database str!ct!re witho!t semantical interpretation of the content. IDocs is the acronym for Interchange for Interchange Document meaning Electronic Interchange Interchange a set of $electronic% information which b!ilds a logical Document entity. &eca!se an IDoc is meant to be exchanged $or interchanged% between two independently existing partners an IDoc m!st adhere to a m!t!ally accepted format or lang!age. An IDoc is eg. all the data of a single c!stomer in yo!r c!stomer master data file. If yo! send data for m!ltiple c!stomer at the same time we shall regard this as sending m!ltiple IDocs. Idoc data is !s!ally exchanged between systems and Data Is Transmitted In ASCII partners who are completely independent. Therefore the Format i!e! "uman data sho!ld be tfransmitted in a format that can easily be #eada$le Form corrected by the h!mans who operate the comp!ters. It is therefore mandatory to post the data in a h!man readable form. 'owadays this means that data is coded in ASCII fomat incl!ding n!mber which are sent as string of fig!res ( to ). S!ch data can easily be read with any text editor on any comp!ter be it a *C +acintosh a ,'ISystem or any internet browser.r
%et A Feeling For IDocs Last edited: For the e!innin! we want to !ive "ou a feelin! of what IDocs are.
IDocs can $e seen as plain ASCII files
eep this in mind: IDocs are basically a small n!mber of records in ASCII format b!ilding altogether a logical entity. In order to sharpen yo!r imagination yo! sho!ld always see an IDoc as a plain ASCII text file. /.g. an IDoc
may contain the data of a p!rchase or sales order resp. or it may contain the data of a material master or of a c!stomer master. See the ill!stration +AT+AS for an example of a material master IDoc or ill!stration 01D/1S for an example of a p!rchase order IDoc. 2e will disc!ss the example of the material master IDoc +AT+AS in the paragraphs below. The contents of s!ch an IDoc is shown in the ill!stration +AT+AS . The definition of the IDoc str!ct!re #AT#AS$% is IDocs are defined in WE& deposited in the data dictionary and can be "iewed with WE30 . Any IDoc consists of two sections "eader record plus man( data the header record •
records ) Idoc
which is always the first line of the file and provides the adminstrative information. The rest of the file is made up by the data records •
which contain the application dependent data, in our example the material master data.
The IDoc "eader #ecord "eader #ecord *ith context information
/ach IDoc is trailed by a header record which pro"ides important information abo!t the context !nder which the IDoc package has been recei"ed. The header record has a fixed pre3defined str!ct!re which is defined in the data dictionary as EDIDC and can "iewed with SE11 in the 145 data dictionary. The header of o!r example will tell !s that the IDoc has been recei"ed from a sender with the name &'C*T%$$ and sent to the system with the name D+,C*T%$$ . It f!rther tells !s that the IDoc is to be interpreted according to the IDoc definition called #AT#AS$% . MATMAS01 ... D!"#$T100 P#+C,-T.. !!!
"eader EDIDC •
Sender
•
#ecei/er
•
IDoc T(pe
The sender6s identification &'C*T%$$ tells the recei"er who sent the IDoc. This ser"es the p! rpose of filtering !nwanted data and gi"es also the opport!nity to process IDocs differently with respect to the sender. The recei"er6s identification D+,C*T%$$ sho!ld be incl!ded in the IDoc header to make s!re that the data has reached the intended recepient. The name of the IDoc type #AT#AS$% is the key information for the IDoc processor. It is !sed to interpret
the data in the IDoc records which otherwise wo!ld be nothing more than a se7!ence of meaningless characters.
The IDoc Data 0ie* 1AT1AS. *ith WE&.
Data and segment info is stored in EDID2
The IDoc type MATMAS01 stands for material master and defines the data str!ct!re of the file. It has been designed to exchange data of the material master. 8o! can "iew the definition of any IDoc data str!ct!re directly within 145 with transaction WE30. The res!lt co!ld look like in the ill!stration. The data records ha"e to match the DDIC str!ct!re EDID4 which yo! can "iew with SE11. They are made !p of two parts. /"ery record hence is led in by a segment info. The remaining part of the record is filled with the act!al IDoc data. These data is stored in the field EDID4SDATA. Segment Info ...E1MARAM .... ...E1MARCM .... ...E1MARDM ....
Segment name tells the data structure
Segment Data 01000000001234567 01000000001234567 01000000001234567
The segment info tells the IDoc processor how the following segment sho!ld be interpreted. +ost of the information in the segment info can be regarded as red!ndant information for e"ent!al non3SA*3compliant partners beca!se this information is also stored in 145s IDoc definition storage. The only interesting information is the name of the segment EDID4-SEGNAM. The segment name EDID4-SEGNAM denominates a corresponding data dictionary str!ct!re with the same name which has been c"reated by transaction WE31 a!tomatically when defining the IDoc segment definition. 8o! wo!ld !s!ally do something like the following: M%! edidd&sdata T% my'se(ment.
Data in EDID23SDATA
Sample coding
Then yo! can access the fields of the IDoc segment EDIDD-SDATA as fields of the str!ct!re my_segment . The following coding sample shows how yo! may read a +AT+AS IDoc and extract the data for the +A1A and +A1C segments to some internal "ariables and tables. DATA) xmara #*+ mara. DATA) tmarc #*+ marc %""-S 0 *T/ /AD- #*$. #%% AT edidd. "AS edidd&se(nam. /$ 1MA-AM.
M%! edidd&sdata T% xmara. /$ 1MA-"M. M%! edidd&sdata T% tmarc. A$D tmarc. $D"AS. $D#%%. now do somethin( with xmara and tmarc.
Contents of an Idoc Pac4age Last edited:
This shall gi/e (ou a feeling ho* an IDoc could loo4 li4e *hen (ou recei/e it as a plain text file! An SA *Doc is always made up out of two lo(ical bloc2s. A "ontrol -ecord An *Doc pac2a(e consist s of one A Table ith The *Doc Data or more records of data in AS"** format and is accomp anied by a control record •
•
Example of of a control record: IDOC Number
Sender
Receiver
0000123456
R3PARIS
R3MUENCHEN
Port FIE
Message Type IDoc Type !RDERS
!RDERS01
Simplified example of an IDoc data array: SegmentType Aufraggeber Warenempfnger Auftrags!ert "ieferdatum Sac#berabeiter !RDERHEADER 10""
10"#
12500$50
24121##"
M%&'( Ma)*
The control record carries all the administrative information of the *Doc, such as its ori(in and its destination and a cata(orial description of the contents and context of the "ontrol record serves attached *Doc data. This is very much li2e the envelope or cover sheet that would accompany any paper document sent via postal mail. as cover slip for the transpo rt
The control record is necessary to find the correct destination of the *Doc and to determine the processin( 34. The control record tells you who sent the *Doc, who is the "ontrol record necess desi(nated receiver and what 2ind of data you will see. ith these three information ary to bits, the SA standard wor2flow facility will determine the 34, to process the *Doc. find its destinat ion and the process in( 34 %nce the *Doc data is handed over to a processin( 34, you will no lon(er need the "ontrol record $ot control record information. The 34s are usually desi(ned in a way, that they are aware $ecess of the individual structure of the *Doc type and the meanin( of the data. *n other words) ary To for every context and syntax of an *Doc, you would write a proper 34 to deal with. roces s *Doc Data
IDoc 5ase 3 Data$ase Ta$les used to store IDocs and related information Last edited:
IDocs are stored in a coule of dataase tales +DI for the data/ control data and the lo! files.
All in$ound and out$ound Docs are stored in
All *Doc, whether sent or received are stored in the table D*D5. The correspondin( control file header (oes into D*D". There are standard pro(rams who read and write the data to and from the *Doc base. These pro(rams and transaction are
EDID2
heavily dependent on the custom6in(, where rules are defined which tell how the *Docs are to be processed.
3or outbound processin(, the custom6in( mainly sets the +ut$ound customi6ing agrees media to transport the data to its receiver, e(. an operatin( system file, automated 3T, 7M# or D*3A"T transmission via ho* data is a bro2er8converter and the internet direct remote function call electronicall( The mean of transport depends on the receivin( partner, the exchanged *Doc type and messa(e type 9context:. So you may determine to send the same data as a file to your vendor and via 3T to your remote plant. Also you may decide to exchan(e purchase data with a vendor via 3T but send payment notes to the same vendor in a file. 3or inbound processin(, the partner profile customi6in( will mainly determine a function module from the function pool, In$ound custom6ing which is written to process an *Doc of the respective type. determines the processing function module %f course, as *Docs are nothin( than structured file data, you could always process it directly with an A4A. This is certainly #ein/enting the *heelI the ;uic2 and dirty solution, bypassin( all the internal chec2 and processin( mechanism. e will not deal here, how to reinvent the wheel, see preamble. To do this customi6in( settin(, chec2 with transaction D* and see the points, dealin( with ports, partner profiles, and all Custom6ing TA7 WEDI under *Doc development.
#in2s to pictures) idocin'visio idoc'out'visio idoc'flow
Some Sample IDocs Last edited: 0ere are some more samles of standard IDocs to !ive "ou a etter imression/ how IDocs are desi!ned..
Chec4 EDID2 *ith SE8
Displa( IDocs *ith WE.9
All IDocs are stored in the IDoc base tables. All recei"ed or send IDocs are stored in the table /DID9 $/DID5 for release 5.x and /DIDD for all releases .x%. Check with the table browser S/;< if there are already IDocs in the table /DID9. 2e will ass!me that there are already some IDocs stored which we can examine. The transaction 2/(= displays the stat!s of all IDocs fo!nd in the system in a more systematic way. Call this transaction fill in proper selection criteria and exec!te the selection. If there are any matching IDocs yo! will recei"e a listing. 2hen yo! click on any line yo! will ha"e a detailed display of the respecti"e IDoc.
1AT1AS. >ere is the display of an IDoc of type +AT+AS(; which we fo!nd in o!r system. 2hen yo! click it open to the f!ll
Content of IDoc file
detail yo! will see something like the following. ??? image of 2/(= 3 +AT+AS(; 3 @@@ +AT+AS(; mirrors widely the str!ct!re of 145s material master if not to say: the IDoc +AT+AS(; is a on e3to3 one copy of the material master entity. A hint by the way: "iew the f!nction mod!le f!nction +AT/1IAL+AI'TAI'DA1. It6s parameters reflect most tables of the material master entity. If this IDoc wo!ld ha"e been written to a file the file content wo!ld ha"e looked like that: MATMAS01 /AD- D!"#$T100 -%"#$T100 -"%-D ...E1MARAM .... ...E1MARCM .... ...E1MARDM ....
8o! can call transaction 2/5( to display the str!ct!re of IDoc structure can $e seen *ith the IDoc type of the fo!nd IDoc WE&.
??? image of 2/5( 3 +AT+AS(; 3 @@@
+#DE#S.
Content of IDoc file
To allow an interference here is a sample of IDoc type 01D/1S(; which is !sed for p!rchase orders and sales orders. *!rchasing and sales share nat!rally the same IDoc type beca!se what is a p!rchase order on sender side will become a sales order on the recei"er side and "ica "ersa. ??? image of 2/(= 3 01D/1S(; 3 @@@ 0ther than +AT+AS(; the IDoc type 01D/1S(; does not reflect the str!ct!re of the order entity neither the one of SD $BA(;% nor the one of ++ $+/;%. The str!ct!re is rather deri"ed from the standard /DIACT. ,nfort!nately this does not make it easier to read. If this IDoc wo!ld ha"e been written to a file the file content wo!ld ha"e looked like that: %-D-S01 /AD- D!"#$T100 -%"#$T100 -"%-D ...E1MARAM .... ...E1MARCM .... ...E1MARDM ....
8o! can call transaction 2/5( to display the str!ct!re of IDoc structure can $e seen *ith the IDoc type of the fo!nd IDoc WE&.
??? image of 2/5( 3 01D/1S(; 3 @@@
Sample Processing #outines
Last edited: Creatin! and rocessin! IDocs are a widel" mechanical task/ as it is true for all interface ro!rammin!. 1e will show a short e2amle that acks SA& '34 SaScrit standard te2t elements into IDocs and stores them ack to te2ts in a second routine. The te2t elements can e edited with S%$.
IDoc o!tbo!nd f!nctions are f!nction mod!les with a standard interface +ut$ound which will read data from an application database and con"ert the data into fun IDoc format. ctio n
In$ound
The interface parameters need to be compatible with a well defined standard beca!se the f!nction mod!le will be called from within another program. IDoc inbo!nd f!nctions are f!nction mod!les with a standard interface which will interpret the recei"ed IDoc data and prepare for processing by fun an application. ctio n
The recei"ed IDoc data is processed record by record and interpreted according the segment information pro"ided with each record. The prepared data can then be processed by an application a f!nction mod!le or a self3written program. The example programs in the following chap ters will show yo! how texts from the text pool can be con"erted into an IDoc and processed by an inbo!nd ro!tine to be stored into another system. The following will gi"e yo! the basics to !nderstand the example. SA* 145 allows the creation of text elements e.g. with transaction S0;(. Text from /ach standard text elements has a header record which is stored in table #E ST->. The text lines itself are stored in a special cl!ster table. To retrie"e AD: the text from the cl!ster yo! will !se the standard f!nction mod!le TE; function READ_TET . 2e will read s!ch a text and pack it into an T IDoc. That is what the following simple f!nction mod!le does. If there is no con"enient ro!tine to process data the easiest way to hand o"er the data to an apllication is to record a transaction with transaction S>D& and create a simple processing f!nction mod!le from that recording.
Sample +ut$ound #outines Last edited: The most difficult work when creatin! outound IDocs i s the retrieval of the alication data which needs to e sent. nce the data is well retrieved/ the data needs to e converted to IDoc format/ onl".
2e will show a short example that packs SA* 145 SapScript standard text elements into IDocs and stores them back to texts in a second ro!tine. The text elements can be
edited with S0;(.
Text from #EAD:TE;T
+ut$ound processing
SA* 145 allows the creation of text elements e.g. with transaction S0;(. /ach standard text elements has a header record which is stored in table ST->. The text lines itself are stored in a special cl!ster table. To retrie"e the text from the cl!ster yo! will !se the standard f!nction mod!le function READ_TET . 2e will read s!ch a text and pack it into an IDoc. That is what the following simple f!nction mod!le does. Check o!t chapters on 1C programming of this cookbook to learn more abo!t the SapScript texts. The program below will retrie"e a text doc!ment from the text pool con"ert the text lines into IDoc format and create the necessary control information.
3$"T*%$ <=&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& <=<=#o2ale Schnittstelle) <= *M%-T*$> <= !A#9*'TD%4?"T: #*+ T/AD&TD%4?"T D3A#T T7T <= !A#9*'TD*D: #*+ T/AD&TD*D D3A#T ST <= !A#9*'TD$AM: #*+ T/AD&TD$AM <= !A#9*'TDS-AS: #*+ T/AD&TDS-AS D3A#T S@A$> <= 7%-T*$> <= !A#9'T/AD: #*+ T/AD ST-"T- T/AD <= TA4#S <= *D%"'DATA ST-"T- D*DD %T*%$A# <= *D%"'"%$T-# ST-"T- D*D" %T*%$A# <= T#*$S ST-"T- T#*$ %T*%$A# <= 7"T*%$S <= 3$"T*%$'$%T'7*ST <= !-S*%$'$%T'3%$D <=&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& < <<< &&& -eadin( the application Data &&& <<<< "A## 3$"T*%$ -AD'T7T 7%-T*$> *D T'/AD&TD*D #A$>A> T'/AD&TDS-AS $AM T'/AD&TD$AM %4?"T T'/AD&TD%4?"T *M%-T*$> /AD 'T/AD TA4#S #*$S T#*$S.
< <<< &&& ac2in( the application data into *Doc M%! 'T/AD T% *D%"'DATA&SDATA. M%! @A77'T/AD T% *D%"'DATA&S>$AM. A$D *D%"'DATA. #%% AT T#*$S. M%! 'T/AD T% *D%"'DATA&SDATA. < <<< && we still need to fill more se(ment info M%! @A77'T#*$ T% *D%"'DATA&S>$AM. A$D *D%"'DATA.
$D#%%.
< <<< &&& ac2in( the *Doc control record &&& <<<< "#A- *D%"'"%$T-#. *D%"'"%$T-#&*D%"T @A77'T7T. < <<< && we still should fill more control record info A$D *D%"'"%$T-#. $D3$"T*%$. #eading data from the application
The first step is reading the data from the application database. In the case of the standard texts this is easily done by calling the f!nction mod!le 1/ADT/-T.
< <<< &&& -eadin( the application Data &&& <<<< "A## 3$"T*%$ -AD'T7T 7%-T*$> *D T'/AD&TD*D #A$>A> T'/AD&TDS-AS $AM T'/AD&TD$AM %4?"T T'/AD&TD%4?"T *M%-T*$> /AD 'T/AD TA4#S #*$S T#*$S.
0!r next d!ty is to pack the data into the Con/erting application data into IDoc format IDoc record. This means mo"ing the application data to the data part of the IDoc record str!ct!re /DIDD and fill the corresponding segment information. < <<< &&& ac2in( the application data into *Doc M%! 'T/AD T% *D%"'DATA&SDATA. < the receiver needs the se(ment name in order to interpret the se(ment M%! @A77'T/AD T% *D%"'DATA&S>$AM. A$D *D%"'DATA. #%% AT T#*$S. M%! 'T/AD T% *D%"'DATA&SDATA. < <<< && we still need to fill more se(ment info M%! @A77'T#*$ T% *D%"'DATA&S>$AM. A$D *D%"'DATA. $D#%%. Filling control record information
inally we ha"e to pro"ide a correctly filled control record for this IDoc. If the IDoc ro!tine is !sed in a standard a!tomated en"ironment it is !s!ally s!fficient to fill the field /DIDC3ID0CT* with the IDoctype and /DIDC3+/ST8* with the context message type and e"ent!ally the recei"er name. The remaining fields are a!tomatically filled by the standard processing ro!tines if necessary.
< <<< &&& ac2in( the *Doc control record &&& <<<< "#A- *D%"'"%$T-#. *D%"'"%$T-#&*D%"T @A77'T7T. < <<< && we still need to fill more control rec info A$D *D%"'"%$T-#.
Sample In$ound #outines Last edited: Inound rocessin! is widel" the reverse rocess of an outound.. The
received IDoc has to e unacked/ interreted and transferred to an alication for further rocessin!. &elow is the example of an inbo!nd f!nction mod!le. This In$ound processing mod!le expects an IDoc with rows of plain text and will sa"e function module this text !nder a gi"en name to SA*6s text database. The proced!re will extract the text name and the text line from the IDoc and hand o"er the text data to the f!nction mod!le 1/ADT/-T which will store the text in the text pool. 3$"T*%$ <=&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& <=<=#o2ale Schnittstelle) <= *M%-T*$> <= !A#9*$T'MT/%D: #*+ 4D3A'A-&*$TMT/D <= !A#9MASS'-%"SS*$>: #*+ 4D3A'A-&MASS'-%" <= 7%-T*$> <= !A#9%-+3#%'-S#T: #*+ 4D3A'A-&-S#T <= !A#9A#*"AT*%$'!A-*A4#: #*+ 4D3A'A-&A#'!A<= !A#9*$'DAT'TAS+: #*+ 4D3A'A-&DATTAS+ <= !A#9"A##'T-A$SA"T*%$'D%$: #*+ 4D3A'A-&"A##T-A$S <= TA4#S <= *D%"'"%$T-# ST-"T- D*D" <= *D%"'DATA ST-"T- D*DD <= *D%"'STATS ST-"T- 4D*D%"STAT <= -T-$'!A-*A4#S ST-"T- 4D3-T!A<= S-*A#*BAT*%$'*$3% ST-"T- 4D*'S<=&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DATA) 7T/AD #*+ T/AD . DATA) T#*$S #*+ T#*$ %""-S 0 *T/ /AD- #*$.
"#A- 7T/AD. -3-S/ T#*$S. < <<< &&& npac2in( the *Doc &&& <<< #%% AT *D%"'DATA. "AS *D%"'DATA&S>$AM. /$ @A77'T/AD. M%! *D%"'DATA&SDATA T% 7T/AD. /$ @A77'T#*$. M%! *D%"'DATA&SDATA T% T#*$S. $D"AS. $D#%%. < <<< &&& "allin( the application to process the received data &&& <<< "A## 3$"T*%$ SA!'T7T 7%-T*$> /AD 7T/AD SA!M%D'D*-"T 7 TA4#S #*$S T#*$S. ADD S@&S4-" T% %+. < fCllen *D%"'Status < fill *D%"'Status *D%"'STATS&D%"$M *D%"'"%$T-#&D%"$M. *D%"'STATS&MS>!1 *D%"'"%$T-#&*D%"T. *D%"'STATS&MS>! 7T/AD. *D%"'STATS&MS>*D EF. *D%"'STATS&MS>$% 000. *3 %+ $ 0. *D%"'STATS&STATS G1. *D%"'STATS&MS>T@ . #S. *D%"'STATS&STATS GE. *D%"'STATS&MS>T@ S. "A##'T-A$SA"T*%$'D%$ 7. $D*3. A$D *D%"'STATS. $D3$"T*%$.
The recei"ed IDoc data is processed record by record and !npacking is a simple discrimination by case according the segment name pro"ided with each record..
< <<< &&& npac2in( the *Doc &&& <<< #%% AT *D%"'DATA.bb "AS *D%"'DATA&S>$AM. /$ @A77'T/AD. -3%-M $A"+'*D%" TA4#S *D%"'DATA S*$> 7T/AD. /$ @A77'T#*$. -3%-M $A"+'TA4 TA4#S *D%"'DATA T#*$S. $D"AS. $D#%%.
2hen the IDoc is !npacked it needs to be passed to the Application processing
application. In o!r case this will be a simple call to a standard f!nction which is going to store the data to the text database. < <<< &&& "allin( the application to process the received data &&& <<< "A## 3$"T*%$ SA!'T7T 7%-T*$> /AD 7T/AD SA!M%D'D*-"T 7 TA4#S #*$S T#*$S. Writing a status log
inally the processing ro!tine needs to pass a stat!s record to the IDoc processor. This stat!s indicates s!ccessf!l or !ns!ccessf!l processing and will be added as a log entry to the table /DIDS.
< fill *D%"'Status *3 %+ $ 0. *D%"'STATS&STATS G1. ... #S. *D%"'STATS&STATS GE. ... $D*3. A$D *D%"'STATS.
The stat!s "al!e 6=;6 indicates a general error d!ring application processing and the stat!s 6=56 indicates e"erything is 0. There are n!mero!s other stat!s "al!es with distinct meanings b!t 6=;6 and 6=56 are the most common ones.
http:44idocs.de4www54cookbooks4idoc4cb;(idoc(5firstlook4