Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 

Dear All,


After all these days, this is my first blog in SAP community.


Business Requirement


To split a flat file into multiple XMLs in SAP PI, the condition being that the resultant XMLs need to have a predefined count of line items.


Solution


We do have blogs for splitting Flat File into multiple files (without using BPM). In this blog, I will explain the mapping logic involved to split a flat file(contains Header, Line Item & Trailer) into multiple XML files, where each of the target files should be having specific count of line items based on the user requirement.


I am not explaining the entire end to end scenario, but only the mapping section.


Consider the csv file below which has a header, 15 line items (in this case) and a trailer. Assumption is that the target XML file needs to have a maximum of 5 Line Items (this value will be dynamic). Thus, in this case, we need to split the file into 3 XMLs.


INPUT CSV FILE


For the field names, please refer the snap of PI structures.



EXPECTED TARGET XMLs


Here the line item count is 5 per XML



PI Structures


Both the sender and receiver structures will look alike, except those of the key fields in the sender structure. FCC needs to be enabled in sender File channel.



Please make sure that the occurrence of the target message is made 0..unbounded under the signature tab of message mapping.


Also, a parameter needs to be maintained in the signature tab – to indicate the line item count that is to be present in each of the split files.



Mapping Logic


Two UDFs have been used in MM,


Split_Message – To handle the Header and Trailer Records.


Split_Line_Item – To handle the Line Item Records.


Split_Message UDF


This accepts three inputs and produces one output.


Count_Item – This specifies the count of total line items in the Input XML.


Inp_Val – This specifies the corresponding input value (varies with respect to fields)


N – This value comes from parameterized mapping (Parameter: Line_Item_No) -  indicates how many line items to be present in the each of the target XML file.


One Output (Result).



Split_Line_Item UDF


Parameters are similar to above UDF.





Field Mapping


MT_Receiver


As explained earlier, the UDF has three inputs, first one being the count of line items in the source side, second one being a constant [CC] and the third one is the parameter maintained in the mapping signature. The second parameter will be generated at the output based on UDF logic. The context change and occurrence of the UDF result is only concerned here rather than the value. You can use display queue for the results.



Header & Trailer Nodes


The mapping logic is similar for both header and trailer nodes.



Header & Trailer Fields


The mapping for the header and trailer fields are in similar way. The Key in header corresponds to Bank_Name whereas for Trailer, the key is TRL. Only the second parameter to the UDF will change in accordance to the target fields.



Line_Items Node


The mapping logic will differ to generate the Line_Item Node.



Line_Items fields


All the fields of Line_Items are mapped one to one. The Key corresponds to IFSC_Code.



We are done with the mapping. Please complete the end to end design and configuration.



FCC in Sender File Channel



Then place the input file in the source directory and you could see the files split up in the target directory. You can also use the counter option to generate the target files with the sequence numbers as well.



Using this approach, we can split a flat file into any number of XML Files dynamically.



Thanks & Regards


Baskaran

2 Comments
Labels in this area