|
View previous topic :: View next topic
|
| Author |
Message |
Chidane
New User
Joined: 25 Nov 2021 Posts: 32 Location: India
|
|
|
|
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 |
|
 |
Chidane
New User
Joined: 25 Nov 2021 Posts: 32 Location: India
|
|
|
|
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 |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1431 Location: Bamberg, Germany
|
|
|
|
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 |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2272 Location: USA
|
|
|
|
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 |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1431 Location: Bamberg, Germany
|
|
|
|
| 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 |
|
 |
Chidane
New User
Joined: 25 Nov 2021 Posts: 32 Location: India
|
|
|
|
| Great. Thanks very much. It worked like a charm. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|