Split a file based on header value



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Split a file based on header value

Postby gunex » Mon Jun 04, 2018 8:37 pm

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
gunex
 
Posts: 2
Joined: Mon Jun 04, 2018 8:34 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Split a file based on header value

Postby Robert Sample » Mon Jun 04, 2018 8:51 pm

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.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Split a file based on header value

Postby enrico-sorichetti » Mon Jun 04, 2018 8:59 pm

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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Split a file based on header value

Postby gunex » Mon Jun 04, 2018 9:00 pm

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.
gunex
 
Posts: 2
Joined: Mon Jun 04, 2018 8:34 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Split a file based on header value

Postby NicC » Mon Jun 04, 2018 9:39 pm

This is now turning into a sort topic. Both COBOL and Sort solutions exist on the forum in the respective areas. Topic locked.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post