Page 1 of 1

Split a file based on header value

PostPosted: Mon Jun 04, 2018 8:37 pm
by gunex
Hi All
I have a huge file with multiple header and trailer. I have another file with only header values.
Now the huge file has to be splitted into two files - one if the header matches and other when the header not matching.
Example given below.

Input File1

HDR AAAA
1232
12455
2XDW2
TRL
HDR BBBB
12321
SER2
242
ASDFA
TRL
HDR CCCC
KDOAE
122
TRL
HDR DDDD
KLIYU
WER3
4368
TRL

INPUT FILE2

AAAA
DDDD

EXPECTED OUTPUTS

OUTPUT1
HDR AAAA
1232
12455
2XDW2
TRL
HDR DDDD
KLIYU
WER3
4368
TRL

OUTPUT2
HDR BBBB
12321
SER2
242
ASDFA
TRL
HDR CCCC
KDOAE
122
TRL

Please advise in acheiving this

Re: Split a file based on header value

PostPosted: Mon Jun 04, 2018 8:51 pm
by Robert Sample
Please advise in acheiving this
Since you posted in the COBOL forum, presumably you want a COBOL solution? Where are you having problems? This is a HELP forum, not a WRITE-THE-CODE-FOR-YOU forum so you need to tell us what code you have, the results you are getting from that code, and where you need help. Assuming the data set (files on z/OS exist on tape and in Unix System Services only) of headers is sorted similarly to the main data set, this is a fairly simple match program (examples of which exist on this forum) with the proviso that the main data set match includes all records through the trailer.

Re: Split a file based on header value

PostPosted: Mon Jun 04, 2018 8:59 pm
by enrico-sorichetti
for a YOUR SORT PRODUCT solution investigate the use of when group to propagate into the detail recordsof the first dataset the header value, and of Joinkeys to match the resulting records with the second dataset

Re: Split a file based on header value

PostPosted: Mon Jun 04, 2018 9:00 pm
by gunex
Hi Robert,
Cobol or SORT anything is fine.
I was trying the SORT option with 'IFTHEN=(WHEN=GROUP' but not sure if we can use a file(INPUT FILE2 as mentioned in the above example) instead of just giving the values. can this be done using sort.

Thanks for your valuable time.

Re: Split a file based on header value

PostPosted: Mon Jun 04, 2018 9:39 pm
by NicC
This is now turning into a sort topic. Both COBOL and Sort solutions exist on the forum in the respective areas. Topic locked.