Overlaying value at a particular byte using SORT

In this Mainframe Forum - You can post your queries on DFSORT, ICETOOL , SyncSort & JCL Utilities

Moderators: Frank Yaeger, Moderator Group

goldyroshan
Active Member
Posts: 67
Joined: Thu Apr 05, 2012 1:29 am
Location: WI, USA

Overlaying value at a particular byte using SORT

Post by goldyroshan » Tue May 06, 2014 7:14 pm

Here is the input file :-

Code: Select all

12345 abcd KEY1  
12346 abcd KEY1 
12347 abcd KEY1 
22345 xyzz KEY2  
22346 xyzz KEY2 
22347 xyzz KEY2
Here is the expected file :-

Code: Select all

12345 abcd KEY1 TARGET 
12346 abcd KEY1 
12347 abcd KEY1 
22345 xyzz KEY2 TARGET 
22346 xyzz KEY2 
22347 xyzz KEY2 
Last edited by goldyroshan on Wed May 07, 2014 12:42 am, edited 1 time in total.
Logically yours,
:-) GRS :-)

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Tue May 06, 2014 9:15 pm

The first record already seems to have TARGET on it. If you provide an expected output file, it'll probably be clearer.

Can you not use the bolding, but post instead inside the Code tags so that we can see the spacing.

goldyroshan
Active Member
Posts: 67
Joined: Thu Apr 05, 2012 1:29 am
Location: WI, USA

Post by goldyroshan » Wed May 07, 2014 12:42 am

William - Done. Edited my original post
Logically yours,
:-) GRS :-)

NicC
Active Member
Posts: 650
Joined: Sun Jul 24, 2011 5:27 pm
Location: Down on the pig farm

Post by NicC » Wed May 07, 2014 3:59 am

Are you saying that when column 5 = '5' then you want ' Target' appended to the end of that record (or, at least, at column 17)? Also what is the RECFM and LRECL of the dataset?
Regards
Nic

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Wed May 07, 2014 4:44 am

OK, thanks.

For an up-to-date DFSORT, you want INREC with IFTHEN=(WHEN=GROUP and KEYBEGIN for your key field, and PUSH a SEQ to a temporary extension of the record. The SEQ= must be long enough to cater for the maximum number of records in a group. SEQ=2 gives 99, SEQ=3 gives 999, you get the picture.

After that, you have IFHTEN=(WHEN=(logical expression to test the extened field to see if it is one. If it is, you OVERLAY your C'TARGET'.

Use IFOUTLEN= for your original record-length, so that the extended data does not get beyond INREC.

That's about it.

goldyroshan
Active Member
Posts: 67
Joined: Thu Apr 05, 2012 1:29 am
Location: WI, USA

Post by goldyroshan » Wed May 07, 2014 11:14 am

NicC wrote:Are you saying that when column 5 = '5' then you want ' Target' appended to the end of that record (or, at least, at column 17)? Also what is the RECFM and LRECL of the dataset?
NicC - Nope. Whenever value at position 12 is KEY1, I would want 'TARGET' populated in position 17. It is also important to note that there are other multiple records for the same value of KEY1 - for those other records, I do not want to overlay TARGET at position 17.

RECFM = FB, LRECL = 1200
Logically yours,
:-) GRS :-)

goldyroshan
Active Member
Posts: 67
Joined: Thu Apr 05, 2012 1:29 am
Location: WI, USA

Post by goldyroshan » Wed May 07, 2014 11:15 am

William Collins wrote:OK, thanks.

For an up-to-date DFSORT, you want INREC with IFTHEN=(WHEN=GROUP and KEYBEGIN for your key field, and PUSH a SEQ to a temporary extension of the record. The SEQ= must be long enough to cater for the maximum number of records in a group. SEQ=2 gives 99, SEQ=3 gives 999, you get the picture.

After that, you have IFHTEN=(WHEN=(logical expression to test the extened field to see if it is one. If it is, you OVERLAY your C'TARGET'.

Use IFOUTLEN= for your original record-length, so that the extended data does not get beyond INREC.

That's about it.

William - you gave a lot of info here, I was not able to absorb all of it.
Please give me a SORT JCL for the above, I would be in a better position to relate the above description to it.
TIA!
Logically yours,
:-) GRS :-)

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Wed May 07, 2014 2:07 pm

Take it a step at a time.

Code: Select all

  OPTION COPY
  INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(your key),PUSH=(20:SEQ=2))
If you run that (untested, you'll have to fix any typos) with the sample data you showed and look at what is produced.

You should then notice that the first record in a group has "01" on it. Brilliant. Now it is an easy task. If that value is "01" use OVERLAY to get "TARGET" where you want.

Read up on IFOUTLEN in the manual. It sets the record-length for when all the IFTHEN processing is finished. If you run the above with IFOUTLEN=15 in INREC, you won't see the SEQ that has been added.

NicC
Active Member
Posts: 650
Joined: Sun Jul 24, 2011 5:27 pm
Location: Down on the pig farm

Post by NicC » Wed May 07, 2014 2:27 pm

Whenever value at position 12 is KEY1, I would want 'TARGET' populated in position 17
Then why does

Code: Select all

22345 xyzz KEY2
become

Code: Select all

22345 xyzz KEY2 TARGET
and the other records with KEY1 not have TARGET appended?
Regards
Nic

goldyroshan
Active Member
Posts: 67
Joined: Thu Apr 05, 2012 1:29 am
Location: WI, USA

Post by goldyroshan » Wed May 07, 2014 2:43 pm

KEY1, KEY2, KEY3..........& so on are just unique identifiers for these records (record set).

so for every KEY1 or KEY2 or KEY3 we have multiple records (having the same Key value = KEY1/2/3). For the 1st occurence of this record, we need to have TARGET at 17th position. All other occurences/records of same KEY need not be overlayed with TARGET. We need to do the same for other KEY2, KEY3..so on
Logically yours,
:-) GRS :-)

NicC
Active Member
Posts: 650
Joined: Sun Jul 24, 2011 5:27 pm
Location: Down on the pig farm

Post by NicC » Wed May 07, 2014 3:28 pm

So what you are wanting is: on change of key append 'TARGET' to the first record of the new key. If that understanding is correct then I am beginning to see what William is getting at with his hints.
Regards
Nic

goldyroshan
Active Member
Posts: 67
Joined: Thu Apr 05, 2012 1:29 am
Location: WI, USA

Post by goldyroshan » Wed May 07, 2014 3:47 pm

Yes, you got it right.
So what is the best way to achieve this?
Should I try William's approach?
Logically yours,
:-) GRS :-)

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Wed May 07, 2014 3:54 pm

You mean you haven't already? What was the point of me suggesting anything? You just want to wait for someone to give you the code? Kick back for a long wait. After a few hours waiting, you may as well just try out what I've suggested anyway. Never know, maybe you can do it?

NicC
Active Member
Posts: 650
Joined: Sun Jul 24, 2011 5:27 pm
Location: Down on the pig farm

Post by NicC » Wed May 07, 2014 6:06 pm

Put it this way: William knows a whole lot more about DFSort than I do - my eyes glaze over after about page 2 of the manual!
Regards
Nic

goldyroshan
Active Member
Posts: 67
Joined: Thu Apr 05, 2012 1:29 am
Location: WI, USA

Post by goldyroshan » Wed May 07, 2014 9:48 pm

William - Sorry; I didn't mean to offend you, but I was looking for a simpler way (if any).
I did try out what you had suggested, but I could not get the desired results out of that. I basically could not understand (practically) the effect of having a PUSH.
Will get back to you on this, if needed for this issue.

Therefore, as of now I have adopted an altogether different approach :-

I found out that 1st 2 bytes of every record set (having same KEY1) has a definite pattern, so I used this -

OPTION COPY
INREC IFTHEN=(WHEN=(1,2,CH,EQ,C'12'),OVERLAY=(995:C'TARGET)

so whenever, I have a '12' in first 2 positions, I can overlay the 995th position to TARGET. (yes, 995th position was what I had wanted).

Many Many Thanks to William & NicC.
Logically yours,
:-) GRS :-)

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others