Tuesday, May 08, 2012

Optional records in a positional flat file

This days I am working with a file with this structure:

AH Record (Mandatory): File's header, with 14 positions + AH identifier (AH12C0OMMTTD6204)
OD Record (Mandatory): 94 positions + OD identifier
EX Record (Mandatory): 6 positions + EX identifier
MN Record (Mandatory): 12 positions + MN identifier
XR Record (Optional): 4 positions + XR identifier
RF Record (Optional): 17 positions + RF identifier
PT Record (Optional): 2 positions + PT identifier

A sample file could be (all data is in the same line):

AH12C0OMMTTD6204OD9200000002                BUY 0001000.00M0ES0112805025    0000000000000090.000CODIGOCLIENTE5  EX040412MN100001000.00PT00

My first try, was to define a flat file schema with:
  • Records for each structure
  • Tag identifiers
  • Min occurs = 0 in optional records 
But the schema didn't work, because Min occurs = 0 doesn't work as I expected.

After reading this post http://www.codeproject.com/Articles/13707/Flattening-Out-the-Complexity-in-Flat-File-Schemas, I try to put optional records inside a Sequence block, with the same properties, now it works as I expected:

No comments: