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

Need all records with high key


IBM Mainframe Forums -> SYNCSORT
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
kalidasvs

New User


Joined: 08 Feb 2018
Posts: 11
Location: US

PostPosted: Fri Feb 09, 2018 10:38 pm
Reply with quote

In my file I have following records:

AAA10
AAA10
AAA10
AAA12
AAA12
AAA11
AAA11
BBB20
BBB20
BBB21
BBB21
BBB22
BBB22

I need the output as follows:

AAA12
AAA12
BBB22
BBB22

What SORT parameters I can use to get the desired output?
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3048
Location: NYC,USA

PostPosted: Fri Feb 09, 2018 11:13 pm
Reply with quote

lol. just use INCLUDE COND = ( "whatever you want")
Back to top
View user's profile Send private message
kalidasvs

New User


Joined: 08 Feb 2018
Posts: 11
Location: US

PostPosted: Sat Feb 10, 2018 12:09 am
Reply with quote

But I have about 70,000 records in my input file. AAA and BBB are 12 digit numbers.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3048
Location: NYC,USA

PostPosted: Sat Feb 10, 2018 1:06 am
Reply with quote

Quote:
But I have about 70,000 records in my input file. AAA and BBB are 12 digit numbers.

Please you need to understand the rules first about what you want exactly.
You need to present the real scenario examples not AAA and BBB or give us piece meal information.

whatever you want as output- tell us how to identify them
or whatever you don't want as output- tell us how to identify them
Back to top
View user's profile Send private message
kalidasvs

New User


Joined: 08 Feb 2018
Posts: 11
Location: US

PostPosted: Sat Feb 10, 2018 2:03 am
Reply with quote

My file has total of 70000 records and record length is about 1000 bytes. Document number is a key field which is 14 digits. The last two digits are usually 00 (two zeros). Each document number could have multiple records. In some situations, there could be an adjustment to the document. In this case the last two digits could be 01, 02 and so on.

So if a document has two adjustments, the document numbers could be as below. I'm showing space preceding the last two digits for display purpose only.

128365290305 00
128365290305 00
128365290305 01
128365290305 01
128365290305 02
128365290305 02

When I use the below Sort, I only get one record for '128365290305 02'. But I need both.

SORT FIELDS=(1,12,CH,D)
SUM FIELDS=NONE

Hope I provided enough details.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2010
Location: USA

PostPosted: Sat Feb 10, 2018 6:08 am
Reply with quote

The first step (as usually!) - you need to understand the logic, or algorithm, or method, or whatever: WHAT AND HOW YOU NEED TO DO TO GET THE DESIRED RESULT.

The second step is, coding the already known algorithm for any desired tool - either SORT utilities, or whatever else.

The computer experts graduated approx. after year 2000 have never heard about the first step. They need some "buttons to click" just to get the result without thinking about it.

* * * * * * * *

Two SORT-related operations are required.

1) Get the list of MAX(adjustment_number) for each unique document_ID
2) Select (via JOIN operation) only those records from the original file with both matching fields of the list created above, e.g. document_ID, and max_adjustment_number

So, step #1 is done.
I suggest the author to complete at least step #2 by himself.
Back to top
View user's profile Send private message
kalidasvs

New User


Joined: 08 Feb 2018
Posts: 11
Location: US

PostPosted: Sat Feb 10, 2018 8:37 am
Reply with quote

Well I started my career with Mainframe in mid-90s but not everyone gets to explore further into some subjects. Thanks for the suggestion to do a join to get the result but I wanted to know if it's achievable through Syncsort. Thanks again.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Sat Feb 10, 2018 3:18 pm
Reply with quote

'Join' is a process within Syncsort.
And if you wanted a Syncsort answer why post in DFsort? (Moving topic).
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2010
Location: USA

PostPosted: Sat Feb 10, 2018 10:22 pm
Reply with quote

kalidasvs wrote:
Well I started my career with Mainframe in mid-90s but not everyone gets to explore further into some subjects. Thanks for the suggestion to do a join to get the result but I wanted to know if it's achievable through Syncsort. Thanks again.

Main point is: designing an algorithm is not related neither to computer platform, nor to specific programming language, nor to particular utility, etc.

It must be a part of design (in simple cases maybe in one's mind only) before any coding begins.
Back to top
View user's profile Send private message
kalidasvs

New User


Joined: 08 Feb 2018
Posts: 11
Location: US

PostPosted: Sat Feb 10, 2018 11:33 pm
Reply with quote

Nic Clouston wrote:
'Join' is a process within Syncsort.
And if you wanted a Syncsort answer why post in DFsort? (Moving topic).


Sure, this topic need to be moved to Syncsort.
Back to top
View user's profile Send private message
kalidasvs

New User


Joined: 08 Feb 2018
Posts: 11
Location: US

PostPosted: Sat Feb 10, 2018 11:38 pm
Reply with quote

sergeyken wrote:
kalidasvs wrote:
Well I started my career with Mainframe in mid-90s but not everyone gets to explore further into some subjects. Thanks for the suggestion to do a join to get the result but I wanted to know if it's achievable through Syncsort. Thanks again.

Main point is: designing an algorithm is not related neither to computer platform, nor to specific programming language, nor to particular utility, etc.

It must be a part of design (in simple cases maybe in one's mind only) before any coding begins.


I have other approach, where I create a VSAM file with document number of highest adjustments. Then a COBOL program extracts the records. This is not for production, but for off side data extract.
Back to top
View user's profile Send private message
kalidasvs

New User


Joined: 08 Feb 2018
Posts: 11
Location: US

PostPosted: Sat Feb 10, 2018 11:39 pm
Reply with quote

I want to thank everyone for your time, I would like to close this thread.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Mon Feb 12, 2018 10:01 pm
Reply with quote

kalidasvs wrote:
have other approach, where I create a VSAM file with document number of highest adjustments. Then a COBOL program extracts the records. This is not for production, but for off side data extract.
I don't have Syncsort. But if you're not concerned about the output order, you could consider something like this (assumed your original sample input data provided in the SORTIN DD).
Code:
//SYSIN     DD *                                             
  SORT FIELDS=(1,5,CH,D)                                     
  OUTREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,5),PUSH=(81:SEQ=8)),
         IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,3),PUSH=(89:SEQ=8)) 
  OUTFIL INCLUDE=(81,8,ZD,EQ,89,8,ZD),BUILD=(1,80)
Back to top
View user's profile Send private message
kalidasvs

New User


Joined: 08 Feb 2018
Posts: 11
Location: US

PostPosted: Mon Feb 12, 2018 10:13 pm
Reply with quote

Arun Raj wrote:
kalidasvs wrote:
have other approach, where I create a VSAM file with document number of highest adjustments. Then a COBOL program extracts the records. This is not for production, but for off side data extract.
I don't have Syncsort. But if you're not concerned about the output order, you could consider something like this (assumed your original sample input).
Code:
//SYSIN     DD *                                             
  SORT FIELDS=(1,5,CH,D)                                     
  OUTREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,5),PUSH=(81:SEQ=8)),
         IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,3),PUSH=(89:SEQ=8)) 
  OUTFIL INCLUDE=(81,8,ZD,EQ,89,8,ZD),BUILD=(1,80)


Thanks, I'll review your solution! I did try one method (suggested in this thread by user sergeyken) which worked on a set of small data. I'm yet to try on full data. Here File-1 is file of unique keys of Document number with highest adjustment. File-2 is the actual file.

//SYSIN DD *
JOINKEYS FILE=F1,FIELDS=(1,8,A)
JOINKEYS FILE=F2,FIELDS=(1,8,A)
REFORMAT FIELDS=(F2:1,20)
SORT FIELDS=COPY
END
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1222
Location: Bamberg, Germany

PostPosted: Tue Feb 20, 2018 12:46 am
Reply with quote

You could just sort by the ID ascending, adjustment descending. When the key ID changes PUSH the record and compare all the other records against the pushed value. Include only equal ones, simple as that.

Using JOIN is more than overkill and with your solution needs an extra step to separate the highest adjustments for each key.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2010
Location: USA

PostPosted: Thu Feb 22, 2018 10:53 pm
Reply with quote

Joerg.Findeisen wrote:
You could just sort by the ID ascending, adjustment descending. When the key ID changes PUSH the record and compare all the other records against the pushed value. Include only equal ones, simple as that.

Using JOIN is more than overkill and with your solution needs an extra step to separate the highest adjustments for each key.

Yes, both solutions (either with PUSH, or with JOIN) use the same logical algorithm implemented in two different ways (and there are more of them). Both types of code have been presented in previous postings.
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 -> SYNCSORT

 


Similar Topics
Topic Forum Replies
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Join multiple records using splice DFSORT/ICETOOL 5
No new posts EZT program to build a flat file with... All Other Mainframe Topics 9
No new posts JCL sortcard to print only the records DFSORT/ICETOOL 11
Search our Forums:

Back to Top