Greetings!
I have a file in the following format - rec size 94,bytes.first byte is record type. Record type 6 is the main record and record type 7 is the continuation record. All the other record types need to be copied to the output file as it is, but if there is a record type 7 immediately after record type 6, that entire record 7 must be concatenated to position 95 onwards to the previous record. Not all rev type 6 may be followed by rec type 7 as they may not have continuation record. Final output will not contain 7 on the column 1 as they are appended to the previous record. I can write a cobol program, but I was thinking it should be possible using sort. Any suggestion is appreciated! Thanks - Srini
1xxxxxxxxxxxxxxyuuiou
2 utuyuyu uiyuiyui
3ytuyiuiuiuiui
4yuyiyuyuyuyiiuiu
5asdfghjk
6Abcdefpghijkl
7Par stubs
6xxxxxxxxxxx
6qqqqqqqqqq
6tttttttttt
7$$$$$$$$$
Need help with sort
-
- Global moderator
- Posts: 3805
- Joined: Tue Jan 25, 2011 12:02 am
- Skillset: Easytrieve Plus, Cobol, Utilities, that sort of stuff
- Referer: Google
Re: Need help with sort
Can there be multiple type 7's per type 6?
-
- Posts: 8
- Joined: Thu Sep 25, 2014 11:05 am
- Skillset: Cobol, jcl, sort, db2, cics
- Referer: Internet
Re: Need help with sort
Thanks for quick response, no, there will be only one 7 followed by 6, but there may be type 6 with no 7 at all
-
- Global moderator
- Posts: 3805
- Joined: Tue Jan 25, 2011 12:02 am
- Skillset: Easytrieve Plus, Cobol, Utilities, that sort of stuff
- Referer: Google
Re: Need help with sort
Are the records variable-length?
I think the easiest way will be with JOINKEYS, specifying the same input DSN for both JOINKEYS statements. In JNFnCNTL you add a sequence number temporarily, starting from 1 (default) in JNF1CNTL and from 0 in JNF2CNTL. Use the two sequence numbers as the key for the JOINKEYS. This will get you records "matched" with their following record.
The details depend on whether you have F or V records.
I think the easiest way will be with JOINKEYS, specifying the same input DSN for both JOINKEYS statements. In JNFnCNTL you add a sequence number temporarily, starting from 1 (default) in JNF1CNTL and from 0 in JNF2CNTL. Use the two sequence numbers as the key for the JOINKEYS. This will get you records "matched" with their following record.
The details depend on whether you have F or V records.
-
- Posts: 8
- Joined: Thu Sep 25, 2014 11:05 am
- Skillset: Cobol, jcl, sort, db2, cics
- Referer: Internet
Re: Need help with sort
Thanks for the reply! The records are FB. But I am still not sure about the solution! I want only type 6 records to contain record 7 appended to the end, all other type of records must be copied one to one. So, if I had 100 records in the input file of record size 94 and if there are 5 records that belong to to type '7', the output file will have 95 records of record size 188, and few type 6 records will have some data from type 7 records which were moved from the next record. All other types like type 1 thru 5, type 8 and 9 ( as well as those type 6 records which don't have a type 7 records following them) are just copied from input file to position 1-94' with spaces in 95-188
-
- Global moderator
- Posts: 3805
- Joined: Tue Jan 25, 2011 12:02 am
- Skillset: Easytrieve Plus, Cobol, Utilities, that sort of stuff
- Referer: Google
Re: Need help with sort
Try this. You need a DD name for INA and another for INB, and you specify the same DSN for both.
If you look at the output (subject to any typos, this is untested) then on the "left" of each record you will see the "current" record, and on the "right" you will see the "next" record.
You then just need INREC IFTHEN=(WHEN=(logical expression) to OVERLAY 95:88X for those (most) occasions that you do not want to see the data on the right.
Code: Select all
//SYSIN DD *
JOINKEYS FILES=INA,FIELDS=(95,5,A),SORTED,NOSEQCK
JOINKEYS FILES=INB,FIELDS=(95,5,A),SORTED,NOSEQCK
REFORMAT FIELDS=(F1:1,94,F2:100,94)
JOIN UNPAIRED,F1
SORT FIELDS=COPY
//JNF1CNTL DD *
OPTION COPY
INREC OVERLAY=(95:SEQNUM,5,ZD)
//JNF2CNTL DD *
OPTION COPY
INREC OVERLAY=(95:SEQNUM,5,ZD,START=0)
If you look at the output (subject to any typos, this is untested) then on the "left" of each record you will see the "current" record, and on the "right" you will see the "next" record.
You then just need INREC IFTHEN=(WHEN=(logical expression) to OVERLAY 95:88X for those (most) occasions that you do not want to see the data on the right.
-
- Posts: 8
- Joined: Thu Sep 25, 2014 11:05 am
- Skillset: Cobol, jcl, sort, db2, cics
- Referer: Internet
Re: Need help with sort
Thank you very much Billy,
It seems to be stuck with an error message WER230A reformat field outside the range
It seems to be stuck with an error message WER230A reformat field outside the range
-
- Global moderator
- Posts: 3805
- Joined: Tue Jan 25, 2011 12:02 am
- Skillset: Easytrieve Plus, Cobol, Utilities, that sort of stuff
- Referer: Google
Re: Need help with sort
Can you paste the full sysout from the failed step please?
-
- Posts: 8
- Joined: Thu Sep 25, 2014 11:05 am
- Skillset: Cobol, jcl, sort, db2, cics
- Referer: Internet
Re: Need help with sort
Thank you very much Billy!
REFORMAT FIELDS=(F1:1,94,F2:100,94) Should have been REFORMAT FIELDS=(F1:1,94,F2:1,94). And it worked fine. Later I put another sort step to initialize col 95 onwards for all records that died not have 7 in position 95 and only extracted the ones that has values in poisition 1 that is not a 7 and worked perfectly!
Once agin, thank you very much!
Srini
REFORMAT FIELDS=(F1:1,94,F2:100,94) Should have been REFORMAT FIELDS=(F1:1,94,F2:1,94). And it worked fine. Later I put another sort step to initialize col 95 onwards for all records that died not have 7 in position 95 and only extracted the ones that has values in poisition 1 that is not a 7 and worked perfectly!
Once agin, thank you very much!
Srini
-
- Global moderator
- Posts: 3805
- Joined: Tue Jan 25, 2011 12:02 am
- Skillset: Easytrieve Plus, Cobol, Utilities, that sort of stuff
- Referer: Google
Re: Need help with sort
No problem. Good work.
You shouldn't need another sort step to do the final part. A JOINKYES consists of two Sub-Tasks, and the Main Task. The Main Task is exactly like any normal SORT, it just takes as its input the joined REFORMAT records, So you can put the code from your extra step immediately after your REFORMAT statement and be good-to-go in one step.
You shouldn't need another sort step to do the final part. A JOINKYES consists of two Sub-Tasks, and the Main Task. The Main Task is exactly like any normal SORT, it just takes as its input the joined REFORMAT records, So you can put the code from your extra step immediately after your REFORMAT statement and be good-to-go in one step.
-
- Similar Topics
- Replies
- Views
- Last post
-
-
COBOL SORT - How to sort entire file first & sort by Key
by k_ekam » Thu Dec 01, 2022 12:58 pm » in IBM Cobol - 3
- 1551
-
by Robert Sample
View the latest post
Wed Dec 07, 2022 7:32 am
-
-
- 1
- 1773
-
by prino
View the latest post
Tue Jul 02, 2024 2:23 pm
-
- 2
- 1449
-
by willy jensen
View the latest post
Fri Aug 13, 2021 8:11 pm
-
-
How to sum a decimal value using sort
by hkaur7087 » Thu Aug 05, 2021 2:19 pm » in DFSORT/ICETOOL/ICEGENER - 4
- 2352
-
by sergeyken
View the latest post
Thu Aug 05, 2021 7:48 pm
-
-
- 1
- 1575
-
by cobol_dev
View the latest post
Thu Apr 14, 2022 12:55 am