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

need help with a tricky sort - Continued


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

New User


Joined: 24 Sep 2008
Posts: 26
Location: Chennai

PostPosted: Tue Jul 16, 2019 1:26 pm
Reply with quote

I have a file with multiple sets of data.
Each set of data has its own header and trailer with data records between them.
The number of sets of data is not fixed; it can vary as per Business day.

1 – Header indicator for each set of data
3 - Trailer indicator for each set of data
Data records between each Header and Trailer are prefixed by number 2.

So the file will look as below

Header
1
2Field2 SUBFIELD3
2Field2 SUBFIELD1
2Field2 SUBFIELD2
2Field1 SUBFIELD1
2Field38 SUBFIELD2
2Field38 SUBFIELD1
2Field3 SUBFIELD1
3
1
2Field4 SUBFIELD1
2Field38 SUBFIELD1
2Field38 SUBFIELD2
2Field40 SUBFIELD1
2Field7 SUBFIELD2
2Field3 SUBFIELD2
2Field3 SUBFIELD1
2Field7 SUBFIELD1
3
1
2Field3 SUBFIELD3
2Field3 SUBFIELD2
2Field3 SUBFIELD1
2Field9 SUBFIELD1
2Field1 SUBFIELD1
2Field38 SUBFIELD2
2Field38 SUBFIELD1
3
Trailer

I want the data contained between each header, trailer to be stored on Filed and Subfield value in ascending order, for the entire file.
Note: But when it comes to Field38, it’s a special type of data. Field38 have has to be placed in ascending order sequence (i.e. after Field37 or any nearest smaller value Field), but its SUBFIELD values should be presented exactly as it been received in the input file.

(Sergeyken had already suggested the solution for sorting on fields and subfields for the whole file, only thing we now want is to grant this special privilege to Filed38)

So the result should look as below

Header
1
2Field1 SUBFIELD1
2Field2 SUBFIELD1
2Field2 SUBFIELD2
2Field2 SUBFIELD3
2Field3 SUBFIELD1
2Field38 SUBFIELD2
2Field38 SUBFIELD1

3
1
2Field3 SUBFIELD1
2Field3 SUBFIELD2
2Field4 SUBFIELD1
2Field7 SUBFIELD1
2Field7 SUBFIELD2
2Field38 SUBFIELD1
2Field38 SUBFIELD2
2Field40 SUBFIELD1

3
1
2Field1 SUBFIELD1
2Field3 SUBFIELD1
2Field3 SUBFIELD2
2Field3 SUBFIELD3
2Field9 SUBFIELD1
2Field38 SUBFIELD2
2Field38 SUBFIELD1
3
Trailer

I've tried to explain at my best effort,please apologies me if its confusion or let me know if you need further information or clarification

Thank you.
Regards,
rajiv r
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2019
Location: USA

PostPosted: Tue Jul 16, 2019 5:34 pm
Reply with quote

rajiv rengasamy wrote:
Note: But when it comes to Field38, it’s a special type of data. Field38 have has to be placed in ascending order sequence (i.e. after Field37 or any nearest smaller value Field), but its SUBFIELD values should be presented exactly as it been received in the input file.

==> Rows (lines) with Field38 should not be reordered by SUBFIELD
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2019
Location: USA

PostPosted: Tue Jul 16, 2019 5:50 pm
Reply with quote

Code:
 INREC IFTHEN=(WHEN=GROUP,                                     
*              DETECT EITHER OF 'H(EADER)', '1', 'T(RAILER)' 
               BEGIN=(1,1,SS,EQ,C'H1T'),                       
               PUSH=(81:ID=6,    APPEND GROUP SEQ NUMBER       
                     SEQ=9)),    APPEND LINE NO WITHIN GROUP   
       IFTHEN=(WHEN=(2,7,CH,EQ,C'FIELD38'),                   
               OVERLAY=(96:87,9)),    USE FIELD38'S SEQ NO     
       IFTHEN=(WHEN=NONE,                                     
               OVERLAY=(96:9,9))      USE REGULAR SUBFIELD     
*                                                             
 SORT FIELDS=(81,6,ZD,A,         GROUP SEQ NUM                 
               1,1,CH,A,          LINE TYPE WITHIN GROUP       
               2,7,CH,A,          FIELD                         
              96,9,CH,A)          MODIFIED SUBFIELD             
*                                                             
 OUTREC BUILD=(1,80)             TRUNCATE GROUP NUMBER, AND LINE NUMBER         
*                                                             
 END
Back to top
View user's profile Send private message
rajiv rengasamy

New User


Joined: 24 Sep 2008
Posts: 26
Location: Chennai

PostPosted: Tue Jul 16, 2019 7:59 pm
Reply with quote

I tried running the code..looks like until it finds a Field38 it works and after that the sorting is not done...Please find the derived output

Header
1
2Field1 SUBFIELD1
2Field2 SUBFIELD1
2Field2 SUBFIELD2
2Field2 SUBFIELD3
2Field3 SUBFIELD1
2Field38 SUBFIELD2
2Field38 SUBFIELD1
3
1
2Field3 SUBFIELD1
2Field3 SUBFIELD2
2Field38 SUBFIELD1
2Field38 SUBFIELD2
2Field4 SUBFIELD1
2Field40 SUBFIELD1
2Field7 SUBFIELD1
2Field7 SUBFIELD2

3
1
2Field1 SUBFIELD1
2Field3 SUBFIELD1
2Field3 SUBFIELD2
2Field3 SUBFIELD3
2Field38 SUBFIELD2
2Field38 SUBFIELD1
2Field9 SUBFIELD1
3
Trailer
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2019
Location: USA

PostPosted: Tue Jul 16, 2019 8:15 pm
Reply with quote

As per your explanation, 'FIELD38' value is sorted among other FIELD values.

So, FIELD38 goes before FIELD4, FIELD40, FIELD7, FIELD9 etc. etc. etc.

It's not clear from your initial example: why FIELD38 might be considered not less than FIELD4, or FIELD40???

If you need this, you MUST consider digits at the end of your "fields" as numeric values, not as character strings.

Code:
 INREC IFTHEN=(WHEN=GROUP,                                     
*              DETECT EITHER OF 'H(EADER)', '1', 'T(TRAILER)' 
               BEGIN=(1,1,SS,EQ,C'H1T'),                       
               PUSH=(81:ID=6,    APPEND GROUP SEQ NUMBER       
                     SEQ=9)),    APPEND LINE NO WITHIN GROUP   
       IFTHEN=(WHEN=(2,7,CH,EQ,C'FIELD38'),                   
               OVERLAY=(96:87,9)),    USE FIELD38'S SEQ NO     
       IFTHEN=(WHEN=NONE,                                     
               OVERLAY=(96:9,9))      USE REGULAR SUBFIELD     
*                                                             
 SORT FIELDS=(81,6,ZD,A,         GROUP SEQ NUM                 
              1,1,CH,A,          LINE TYPE WITHIN GROUP       
              2,7,UFF,A,          FIELD                       
             96,9,UFF,A)          MODIFIED SUBFIELD           
*                                                             
 OUTREC BUILD=(1,80)             TRUNCATE GROUP NUMBER         
*                                                             
 END                                                           


Code:
HEADER                 
1                       
2FIELD1 SUBFIELD1       
2FIELD2 SUBFIELD1       
2FIELD2 SUBFIELD2       
2FIELD2 SUBFIELD3       
2FIELD3 SUBFIELD1       
2FIELD38SUBFIELD2       
2FIELD38SUBFIELD1       
3                       
1                       
2FIELD3 SUBFIELD1       
2FIELD3 SUBFIELD2       
2FIELD4 SUBFIELD1       
2FIELD7 SUBFIELD1       
2FIELD7 SUBFIELD2       
2FIELD38SUBFIELD1       
2FIELD38SUBFIELD2       
2FIELD40SUBFIELD1       
3                       
1                       
2FIELD1 SUBFIELD1       
2FIELD3 SUBFIELD1       
2FIELD3 SUBFIELD2       
2FIELD3 SUBFIELD3       
2FIELD9 SUBFIELD1       
2FIELD38SUBFIELD2       
2FIELD38SUBFIELD1       
3                       
TRAILER                 
Back to top
View user's profile Send private message
rajiv rengasamy

New User


Joined: 24 Sep 2008
Posts: 26
Location: Chennai

PostPosted: Tue Jul 16, 2019 8:21 pm
Reply with quote

Sorry..i tried executing the code which you shared and that resulted me the output which i highlighted in my previous reply.

But the expected output is

Header
1
2Field1 SUBFIELD1
2Field2 SUBFIELD1
2Field2 SUBFIELD2
2Field2 SUBFIELD3
2Field3 SUBFIELD1
2Field38 SUBFIELD2
2Field38 SUBFIELD1

3
1
2Field3 SUBFIELD1
2Field3 SUBFIELD2
2Field4 SUBFIELD1
2Field7 SUBFIELD1
2Field7 SUBFIELD2
2Field38 SUBFIELD1
2Field38 SUBFIELD2
2Field40 SUBFIELD1

3
1
2Field1 SUBFIELD1
2Field3 SUBFIELD1
2Field3 SUBFIELD2
2Field3 SUBFIELD3
2Field9 SUBFIELD1
2Field38 SUBFIELD2
2Field38 SUBFIELD1
3
Trailer
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2019
Location: USA

PostPosted: Tue Jul 16, 2019 8:25 pm
Reply with quote

rajiv rengasamy wrote:
Sorry..i tried executing the code which you shared and that resulted me the output which i highlighted in my previous reply.

But the expected output is

Header
1
2Field1 SUBFIELD1
2Field2 SUBFIELD1
2Field2 SUBFIELD2
2Field2 SUBFIELD3
2Field3 SUBFIELD1
2Field38 SUBFIELD2
2Field38 SUBFIELD1

3
1
2Field3 SUBFIELD1
2Field3 SUBFIELD2
2Field4 SUBFIELD1
2Field7 SUBFIELD1
2Field7 SUBFIELD2
2Field38 SUBFIELD1
2Field38 SUBFIELD2
2Field40 SUBFIELD1

3
1
2Field1 SUBFIELD1
2Field3 SUBFIELD1
2Field3 SUBFIELD2
2Field3 SUBFIELD3
2Field9 SUBFIELD1
2Field38 SUBFIELD2
2Field38 SUBFIELD1
3
Trailer

I repeat again: your verbal explanation did not much your example.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2019
Location: USA

PostPosted: Tue Jul 16, 2019 8:27 pm
Reply with quote

rajiv rengasamy wrote:
Sorry..i tried executing the code which you shared and that resulted me the output which i highlighted in my previous reply.

But the expected output is

Header
1
2Field1 SUBFIELD1
2Field2 SUBFIELD1
2Field2 SUBFIELD2
2Field2 SUBFIELD3
2Field3 SUBFIELD1
2Field38 SUBFIELD2
2Field38 SUBFIELD1

3
1
2Field3 SUBFIELD1
2Field3 SUBFIELD2
2Field4 SUBFIELD1
2Field7 SUBFIELD1
2Field7 SUBFIELD2
2Field38 SUBFIELD1
2Field38 SUBFIELD2
2Field40 SUBFIELD1

3
1
2Field1 SUBFIELD1
2Field3 SUBFIELD1
2Field3 SUBFIELD2
2Field3 SUBFIELD3
2Field9 SUBFIELD1
2Field38 SUBFIELD2
2Field38 SUBFIELD1
3
Trailer


String 'Field38' is less than string 'Field4'
As well as string '38' is less than string '4'
But numeric value 38 is greater than numeric value 4.

Read carefully about different datatypes in SORT utilities, and in various programming languages, too.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2019
Location: USA

PostPosted: Wed Jul 17, 2019 1:20 am
Reply with quote

With your understanding of the terms "greater than" vs "less than" your example must look as follows

Code:
//*==========================================
//* PROCESS GROUPS                           
//*==========================================
//GROUPS   EXEC PGM=SYNCSORT                 
//*                                         
//SYSOUT   DD  SYSOUT=*                     
//*                                         
//SORTIN   DD  *                             
HEADER                                       
1                                           
2     2         3                           
2     2         1                           
2     2         2                           
2     1         1                           
2    38         2                           
2    38         1                           
2     3         1                           
3                                           
1                                           
2     4         1                           
2    38         1                           
2    38         2                           
2    40         1                           
2     7         2                           
2     3         2                           
2     3         1                           
2     7         1                           
3                                           
1                                           
2     3         3                           
2     3         2                           
2     3         1                           
2     9         1                           
2     1         1                           
2    38         2                           
2    38         1                           
3                                           
TRAILER                                     
//*                                         
//SORTOUT  DD  SYSOUT=*                                       
//*                                                           
//SYSIN    DD  *                                               
 INREC IFTHEN=(WHEN=GROUP,                                     
*              DETECT EITHER OF 'H(EADER)', '1', 'T(TRAILER)' 
               BEGIN=(1,1,SS,EQ,C'H1T'),                       
               PUSH=(81:ID=6,    APPEND GROUP SEQ NUMBER       
                     SEQ=9)),    APPEND LINE NO WITHIN GROUP   
       IFTHEN=(WHEN=(2,7,UFF,EQ,+38),                         
               OVERLAY=(96:87,9)),    USE FIELD38'S SEQ NO     
       IFTHEN=(WHEN=NONE,                                     
               OVERLAY=(96:9,9))      USE REGULAR SUBFIELD     
*                                                             
 SORT FIELDS=(81,6,ZD,A,         GROUP SEQ NUM                 
              1,1,CH,A,          LINE TYPE WITHIN GROUP       
              2,7,CH,A,          FIELD                         
             96,9,CH,A)          MODIFIED SUBFIELD             
*                                                             
 OUTREC BUILD=(1,80)             TRUNCATE GROUP NUMBER         
*                                                             
 END                                                           
//*


Result looks like this
Code:
HEADER               
1                     
2     1         1     
2     2         1     
2     2         2     
2     2         3     
2     3         1     
2    38         2     
2    38         1     
3                     
1                     
2     3         1     
2     3         2     
2     4         1     
2     7         1     
2     7         2     
2    38         1     
2    38         2     
2    40         1     
3                     
1                     
2     1         1     
2     3         1     
2     3         2     
2     3         3     
2     9         1     
2    38         2     
2    38         1     
3                     
TRAILER               


Conclusion: RTFM, RTFM, and RTFM! 358.gif
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 -> SYNCSORT

 


Similar Topics
Topic Forum Replies
No new posts Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts JCL sort card - get first day and las... JCL & VSAM 9
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
No new posts how to calculate SUM value for VB fil... DFSORT/ICETOOL 1
Search our Forums:

Back to Top