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



JES, JES2, JCL utilities, IDCAMS, Compile & Run JCLs, PROCs etc...

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

Postby vijayakumarvc » Thu Aug 20, 2009 3:50 pm

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
.
.
.
vijayakumarvc
 
Posts: 1
Joined: Thu Aug 20, 2009 3:01 pm
Has thanked: 0 time
Been thanked: 0 time

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

Postby arcvns » Thu Aug 20, 2009 7:26 pm

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)
Arun
User avatar
arcvns
 
Posts: 55
Joined: Sat Feb 28, 2009 12:36 am
Location: India
Has thanked: 0 time
Been thanked: 0 time


Return to JCL

 


  • Related topics
    Replies
    Views
    Last post