Jump to content

IDOC

From Commander4j
Revision as of 21:47, 9 November 2026 by Dgarratt (talk | contribs) (Updated by push_wiki.py)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The IDOC connector reads SAP IDOC flat files and converts them into XML, so that a stylesheet can turn them into another format. It is an input connector only: Middleware4j does not write IDOC files.

How it works

An IDOC flat file is a long run of fixed length segments, each beginning with the segment name. The connector needs to be told which segments and fields you are interested in and where each field sits within its segment. That description is held in a schema file, and one for the SAP material master (MATMAS03) is supplied in idoc/schema.

The sample map Map11 reads a material master IDOC and writes a Commander4j material XML message.

Map configuration

config.xml

<map>
   <id>Map11</id>
   <enabled>true</enabled>
   <description>Idoc Material to XML</description>
   <enableEmailNotifications>true</enableEmailNotifications>
   <connectors>
      <input>
         <id>in1</id>
         <description>Read IDOC</description>
         <type>IDOC</type>
         <url>
            <path>./interface/input/Map11 IDOC to XML</path>
            <mask/>
            <prefix/>
            <pollingInterval>1000</pollingInterval>
         </url>
         <xsl>
            <XSLTPath/>
            <XSLT>Map11_IDOC_to_XML.xsl</XSLT>
         </xsl>
         <idoc>
            <idocSchemaFilename>./idoc/schema/ZMATMAS03c.txt</idocSchemaFilename>
         </idoc>
      </input>
      <output>
         <id>out1</id>
         <enabled>true</enabled>
         <description>Write XML File</description>
         <type>XML</type>
         <url>
            <path>./interface/output/Map11 IDOC to XML</path>
            <prefix/>
            <fileExtension/>
            <use83GUID>false</use83GUID>
            <retainOriginalFilename>false</retainOriginalFilename>
         </url>
      </output>
   </connectors>
</map>
Setting Description
type IDOC
mask Leave empty to pick up files ending in .txt or .idoc.
idoc / idocSchemaFilename The schema file describing the segments and fields to read.

The settings shared by all connectors are described on the Maps page.

The XML produced

Each group of fields becomes a <DATA> element, and each field a <FIELD> element with a name and a value. This is part of the XML produced from the sample IDOC:

<MESSAGE id="150493303" number="./interface/input/Map11 IDOC to XML/IDOC Sample.txt" type="idoc">
   <DATA type="Basic">
      <FIELD name="Material" value="000000000043066649"/>
      <FIELD name="MaterialType" value="HALB"/>
      <FIELD name="BaseUOM" value="EA"/>
      <FIELD name="GrossWeight" value="90.000"/>
      <FIELD name="EANItemCode" value="5000161030149"/>
      ...
   </DATA>
   <DATA type="Additional">
      <FIELD name="RecordType" value="HUTYP"/>
      <FIELD name="Value" value="P53"/>
   </DATA>
   <DATA type="Additional">
      <FIELD name="RecordType" value="STACK"/>
      <FIELD name="Value" value="Y"/>
   </DATA>
   <DATA type="Text">
      <FIELD name="Description" value="SELF SEALING STEM BOLT"/>
      ...
   </DATA>
</MESSAGE>

Points to note when writing the stylesheet:

  • The values are in the value attribute, not in the text of the element.
  • The fields within a <DATA> element are in no particular order. Always select them by name.
  • A segment that repeats in the IDOC, such as a unit of measure or a plant, gives one <DATA> element for each occurrence.

Selecting a single value:

<xsl:variable name="BASE_UOM" select="string(/MESSAGE/DATA[@type='Basic']/FIELD[@name='BaseUOM']/@value)"/>

Selecting a value from the one repeated section that matches a key, here the plant section for a given plant:

<xsl:variable name="PROCUREMENT" select="string(/MESSAGE/DATA[@type='Plant']/FIELD[@name='Plant'][@value=$PLANT]/parent::*/FIELD[@name='SpecialProcessing']/@value)"/>

Both lines are taken from Map11_IDOC_to_XML.xsl, which is the best starting point for a stylesheet of your own.

The schema file

The schema is a text file with one line for each field to be read. Lines beginning with a single quote are comments, and the list of fields starts after a line beginning #START.

' Segment Definition,  IDOC Field,  Field Offset,  Length,  FFMW Section,  New Section,  FFMW Field
'
#START MATMAS03 MM
EDI_DC40,                   ,20  ,9   ,          ,0  ,MessageId
E2MARAM005,     MATNR       ,66  ,18  ,Basic     ,1  ,Material[KEY]
E2MARAM005,     MTART       ,140 ,4   ,          ,0  ,MaterialType
E2MARAM005,     MEINS       ,172 ,3   ,          ,0  ,BaseUOM
E2MAKTM001,     MAKTX       ,66  ,1   ,Text      ,1  ,Language[SUBKEY]
E2MAKTM001,     SPRAS       ,67  ,40  ,          ,0  ,Description
Column Description
Segment Definition The SAP segment name as it appears in the IDOC file.
IDOC Field The SAP field name. For reference only.
Field Offset Position of the field within the segment.
Length Length of the field in characters.
Section The name given to the <DATA type="..."> element. Entered on the first field of each section.
New Section 1 on the line that starts a new section, otherwise 0.
Field The name given to the <FIELD name="..."> element. [KEY] and [SUBKEY] mark the fields that identify a section.

To read a different IDOC type, or extra fields, copy the supplied schema and edit the copy. The offsets and lengths come from the SAP documentation for the segment. The simplest way to check a change is to run a sample IDOC through a map with no stylesheet and read the XML that comes out.

See also: Connectors, Maps, Creating a Map