Tuesday, November 13, 2012

Splitting a Flat-file with multiple records to multiple files with single record.



In BizTalk we can split a flat-file with multiple records to multiple files with single record.
This can be done with Envelope schema or using the below method.

Scenario : 

Suppose we have a input flat-file with multiple records of Purchase Orders of various customers.
Output should be a different file with single Purchase order of the customer.

Solution :

Input File structure:

191,201,44,Sam
192,202,45,John
193,203,46,Jeorge
194,204,47,Kelly
195,205,48,Kristin
196,206,49,Kim


Note : There is an enter at the end of the file.

Source Schema :

Create a source schema with a parent record Root and its child record PurchaseOrder.
Set child delimiter for Root node to 0x0D 0x0A i.e. enter and child order to Postfix.













In the above pic highlighted is the properties that we need to set i.e Group Max occur =1 and Group Min occur =0.

PurchaseOrder record properties :

Set child delimiter for PurchaseOrder node to ',' i.e. comma and child order to Infix.













In the above pic highlighted is the properties that we need to set i.e Max occur =1 and Min occur =0.


Destination Schema :














Map :














Receive Pipeline :














Output Files :














There were 6 records in the input files, hence in there are 6 XML files in the output.

Port Creation\Configuration :

Receive Port & Receive Location- Create a receive port and a receive location after deploying the solution. Select receive pipeline created in the solution on receive location and poll for a specific location using *.txt mask.

Send Port - Create a send port with filter property set to receive port name and in outbound map select the map created in the solution.

How this works :

Setting the Max occur property =1 is responsible for debatching the flat file. When we set Max occur prperty = unbounded, it automatically receive multiple records of the file. In the same manner if we set Max occur =1 schema will only take a single record at a time, mapping will be done for this record and a separate file will be created for this record. Actually all this work is done by the receive pipeline. It will debatch the file while seeing the Max occur property =1 set on the schema.


3 comments:

  1. This is definitely a topic that's close to me so I'm happy that you wrote about it. I'm also happy that you did the subject some justice. Not only do you know a great deal about it, you know how to present in a way that people will want to read more. I'm so happy to know someone like you exists on the web. online property ownership record

    ReplyDelete
  2. What if we need a batch of say 100 records? in that case this will not work.

    ReplyDelete
    Replies
    1. Mady,
      In that case you have to create a custom pipeline component at receive side and make it configurable to achieve 100 records to debatch.

      Delete