Page 1 of 2

Need help with sort

PostPosted: Thu Sep 25, 2014 11:26 am
by Srini1808
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$$$$$$$$$

Re: Need help with sort

PostPosted: Thu Sep 25, 2014 11:46 am
by BillyBoyo
Can there be multiple type 7's per type 6?

Re: Need help with sort

PostPosted: Thu Sep 25, 2014 12:06 pm
by Srini1808
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

Re: Need help with sort

PostPosted: Thu Sep 25, 2014 2:09 pm
by BillyBoyo
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.

Re: Need help with sort

PostPosted: Thu Sep 25, 2014 6:48 pm
by Srini1808
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

Re: Need help with sort

PostPosted: Thu Sep 25, 2014 7:21 pm
by BillyBoyo
Try this. You need a DD name for INA and another for INB, and you specify the same DSN for both.

//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.

Re: Need help with sort

PostPosted: Fri Sep 26, 2014 12:38 am
by Srini1808
Thank you very much Billy,
It seems to be stuck with an error message WER230A reformat field outside the range

Re: Need help with sort

PostPosted: Fri Sep 26, 2014 2:19 am
by BillyBoyo
Can you paste the full sysout from the failed step please?

Re: Need help with sort

PostPosted: Fri Sep 26, 2014 2:47 am
by Srini1808
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

Re: Need help with sort

PostPosted: Fri Sep 26, 2014 3:31 am
by BillyBoyo
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.