Split a file into 3 files upon header and trailer condition



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

Split a file into 3 files upon header and trailer condition

Postby ravitejaintel » Sun Aug 07, 2016 7:30 pm

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
Last edited by Akatsukami on Sun Aug 07, 2016 9:28 pm, edited 1 time in total.
Reason: Coded
ravitejaintel
 
Posts: 4
Joined: Wed Nov 05, 2014 7:24 am
Has thanked: 0 time
Been thanked: 0 time

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

Postby Aki88 » Mon Aug 08, 2016 11:44 am

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.
Aki88
 
Posts: 381
Joined: Tue Jan 28, 2014 1:52 pm
Has thanked: 33 times
Been thanked: 36 times

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

Postby Magesh23586 » Tue Aug 09, 2016 7:11 am

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
Magesh23586
 
Posts: 36
Joined: Sat Jul 05, 2014 5:36 pm
Has thanked: 1 time
Been thanked: 3 times


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post