I have a question on using DFSORT/ICETOOL to sort a file which has multiple batches. A batch here means a header record then multiple detail records.
I want to sort the entire file on detail record which will mix the other batch's detail record and when this situation happens, I want to bring the header along with it. Please have a look as explained below:
Here DATA1111, DATA2222, DATA3333 are the header record keys and other records are detail records.
Code:
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+--
Ç OAU 5DPLA9 151 ? ñ &DBFHDC40 z 4 m DPLA9A0 Ô * Ø i
SEGA DATA3333 XXXX ROOT XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
!SDEP Nd !33330S03 XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
!SDEP l° !33330P07 XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
!SDEP l !33330P04 XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
!SDEP k !33330P08 XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
SEGA Ø Ø DATA2222 XXXX ROOT XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
!SDEP n !22220P05 XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
!SDEP m¯ !22220P10 XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
!SDEP Jæ !22220S06 XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
!SDEP J !22220S09 XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
SEGA DATA1111 XXXX ROOT XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
!SDEP L° !11110S02 XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
!SDEP L !11110S01 XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
Here if we see the sort is needed at column 44 (2 bytes), which will sort all the records out of which the detail are sorted on the sequence number. Here we want that the header under which that detail record is present in the input file should be retained on the output. And also, when a detail record gets seperated from its batch then, in the output file the original header for that detail record gets inserted again.
The LRECL is 133 bytes. Its a FB file. Identificationi for a header record is SEGA at 7th byte and for detail record is SDEP at 7th byte.
Please feel free to ask if you have any questions.
1) What you try to call "batch" is called "group" in SORT terminology. Try to use WHEN=GROUP definition in your INREC or OUTREC or OUTFIL statements.
2) From your example is not clear: why the group "3333" consists of 4 detail records on input, but appears reduced to only 2 of those records on output?
1) What you try to call "batch" is called "group" in SORT terminology. Try to use WHEN=GROUP definition in your INREC or OUTREC or OUTFIL statements.
2) From your example is not clear: why the group "3333" consists of 4 detail records on input, but appears reduced to only 2 of those records on output?
Try to describe your requirements more clearly.
Thanks for your reply sergeyken.
The header DATA3333 is having four detail records in the input (03, 04, 07, 08). In the output, it has 4 detail records, but since its sorted on detail records(byte 44,45) the sequence of four detail is breaking i.e. there are other detail records( 05, 06 ) from different header ( DATA2222 ) which is getting inserted in between and due to that, the group for header 3333 is getting split in to two. If you notice, the output has all detail records sorted on byte 44,45. Sorry if thats creating even more confusion. I will look at the solution you suggested now.