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

SORT on detail record, then repeat header with correct batch


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

New User


Joined: 21 Aug 2012
Posts: 13
Location: India

PostPosted: Wed Oct 16, 2024 2:14 pm
Reply with quote

Hi,

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}


The output should look like

Code:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+--
      SEGA                           DATA1111   XXXX ROOT XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     !SDEP                       L  !11110S01   XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
     !SDEP                       L° !11110S02   XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
      SEGA                           DATA3333   XXXX ROOT XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     !SDEP                       Nd !33330S03   XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
     !SDEP                       l  !33330P04   XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
      SEGA                   Ø   Ø   DATA2222   XXXX ROOT XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     !SDEP                       n  !22220P05   XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
     !SDEP                       Jæ !22220S06   XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
      SEGA                           DATA3333   XXXX ROOT XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     !SDEP                       l° !33330P07   XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
     !SDEP                       k  !33330P08   XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
      SEGA                   Ø   Ø   DATA2222   XXXX ROOT XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     !SDEP                       J  !22220S09   XXXX SDEP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {END}
     !SDEP                       m¯ !22220P10   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.

Thanks,
Adi
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2146
Location: USA

PostPosted: Wed Oct 16, 2024 6:01 pm
Reply with quote

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.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2146
Location: USA

PostPosted: Wed Oct 16, 2024 6:50 pm
Reply with quote

Try this example

Code:
//*====================================================================
//SORTGRP  EXEC PGM=ICETOOL                                           
//*                                                                   
//TOOLMSG  DD  SYSOUT=*                                               
//DFMSG    DD  SYSOUT=* 
//*                                             
//*....................................................................
//SYMNAMES DD  *                                                       
GroupID,7,4,CH                                                         
GroupHead,C'SEGA'                                                     
*                                                                     
SortVal,44,2,CH                                                       
*                                                                     
InRecord,1,133,CH                                                     
JoinRecord,*,133,CH                                                   
JoinGroup,*,4,ZD                                                       
*                                                                     
//*....................................................................
//*                                                                   
//SORTIN   DD  DISP=SHR,DSN=input.dataset                                                       
//*                                                                   
//*....................................................................
//TOOLIN   DD  *                                                       
 COPY FROM(SORTIN)    TO(WIDETAB)             USING(GETH)             
 SORT FROM(WIDETAB)   TO(SORTOUT)             USING(CONV)             
//*....................................................................
//GETHCNTL DD  *                                                       
 INREC IFTHEN=(WHEN=GROUP,                                             
               BEGIN=(GroupID,EQ,GroupHead),                           
               PUSH=(JoinRecord:InRecord,                             
                     JoinGroup:ID=4))                                 
//*....................................................................                                               
//WIDETAB  DD  SPACE=(TRK,(100,100))                                     
//*....................................................................
//CONVCNTL DD  *                                                       
 INCLUDE COND=(GroupID,NE,GroupHead)                                   
*                                                                     
 SORT FIELDS=(SortVal,A)                                               
*                                                                     
 OUTFIL REMOVECC,                                                     
        SECTIONS=(JoinGroup,                                           
                  HEADER3=(JoinRecord)),                               
        BUILD=(InRecord)                                               
*                                                                     
//*....................................................................
//SORTOUT  DD  SYSOUT=*                                               
//*....................................................................
//*                                                                   


P.S.
It would be nice if (besides of trying to copy this example) you also tried to find out: how it is organized?
Back to top
View user's profile Send private message
Aditya.Srivastava

New User


Joined: 21 Aug 2012
Posts: 13
Location: India

PostPosted: Wed Oct 16, 2024 9:07 pm
Reply with quote

sergeyken wrote:
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.

Thanks,
Adi
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 Help with SORT - I need to validate d... DFSORT/ICETOOL 7
No new posts MacKinney Batch to CICS upgrade causi... CICS 7
No new posts Run rexx in batch job CLIST & REXX 7
No new posts Excuting store procedure via JCL batch JCL & VSAM 1
No new posts Copy only TEXT or String from a record SYNCSORT 4
Search our Forums:

Back to Top