File with multiple trailer with record counters



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

File with multiple trailer with record counters

Postby plopoff » Tue Nov 17, 2015 10:51 pm

Hello

I'm trying to code a DFSORT procedure that would merge 2 files into one with the following model :
<header1>
<detail1>
..
<detail1>
<trailer1>
<header2>
<detail2>
..
etc.

The first input file contains every headers and trailers while the second input file only contains the details records.
The records look like that :
Header : 01XXXXXXCCCCCXXXXXXXXX..
Detail : 02XXXXXXCCCCCXXXXXXXXXXXXXX....
Header : 09XXXXXXCCCCC0000000

The X's are random irrelevant characters
The C's represent the key on which both files are sorted
The counter of the trailer is initialy at 0000000

What I've been able to do so far is just a simple sort merging both files using :
//SORT01    EXEC PGM=SORT             
//SYSOUT  DD   SYSOUT=*               
//SORTIN  DD   DISP=SHR,DSN=dsn of input1
//        DD   DISP=SHR,DSN=dsn of input2
//SORTOUT DD   DISP=SHR,DSN=dsn of output
//SYSIN   DD   *                     
 SORT FIELDS=(9,5,CH,A,1,2,CH,A)     
/*

but I then have to manually count the detail records to change the trailer for each header/details/trailer bloc.

So I need your help to add a counter to each trailer, that would reset back to 0 everytime the sorting key changes
The output file should look like this
01XXXXXX12135XXXXXXXXX                       
02XXXXXX12135XXXXXXXXXXXXXXXXXXXXXXX           
09XXXXXX121350000001                               
01XXXXXX13135XXXXXXXXX                       
0200000013135XXXXXXXXXXXXXXXXXXXXXXX             
09XXXXXX131350000001                               
01XXXXXX13335XXXXXXXXX                       
0200000013335XXXXXXXXXXXXXXXXXXXXXXX
0200000013335XXXXXXXXXXXXXXXXXXXXXXX
09XXXXXX133350000002                               
etc.

I tried a few things using Frank Yaeger's documentation but nothing succesful so far.

I'm sorry for any english mistake and/or if my post isn't clear enough, but english is not my first langage :(
Thanks in advance for any help.
plopoff
 
Posts: 3
Joined: Tue Nov 17, 2015 6:23 pm
Has thanked: 1 time
Been thanked: 0 time

Re: File with multiple trailer with record counters

 

Re: File with multiple trailer with record counters

Postby BillyBoyo » Wed Nov 18, 2015 5:17 am

Temporarily extend your records to include a sequence number, and RESTART that on your key (Use INREC, with IFTHEN=(WHEN=INIT). Use IFTHEN=(WHEN=(logicalexpression) to identify the trailer, and by subtracting two (for the header and trailer) from the extended sequence number you will be able to calculate the number of data-records in a header/trailer group, and store the calculated value on the trailer for that group.

If you have a file trailer, do a similar thing with a second sequence number, which is not RESTARTed, and do a similar calculation after identifying the file trailer.

These users thanked the author BillyBoyo for the post:
plopoff (Wed Nov 18, 2015 11:06 pm)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: File with multiple trailer with record counters

Postby plopoff » Wed Nov 18, 2015 10:56 pm

Hello BillyBoyo

Thanks a lot for the idea. I have managed to add a seqnum that reset every time the key changes with the simple code :
OUTFIL BUILD=(1:1,1493, -                               
              SEQNUM,7,ZD,START=1,INCR=1,RESTART=(9,5))

But I'm actually having trouble substracting 2 to the seqnum.
I have reformated the trailer to look like it is supposed to with an INREC IFTHEN :
09XXXXXX113150000008XXXXXXXX...

And i have tried to substract 2 by using this :
OUTREC IFTHEN=(WHEN=(1,2,CH,EQ,C'09'), -
             BUILD=(1:1,13, -           
                    14:14,7,ZD,SUB,+2,TO=ZD,LENGTH=7, - 
                    21:21,1485))

But I am getting the error :
CE126A 2 INCONSISTENT REFORMATTING FOR *OUTREC : REASON CODE 04, IFTHEN 1

So I am guessing syntax error, somewhere in my OUTREC but I couldn't find it.
Hopefully you'll be able to help me one more time.
Thanks again.
plopoff
 
Posts: 3
Joined: Tue Nov 17, 2015 6:23 pm
Has thanked: 1 time
Been thanked: 0 time

Re: File with multiple trailer with record counters

Postby BillyBoyo » Wed Nov 18, 2015 11:02 pm

Are your record variable-length? Can you show the full code that you have? It will be easier to explain that way.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: File with multiple trailer with record counters

Postby plopoff » Wed Nov 18, 2015 11:06 pm

No my record are 1500 char long and not variable.
But nevermind, it was a stupid syntax mistake that I corrected and it acutally works as I want now !

Thanks a lot BillyBoyo, this will probably save me many hours :)
plopoff
 
Posts: 3
Joined: Tue Nov 17, 2015 6:23 pm
Has thanked: 1 time
Been thanked: 0 time


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post