File Content Conversion (FCC) in sender file adapter

Many a times, you are required to read a non XML file into SAP PI. SAP provides an out of the box solution for this, wherein you read the contents of a non XML file, e.g., a text(.txt) file or a comma separated(.csv) file and convert it into standard XML format that PI understands.

Scenario

Let’s imagine a scenario where you are supposed to read a flat file containing employee records. The file is a comma separated (.csv) file containing four columns, namely Employee Name,Employee ID,Employee Address and Employee Phone.1

Here’s how you would do it:

ESR: [Create design objects]

Step 1) Create a data type which reflects the source file structure.screenshot_7

Here, I have created a data type named EmployeeData, which contains 4 fields of type String, which will be used to store data from all the four columns in the file.

Step 2) Create a message type encapsulating the data type you just created. This message type will be used in graphical message mapping (transform source message to target).screenshot_8

Step 3) Create service interfaces. Here, I will be using the same message type to create both outbound and inbound service interfaces for the sake of simplicity. However, real-time scenarios will rarely have this requirement.

a) Outbound interface (represents the structure of the data to be read into PI)screenshot_3

b) Inbound interface: (represents the structure of the data to be used on the target side)screenshot_4

Step 4) Create message mapping, here I have mapped all the fields one-to-one so that we could focus more on the primary objective of this blog, which is File content conversion. Real time scenarios may involve different source and target structures and complex mappings, which will be a topic in future blog posts to come.screenshot_9

Step 5) Create operation mapping, this is the final step in the series of creating design objects. Operation mapping is the object which is called in run time and it refers to the message mapping in turn in order to do the transformation from source to target.screenshot_6

ID: [Create configuration objects]

Step 6) Create sender and receiver business components.screenshot_10screenshot_11

Step 7) Create sender file channel:

a) Enter details of source directory and source file name. Message protocol should be ‘File
Content Conversion’.

screenshot_12

b) In the Content conversion tab, specify the parameters necessary for reading the non XML data into PI as an XML.screenshot_13

Parameters:
Document Name: Name of the XML document. This name is inserted as the main XML tag in the message. (Keep the message type name here)
Document Namespace: Document namespace is added to the XML document along with the Document Name. (Enter the namespace for message type here)
Document Offset: Specify number of lines to be skipped before PI starts reading the data as XML.
Recordset Structure: Specify names and occurrences of the substructures. In this case, the file has only one substructure. The occurrence * represents unbounded occurrences for the Record substructure.

Record.fieldSeparator: This specifies the separator used for distinguishing the end of one field and start of another. (a comma in this case)
Record.endSeparator:  This specifies the end of a Record. (nl or a newline in this case)
Record.fieldNames: Specify the names of the fields in the same order as they appear in the file. These act as XML tags within which the field values are enclosed.
Record.missingLastFields: This property specifies the behavior in case the input file has less fields than specified in the structure. With options:
        Ignore: The XML document only contains the fields which have values.
        add: The XML document contains all the fields, with missing fields having empty tags.
        error: File content conversion is terminated due to missing fields in the file.
Record.additionalLastFields: This property specifies the behavior in case the input file has more fields than specified in the structure. With options:
        Ignore: XML document only contains the fields which are specified in the structure..
        error: File content conversion is terminated due to additional fields in the file.

Step 8) Create receiver file channel:

Here, I have configured the receiver file channel to place the data as it is coming from the mapping run time, hence the channel will place an XML file on the target side. There could be many other possible options, e.g. a SOAP receiver channel sending data to a webservice server or an IDoc receiver channel sending IDocs to an SAP system. However, to focus only on the file content conversion in the sender file channel, I have created a file receiver channel with no manipulation in the data format. (File content conversion on receiver file channel will be covered in another blog post)screenshot_14

Step 9) Create integrated configuration object (ICO):

a) Inbound Processing (Sender file channel)
screenshot_15

b) Receiver determination (Specify the receiver business component)
screenshot_16

c) Receiver Interfaces (Receiver interface name and corresponding operation mapping)
screenshot_17

d) Outbound Processing (Receiver file channel)
screenshot_18

Test:

1) File placed in the source directory.screenshot_19

2) Data read into PI.
screenshot_20

3) File written in the target directory as XML.screenshot_21

4) Data in the resultant file.
screenshot_22


Further Readings:
SAP Help
SAP Wiki


P.s. I will be covering reading a more complex structure using file content conversion in another blog in this series.

One thought on “File Content Conversion (FCC) in sender file adapter

Leave a comment