Page 1 of 1

How to Split a file based on the key value of record

PostPosted: Thu Aug 20, 2009 3:50 pm
by vijayakumarvc
I have a file contains Invoice information. Each invoice contains 140 or 150 or more records (not constant).The begining of an invoice can be identified by first two bytes of the record and it is '01' and the rest of the records for that invoice have '02' as the first two bytes.

My requirement is to split this file into 10 files. Write all the records of the first invoice to file1 and all records of the 2nd invoice to file2, etc... in this way all the records for the 11th invoice should go to file1 and so on.

My input file records as below.

01046467490I =====> FIRST INVOICE
02046467490I
02046467490I
02046467490I
02046467490I
.
.
.
02046467490I
01046467491I =====> 2ND INVOICE
02046467491I
.
.
.

Re: How to Split a file based on the key value of record

PostPosted: Thu Aug 20, 2009 7:26 pm
by arcvns
vijayakumarvc,

Welcome to the forums. :)

You can achieve this using the below SyncSort job. I have assumed the input file to be of FB and LRECL to be 80. You can modify the job as per your real file attributes.
//STEP1    EXEC PGM=SORT                                         
//SYSOUT     DD SYSOUT=*                                         
//SORTIN     DD DSN= Input file  --> FB/80                       
//OUT1       DD DSN= Output file1  --> FB/80                     
//OUT2       DD DSN= Output file2  --> FB/80                     
//OUT3       DD DSN= Output file3  --> FB/80                     
//OUT4       DD DSN= Output file4  --> FB/80                     
//OUT5       DD DSN= Output file5  --> FB/80                     
//OUT6       DD DSN= Output file6  --> FB/80                     
//OUT7       DD DSN= Output file7  --> FB/80                     
//OUT8       DD DSN= Output file8  --> FB/80                     
//OUT9       DD DSN= Output file9  --> FB/80                     
//OUT10      DD DSN= Output file10 --> FB/80                     
//SYSIN      DD *                                               
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,2,CH,EQ,C'01'),PUSH=(81:ID=1))
  SORT FIELDS=COPY                                               
  OUTFIL FNAMES=OUT1,INCLUDE=(81,1,ZD,EQ,1),BUILD=(1,80)
  OUTFIL FNAMES=OUT2,INCLUDE=(81,1,ZD,EQ,2),BUILD=(1,80)
  OUTFIL FNAMES=OUT3,INCLUDE=(81,1,ZD,EQ,3),BUILD=(1,80)
  OUTFIL FNAMES=OUT4,INCLUDE=(81,1,ZD,EQ,4),BUILD=(1,80)
  OUTFIL FNAMES=OUT5,INCLUDE=(81,1,ZD,EQ,5),BUILD=(1,80)
  OUTFIL FNAMES=OUT6,INCLUDE=(81,1,ZD,EQ,6),BUILD=(1,80)
  OUTFIL FNAMES=OUT7,INCLUDE=(81,1,ZD,EQ,7),BUILD=(1,80)
  OUTFIL FNAMES=OUT8,INCLUDE=(81,1,ZD,EQ,8),BUILD=(1,80)
  OUTFIL FNAMES=OUT9,INCLUDE=(81,1,ZD,EQ,9),BUILD=(1,80)
  OUTFIL FNAMES=OUT10,SAVE,BUILD=(1,80)