Page 1 of 1

Split a file into 3 files upon header and trailer condition

PostPosted: Sun Aug 07, 2016 7:30 pm
by ravitejaintel
Hi All,

A file has 3 Set of batches. Each batch can be identified by Header and Trailer. The records between Header and trailer can be dynamic.
So, I want to split this file into 3 files based on Header and Trailer.

In the below example, Header& Trailer are identified by first two characters.
Header Starts with 00
Trailer Starts with 80
Data records Starts with 10

Example:
Input file:

00ABCDEFG
10AGAG
10BCDHE
10DHHE
80TRL
00RTAETG
10GAG
10ADGAGD
80GAGAG
00RTAETG
10GAG
10ADGAGD
10GAGAG
10GAGG
80GAGAG


Expected Output files:

Output file1:

00ABCDEFG
10AGAG
10BCDHE
10DHHE
80TRL


Output file2:

00RTAETG
10GAG
10ADGAGD
80GAGAG


Output file3:

00RTAETG
10GAG
10ADGAGD
10GAGAG
10GAGG
80GAGAG
 

The record format is FB and Length is 80 for all the files.

Please help me on getting this output using any tool like ICETOOL/SORT/FILEAID.

Please let me know if any information to be clear.

Thank you!

Coded

Re: Split a file into 3 files upon header and trailer condit

PostPosted: Mon Aug 08, 2016 11:44 am
by Aki88
Hello,

Multiple ways of achieving this, one of the ways:
1. Use 'INREC IFTHEN=(WHEN=GROUP' to group your data basis the header and tail, use BEGIN and END subcommands of WHEN=GROUP
2. Extend the record by a few bytes, use 'PUSH/ID' to add a unique identifier at the end of each grouped record; this way each group encountered will get a unique number assigned
3. SORT FIELDS=COPY
4. Segregate the data using OUTFIL INCLUDE, testing the unique ID assigned earlier; the number of OUTFIL statements will depend on the number of groups in your input

Hope this helps.

Re: Split a file into 3 files upon header and trailer condit

PostPosted: Tue Aug 09, 2016 7:11 am
by Magesh23586
Assuming LRECL=80 and have only 3 group of records.

//S1 EXEC PGM=SORT  
//SYSOUT DD SYSOUT=*      
//SORTIN DD *            
00ABCDEFG                
10AGAG                    
10BCDHE                  
10DHHE                    
80TRL                    
00RTAETG                  
10GAG                    
10ADGAGD                  
80GAGAG                  
00RTAETG                  
10GAG                    
10ADGAGD                  
10GAGAG                  
10GAGG                    
80GAGAG                  
//OUT1    DD SYSOUT=*                                      
//OUT2    DD SYSOUT=*                                      
//OUT3    DD SYSOUT=*                                      
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,2,CH,EQ,C'00'),
END=(1,2,CH,EQ,C'80'),
PUSH=(81:ID=8))

OUTFIL FNAMES=OUT1,INCLUDE(81,8,ZD,EQ,1),BUILD=(1,80)
OUTFIL FNAMES=OUT2,INCLUDE(81,8,ZD,EQ,2),BUILD=(1,80)
OUTFIL FNAMES=OUT3,SAVE,BUILD=(1,50)
 


Thanks
Magesh