IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Get maximum value of 2 different fields


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
aditya_gorti

New User


Joined: 21 Dec 2005
Posts: 19

PostPosted: Wed Nov 27, 2013 7:36 pm
Reply with quote

Hi,

I have a file with the following layout

lrecl=22

Input data:

0000000000100000000001
0000000000400000000003
0000000000500000000009
0000000000600000000002

I need the output as:

0000000000100000000001
0000000000400000000002
0000000000500000000003
0000000000600000000009

I need the first 11 to be sorted independently and then the 2 11 bytes independently.

This might be a very silly question.. Can you please help me?

Thanks
Adi
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Nov 27, 2013 8:00 pm
Reply with quote

Hello,

Why is it desirable to swap values between the records?

If you explain just what this is to accomplish, we (i) might be better able to suggest something.
Back to top
View user's profile Send private message
aditya_gorti

New User


Joined: 21 Dec 2005
Posts: 19

PostPosted: Wed Nov 27, 2013 8:04 pm
Reply with quote

The 22 bytes are actually 2 different sets of keys which are combined..
I need to get the max vaue of first key(position 1-11) and also the maximum of 2nd key (position 12-22) to be used further..

I was thinking of icetool to split the keys into separate files and then merging them back.. but was not sure if there was an easier way to do it..
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Wed Nov 27, 2013 8:08 pm
Reply with quote

Add a sequence number before sort -> Step 1
Add a sequence number after sort -> Step 2
Join output of Step 1 & Step 2 based on Sequence number

You would get the desired results
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Nov 27, 2013 9:00 pm
Reply with quote

Hello,

How many pairs of keys will be processed?
Back to top
View user's profile Send private message
aditya_gorti

New User


Joined: 21 Dec 2005
Posts: 19

PostPosted: Wed Nov 27, 2013 9:28 pm
Reply with quote

Only 2 sets of keys. One from the 1st 11 bytes and 1 key from 2nd 11 bytes..
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Nov 27, 2013 9:40 pm
Reply with quote

Hello,

Quote:
Only 2 sets of keys.
Your original post shows 4 sets of keys.

How many will there be "for real"?
Back to top
View user's profile Send private message
aditya_gorti

New User


Joined: 21 Dec 2005
Posts: 19

PostPosted: Wed Nov 27, 2013 10:00 pm
Reply with quote

I am sorry.. there would be close to 1.5 million sets of keys..
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Nov 27, 2013 10:32 pm
Reply with quote

Hello,

Quote:
I am sorry.. there would be close to 1.5 million sets of keys..
Not to worry icon_smile.gif
Might take a couple of iterations, but we get there icon_wink.gif

If all you want is the 2 highest values (regardless of which "other" value), suggest you consider a tiny bit of Easytrieve or COBOL code.
This code would read each record only once and if the incoming value was greater than the previous "highest value", store it. There would be 2 "highest values - left side and right side.

Only 1 pass of the data and no sorting to find the "winners".
Back to top
View user's profile Send private message
aditya_gorti

New User


Joined: 21 Dec 2005
Posts: 19

PostPosted: Thu Nov 28, 2013 12:27 am
Reply with quote

Yupp probably I will just do it in a cobol program..
Thank you! icon_smile.gif
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Thu Nov 28, 2013 12:44 am
Reply with quote

use the following DFSORT JCL which will give you the desired results. The trick here is to use the same file twice but treating the keys differently using JNF1 and JNF2

Code:

//STEP0100 EXEC PGM=SORT                               
//SYSOUT   DD SYSOUT=*                                 
//INA      DD *                                         
0000000000100000000001                                 
0000000000400000000003                                 
0000000000500000000009                                 
0000000000600000000002                                 
//INB      DD *                                         
0000000000100000000001                                 
0000000000400000000003                                 
0000000000500000000009                                 
0000000000600000000002                                 
//SORTOUT  DD SYSOUT=*                                 
//SYSIN    DD *                                         
  JOINKEYS F1=INA,FIELDS=(1,12,A)                       
  JOINKEYS F2=INB,FIELDS=(1,12,A)                       
  REFORMAT FIELDS=(F1:1,12,F2:1,12,?)                   
  JOIN UNPAIRED                                         
  INREC BUILD=(2,11,14,11,X,SEQNUM,8,ZD,RESTART=(25,1))
  SORT FIELDS=(24,8,CH,A),EQUALS                       
  OUTREC IFTHEN=(WHEN=GROUP,RECORDS=2,PUSH=(1,11))     
  OUTFIL OMIT=(12,1,CH,EQ,C' '),BUILD=(1,22)           
//*                                                     
//JNF1CNTL DD *                                         
  INREC BUILD=(C'1',1,11)                               
//*                                                     
//JNF2CNTL DD *                                         
  INREC BUILD=(C'2',12,11)                             
//*
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts SORT ERROR PARAMETER VALUE EXCEEDS M... DFSORT/ICETOOL 12
No new posts Concatenate 2 fields (usage national)... COBOL Programming 2
No new posts Cobol COMP-2 fields getting scrambled... Java & MQSeries 6
No new posts Converting unpacked fields to pack us... SYNCSORT 4
No new posts Data for newly added fields not displ... IMS DB/DC 6
Search our Forums:

Back to Top