An common case is, that the IDoc is given as a file. In this case,you have two possibilities for reading the IDoc:

  • Using the FlatFile Adapter
    Use the FlatFile Adapter, if you need to process the IDocs to SAP tables afterwards, e.g. for calling a SAP RFC adapter.
  • Using the FileSystem Adapter
    In all other cases (e.g. if you need to parse the IDoc to a specific structure), it is more convenient to use the FileSystem Adapter to read the IDoc file.

Using the Flat File Adapter to Read an IDoc File

Using the FlatFile Adapter is helpful, if you need to process the IDoc to SAP tables afterwards, e.g. for calling a SAP RFC adapter.

It is very convenient that the Builder provides ready structured IDoc_FlatFile classes. One class IDOC_FlatFile to be used for files containing only one IDoc, one class IDOCs_FlatFile to be used for files containing multiple IDocs.

Reading a Single IDoc and Creating SAP Tables

If the IDoc file contains only a single IDoc, you can easily read the file as shown in the example below.

Figure: Read IDoc File To IDoc_FlatFile Object

After having read the IDoc file, move the IDoc_FlatFile object to a (SAP) Tables object as shown above.

Reading Multiple IDocs and Creating SAP Tables

If the IDoc file contains multiple IDocs,it is a bit more complicated to create the SAP tables. This is because of the different data structure of the flat file and the SAP tables.

Figure: Overview on the Differences Between the Structure of IDOc FlatFiles and SAP Tables

If the IDoc file does not contain the IDoc data according to the structure above but in a different order, it is not possible to use the FlatFile Adapter to read the IDoc file.

Find below an example of reading an IDoc flat file and creating the SAP tables.

  1. Read the IDoc file using the <<FlatFileAdapter>>. You get all IDocs in a structured IDoc file object.
  2. Extract all control records from the IDoc file object. This can be done using an apply statement, because there is only a single control record per IDoc.
  3. Extract all data records from the IDoc file object. Here, you have to use an iteration to get all data records of all IDocs.
  4. Create the SAP tables from the arrays containing the control and data records.

Using the File System Adapter to Read an IDoc File

In all other cases (e.g. if you need to parse the IDoc to a specific structure), it is more convenient to use the File System Adapter to read the IDoc file.

Figure: Read IDoc File with File System Adapter

  1. Read the IDoc file using the <<FileSystemAdapter>>. You get a Blob containing the data of the file.
  2. Transcode this blob to a String. This string then can be input for the <<SAPIDocParser>>.