I have an input file with say 1000+ records.
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
AAAAAAAAAAH99999 ====> Header type record
AAAAAAAAAAD88888 => detail record
AAAAAAAAAAD77777 => detail record
AAAAAAAAAAD66666 => detail record
AAAAAAAAAAD55555 => detail record
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.
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 (email@example.com) as an attached .txt file.
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.
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?
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: