Page 1 of 1

Split variable length record

PostPosted: Thu Aug 06, 2015 3:45 pm
by GabHof2611
Hallo,

I have a variable length record with following format:

Main (Byte 1 to 80)
Number of Dependents (2 Bytes Packed)
Dependent 1 (30 Bytes)
Dependent 2 (30 Bytes)
..
Dependent N
Tail (50 Bytes after all Dependents)

Output should be 3 files:
File1 Main
File2 all Dependents (1 row for each Dependent)
File3 Tail

Is it possible with DFSORT/ICETOOL?

Thank You.

Re: Split variable length record

PostPosted: Thu Aug 06, 2015 4:10 pm
by BillyBoyo
Yes, with three OUTFILs. As long as you can identify two of the types easily, use the INCLUDE= for the OUTFILs for those two types and SAVE for the third OUTFIL (which will get all records not otherwise processed in an OUTFIL).

Re: Split variable length record

PostPosted: Thu Aug 06, 2015 4:15 pm
by GabHof2611
sorry, I didn't asked correctly.

The variable record looks like this:

Main Dep1 Dep2 ... DepN Tail

Re: Split variable length record

PostPosted: Thu Aug 06, 2015 4:19 pm
by BillyBoyo
What's the maximum number of dependants?

Re: Split variable length record

PostPosted: Thu Aug 06, 2015 4:51 pm
by GabHof2611
maximum number of dependants is 40

Re: Split variable length record

PostPosted: Thu Aug 06, 2015 5:51 pm
by BillyBoyo
OK, three OUTFILs.

The first outputs the first part of each record.

The second contains 40 IFTHEN=(WHEN=(logicalexpressions) testing the value of your count, and uses the slash-operator (/) to output the correct number of records.

The third also contains 40 IFTHEN=(WHEN=(logicalexpressions) also testing the value of your count and outputs the trailer from the correct location.

A variation on that, especially if you have DFSORT 2.1, would be to extend the record to maximum length and then use PARSE, where you can use a repetition. Your trailer-data would exist in two PARSEd fields. You'd still need the 80 IFTHENs to identify which PARSEd fields to use when and for what, but the negative influence of typos would be reduced.

You could look at using ICETOOL's RESIZE, but that would require another pass of the data to make the records fixed-length, then in a USING on the RESIZE you'd have to format each part to the maximum length (80 bytes, your main data). In three OUTFILs in the USING, you'd then do roughly my first suggestion, but you'd not be able to use SAVE as there will always be blank records to ignore completely. You'd need to be able to identify the record-types, so may require the addition of a marker (depending on your data).