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

SORT making groups or sections with limited no. of records


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

New User


Joined: 28 Feb 2007
Posts: 4
Location: chennai

PostPosted: Thu Oct 21, 2010 7:19 pm
Reply with quote

Hi,

Just a glimpse of my requirement.

I have an input file with say 1000+ records.
Layout:
field-A=10 bytes Char (non-unique-key).
field-B=1 byte (an indicator, either H or D, for header/Detail)
Field-C=5 bytes Numeric
There will be only one H record for particular Field-A value

SAMPLE:
AAAAAAAAAAH99999 ====> Header type record
AAAAAAAAAAD88888 => detail record
AAAAAAAAAAD77777 => detail record
AAAAAAAAAAD66666 => detail record
AAAAAAAAAAD55555 => detail record
...................
BBBBBBBBBBH99999
BBBBBBBBBBD88888
BBBBBBBBBBD77777
...............
CCCCCCCCCCH99999
CCCCCCCCCCD88888
CCCCCCCCCCD77777
................


Need to create one single output file grouped by field-A
In output file,
There can be 'n' no. of groups. 'n' is not known / not fixed.
Each group will have :
- 1 to 40 nos. of 'D' type rows &
- 1 'H' type row.
Additionally these 40 rows are the top 40 rows sorted in descending order of field-C.

I think it could be done in sort, using SECTIONS, reports etc.

In the job, One or multiple steps is fine.

If further information is required, I may be able to provide.
Request your kind help.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Thu Oct 21, 2010 10:28 pm
Reply with quote

I can't figure out what you want from your description.

It would help if you would show a better example of your input records and what you expect for output, and explain the rules for getting from input to output using the example. Also, give the RECFM and LRECL of the input file.

You don't need to use 40 rows for your example - just give enough data to show what you want to do. However, if you need to show a lot of input and output data to illustrate what you want to do, feel free to send it to me offline (yaeger@us.ibm.com) as an attached .txt file.
Back to top
View user's profile Send private message
sajusmail

New User


Joined: 28 Feb 2007
Posts: 4
Location: chennai

PostPosted: Thu Oct 21, 2010 11:26 pm
Reply with quote

With due respect to your reply, I would like to stick to the same illustrative example for it exactly represents my need. Please note The above given was a sample sorted 'output' that is required. As u might have noticed it is sorted first on A then B and finally C. The input file is the same but will be in any order also it can contain lot more records. ( not just 41 records having same field-A). 
The sort process does not add or remove any fields. It may remove  rows if there are more than 40 detailed records for any key value in the input.
It is FB & LRECL is 16 here

It is more like control break process, that too with some specific no. of records only required (top 40 values of C here)for one particular set. This is the catch where I am stuck. 
Rather than coding a program for this,( restrictions present) I would look for a sort approach. 
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Thu Oct 21, 2010 11:36 pm
Reply with quote

Quote:
above given was a sample sorted 'output' that is required.


It would have helped if you'd said that in your first post. I thought it was the input.

The approach I would take would be to use GROUP processing to assign sequence numbers for each group (SEQ=n) - then you could use OUTFIL OMIT to remove data records based on the sequence number.

Quote:
The input file is the same but will be in any order


Do you mean in any order of keys by groups with H followed by Ds for a particular key in a group, or something else? It may be clear to you what the input looks like, but it isn't clear to me.

If you need more help with this, show me what the input file might look like for your output example.
Back to top
View user's profile Send private message
sajusmail

New User


Joined: 28 Feb 2007
Posts: 4
Location: chennai

PostPosted: Fri Oct 22, 2010 6:44 am
Reply with quote

Thanks, Frank.
I got your logic by saying that we have to assign seq number for each group, and then removing those rows with seq >41 (in my case).
But, when I thought about it earlier, I was not sure of (still no idea how the code will be) how to assign seq no. to each group .i.e., restarting seq number when we encounter a set with different key.

Could anyone post what the SORT code will look like, if I were to go this way? How to use GROUP processing for assigning seq numbers, with a small example?
Back to top
View user's profile Send private message
sajusmail

New User


Joined: 28 Feb 2007
Posts: 4
Location: chennai

PostPosted: Fri Oct 22, 2010 7:07 pm
Reply with quote

Hi,

I used the below code for desirable results.

Code:
//SYSIN     DD   *                                     
  INREC FIELDS=(1,16,17:SEQNUM,8,ZD,RESTART=(1,10))     
  SORT FIELDS=COPY                                     
  OUTFIL INCLUDE(17,8,ZD,LE,40),OUTREC=(1,16)           
/*                                                     


Appending a seq num from pos:17, and restarting the seq num whenever the value at pos:1 with length 10 changes.
Outfil includes only the rows with seq num <= 40
Seq num is then removed from the end.

Thanks for the guidance.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri Oct 22, 2010 10:56 pm
Reply with quote

sajusmail,

You can do the sort and omit in the same pass. Just set up the sequence numbers in an OUTREC statement after the records are sorted (rather than in an INREC statement before the records are sorted). Something like this:

Code:

    SORT FIELDS=(...)
    OUTREC OVERLAY=(17:SEQNUM,8,ZD,RESTART=(1,10))
    OUTFIL OMIT=(17,8,ZD,GT,40),BUILD=(1,16)
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 How to split large record length file... DFSORT/ICETOOL 10
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 JCL sort card - get first day and las... JCL & VSAM 9
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
Search our Forums:

Back to Top