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

To Sort detail records in a file with Multiple Hdr and Trl


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

New User


Joined: 25 Nov 2021
Posts: 32
Location: India

PostPosted: Mon Dec 08, 2025 3:49 pm
Reply with quote

Hi Team,

Could you please help me with the below requirement to sort Detail records in a file with multiple Header and Trailer

Code:
HDRFILE01
DEF
GHI
ABC
TRLFILE01
HDRFILE02
SAP
ABC
GFI
TRLFILE02


I would like to have the result as

Code:
HDRFILE01
ABC
DEF
GHI
TRLFILE01
HDRFILE02
ABC
GFI
SAP
TRLFILE02
Back to top
View user's profile Send private message
Chidane

New User


Joined: 25 Nov 2021
Posts: 32
Location: India

PostPosted: Mon Dec 08, 2025 5:07 pm
Reply with quote

Our firm is using SYNSORT utility.

I was able to sort records when only ONE HEader and One trailer is there. So when Multiple headers and trailers are there, wodering how the sort will fucntion to sort those records within the Header and Trailer
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


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

PostPosted: Mon Dec 08, 2025 11:22 pm
Reply with quote

Try and modify as needed:

Code:
  INREC IFTHEN=(WHEN=GROUP,                             
    BEGIN=(1,3,CH,EQ,C'HDR'),END=(1,3,CH,EQ,C'TRL'),     
      PUSH=(41:ID=3)),                                     
    IFTHEN=(WHEN=(1,3,CH,EQ,C'HDR'),OVERLAY=(44:Z)),     
    IFTHEN=(WHEN=(1,3,CH,EQ,C'TRL'),OVERLAY=(44:X'FF')),
    IFTHEN=(WHEN=NONE,OVERLAY=(44:X'01'))               
  SORT FIELDS=(41,3,BI,A,44,1,BI,A,1,40,CH,A)           
  OUTREC BUILD=(1,40)

It's not that difficult, is it?
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2272
Location: USA

PostPosted: Tue Dec 09, 2025 2:00 am
Reply with quote

It is more important that programs to be understandable by a human, rather than runnable by a computer
Code:
 INREC IFTHEN=(WHEN=INIT,      support ordering within groups
               OVERLAY=(44:1,3,
                  CHANGE=(1,        convert to 1 byte
                     C'HDR',X'00',
                     C'TRL',X'FF'),
                     NOMATCH=(X'01'))),               
       IFTHEN=(WHEN=GROUP,      support ordering of whole groups                             
               BEGIN=(1,3,CH,EQ,C'HDR'),
               END=(1,3,CH,EQ,C'TRL'),     
               PUSH=(41:ID=3))                                   
  SORT FIELDS=(41,3,BI,A,          order by GroupID
               44,1,BI,A,          retain HDR and TRL in place
               1,40,CH,A)          order group content         
  OUTREC BUILD=(1,40)              get rid of work fields
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


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

PostPosted: Tue Dec 09, 2025 6:27 am
Reply with quote

With CHANGE I find it harder to read, so I use it sparsely. Comment fields however will contribute to readability. I assume the TS will add them once the logic is understood.
Back to top
View user's profile Send private message
Chidane

New User


Joined: 25 Nov 2021
Posts: 32
Location: India

PostPosted: Thu Dec 18, 2025 3:41 pm
Reply with quote

Great. Thanks very much. It worked like a charm.
Back to top
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> SYNCSORT

 


Similar Topics
Topic Forum Replies
No new posts Sort SMF records? SYNCSORT 6
No new posts Identify and write records containing... SYNCSORT 11
No new posts Filter records where condition is in ... SYNCSORT 6
No new posts To Populate Trailer cnt in the file w... SYNCSORT 1
No new posts Extract records for a specific condit... DFSORT/ICETOOL 25
Search our Forums:


Back to Top