- File Content Conversion In Sap Pi At Receiver Position
- File Content Conversion In Sap Pi At Receiver System
- File Content Conversion In Sap Pi Receiver
SAP PI/PO provides out-of-the-box functionality to handle file content conversion from Flat file to XML and vice versa in File Adapter. This function can only be used if the file isn’t encrypted. For handling File content conversion along with PGP, we need adapter modules and advanced user detail function. Content conversion in Sender file adapter– 2 new useful parameters When we use the sender file adapter to do a content conversion, the conversion routine assumes that all structures are constant. The number of fields corresponds to the entry in parameter NameA.fieldNames or the number and length of fields in parameter NameA.fieldFixedLengths.
Introduction
This is a basic overview of content conversion using the file adapter.
Scenario
This is a simple asynchronous File to File scenario. A flat file is deposited on a local FTP server; it's read by a Communications Channel, converted to XML, mapped to an inbound XML document and sent back to the FTP server
I'm going to create two Data Types, two Messages Types , two Message Interfaces and a single Interface Mapping. The flat file is being read by a File Adapter so I'll need to configure 'Content Conversion' on the sender communications channel.
Input/Output
The input file contains a list of employees and their previous employers as shown below. Please note that the first two rows are for reference only and won't be included when testing.
The records are grouped by employee, the first record being the header. Each Header Record contains a key, employee number, first name, current employer and phone number. Subsequent rows contain detail records. The detail records hold the employee's previous employers and company locations. The first character is the key field, 'H' for header and 'D' for detail. I've assumed that the records are presented in the correct sequence - one header record, an unlimited number of detail records, followed by another header record and so on.
The records are grouped by employee, the first record being the header. Each Header Record contains a key, employee number, first name, current employer and phone number. Subsequent rows contain detail records. The detail records hold the employee's previous employers and company locations. The first character is the key field, 'H' for header and 'D' for detail. I've assumed that the records are presented in the correct sequence - one header record, an unlimited number of detail records, followed by another header record and so on.
Design
1) The first data type will hold the outbound file (flat file) once it's been received by PI. You need to be aware that the Sender Communications Channel 'Content Conversion' configuration has references to elements within this XML document so they need to be an exact match.
The second data type will contain the inbound file. I've tidied it up a little, the 'key' has been dropped and the prior employers sit underneath the employee record.
2) Create two Message Types.
3) Create an outbound asynchronous Message Interface that references the flat file Message Type and an inbound asynchronous Message Interface that references the XML Message Type.
4). Create a single Interface Mapping and a single Message Mapping. Map as required.
Configuration
1) The following objects are required.
- Sender communications channel
- Sender Agreement
- Receiver Determination
- Interface Determination
- Receiver Agreement
- Receiver Communications Channel
I'm going to focus on the Sender Communication Channel as the rest of the configuration is straightforward. When creating the Communications Channel select 'File Content Conversion' as the message protocol. Configure the File or FTP server details as required and click on the 'Content Conversion' tab.
OK, now we can concentrate on the 'Content Conversion' parameters which are shown below.
OK, now we can concentrate on the 'Content Conversion' parameters which are shown below.
Document...
- Name: The name of the XML structure receiving the document. This is will be the Outbound Message Type.
- Namespace: Namespace of the Outbound Message Type
- Offset: Number of lines to be ignored at the beginning of the document.
Recordset...
- Name: Name of the recordset structure.
- Namespace: Namespace to be appended to the document structure.
- Structure: The name of substructures within the outbound document followed by the number of times the substructures occur. * indicates an unknown number of substructures.
- Sequence: The help documentation is a confusing when describing sequence. I've left this as Ascending on the assumption that the data within the Outbound file is formatted correctly and appears in ascending order. If anyone can provide a detailed explanation of this parameter it would be appreciated.
- Per Message: Number of recordsets that should be included in the message. If this number is exceeded another message is created.
Key
- Field Name: Name of the key field within the file.
- Field Type: I left this as string and didn't see any reason why it should be changed.
![Content Content](/uploads/1/1/9/3/119358998/603744206.png)
Now we can move on to the Recordset parameters. This is the where I tell PI how to locate the substructures, the elements contained within them and the field lengths. Each parameter is prefixed with the name of the element it refers to. All of this has to be typed in so double check everything before you activate the object. As you saw earlier I have two recordset substructures, Header and Detail. The parameters I used are shown below.
- FieldNames - These names correspond to the elements within the outbound XML.
- FieldFixedLengths - The length of each field. It is assumed that each field starts after the previous field.
- KeyFieldValue - The value contained within the key field. In this example the key values are 'H' for header and 'D' for detail.
- ProcessConfiguration - I'm not sure why I used this parameter or where I got it from. If anyone can provide some detail or a link to the appropriate help document it would be appreciated.
The following screen shot shows the relationship between the 'Content Conversion' parameters and the input file.
For example the header row contains 5 elements. Key, EmpID, Name, Company and Phone. The key is indicated by 'H' in column one and will be one character long. EmpID will be eight characters long and starts in column two and so on.
For example the header row contains 5 elements. Key, EmpID, Name, Company and Phone. The key is indicated by 'H' in column one and will be one character long. EmpID will be eight characters long and starts in column two and so on.
This is a small selection of the available recordset parameters. More detailed information can be found on SAP Help. http://help.sap.com/saphelp_nw04/helpdata/en/2c/181077dd7d6b4ea6a8029b20bf7e55/frameset.htm
[]
Testing
Now its just a case of putting the outbound file in the appropriate directory on your FTP server. Make sure the file has the correct filename. In my scenario the Sender Communications Channel checks for files every 60 seconds. Once the file has been read it's archived to another directory. You won't see any content conversion in SXMB_MONI so I assume this is done within the adapter (please correct if I'm wrong).
Summary
This is a very simple way of importing flat files into PI. The only problems I encountered were with the 'Content Conversion' parameters. With a little trial and error I managed to get it working. I'd advise getting yourself a decent text editor as this helped me when designing the content conversion.
Recently went through a question on content conversion for receiver file adapter, where the xml contains multiple header and detail lines. The question is posted here –
Worked on this problem via XSLT which saves the pain for content conversion. Using XSLT, we can convert any xml into csv / other text formats without worrying for XML hierarchy
Structure for this example is as mentioned below –
Output from the interface should be as mentioned below
File Content Conversion In Sap Pi At Receiver Position
Source XML data:
one option is obviously trying via content conversion or message transformation bean which might need some tricks but knowing XSLT gives an edge here.
This requirement can be achieved via a simple XSLT mapping. The idea behind that is that just print the segments we need in the output and pass to the receiver file adapter as it is. In other words, no need to use the content conversion
Here is the XSLT, which would provide us the desired output.
Points to note:
File Content Conversion In Sap Pi At Receiver System
- I have used semicolon (;) as the field separator here. Any other separator can be used.
- If field length is to be shortened, XPath function substring can be used to shorten the fields.
- Similarly spaces can be added using the XPath functions by adding spaces to the fields (Field fixed length type)
- XSLT can also be adjusted in the receiver file adapter but unit testing is as straight forward in that case as in case of XSLT mapping.
Conclusion
File Content Conversion In Sap Pi Receiver
Receiver File content conversion has got an escape route and that is XSLT.
Simple or complex, it is a matter of few lines of code in XSLT, rather than a brainstorming in FCC :).