Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
need help with a tricky sort - Continued

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> SYNCSORT
View previous topic :: :: View next topic  
Author Message
rajiv rengasamy

New User


Joined: 24 Sep 2008
Posts: 27
Location: Chennai

PostPosted: Tue Jul 16, 2019 1:26 pm    Post subject: need help with a tricky sort - Continued
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

Active Member


Joined: 29 Apr 2008
Posts: 609
Location: Maryland

PostPosted: Tue Jul 16, 2019 5:34 pm    Post subject: Re: need help with a tricky sort - Continued
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

Active Member


Joined: 29 Apr 2008
Posts: 609
Location: Maryland

PostPosted: Tue Jul 16, 2019 5:50 pm    Post subject:
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: 27
Location: Chennai

PostPosted: Tue Jul 16, 2019 7:59 pm    Post subject:
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

Active Member


Joined: 29 Apr 2008
Posts: 609
Location: Maryland

PostPosted: Tue Jul 16, 2019 8:15 pm    Post subject:
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: 27
Location: Chennai

PostPosted: Tue Jul 16, 2019 8:21 pm    Post subject:
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

Active Member


Joined: 29 Apr 2008
Posts: 609
Location: Maryland

PostPosted: Tue Jul 16, 2019 8:25 pm    Post subject:
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

Active Member


Joined: 29 Apr 2008
Posts: 609
Location: Maryland

PostPosted: Tue Jul 16, 2019 8:27 pm    Post subject:
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

Active Member


Joined: 29 Apr 2008
Posts: 609
Location: Maryland

PostPosted: Wed Jul 17, 2019 1:20 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> SYNCSORT All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Sort to construct single record from ... Deepti_R SYNCSORT 3 Wed Nov 13, 2019 12:14 am
No new posts Capture DSN names through SORT / IDCAMS reach2abhinavtyagi DFSORT/ICETOOL 8 Tue Nov 05, 2019 7:33 pm
No new posts Convert mainframe data to .csv format... karan_reddy DFSORT/ICETOOL 10 Sat Nov 02, 2019 2:09 am
No new posts One-One matching using SORT dearlux SYNCSORT 14 Fri Oct 11, 2019 12:11 am
No new posts Create Dynamic Sort card with Omit co... balaji81_k DFSORT/ICETOOL 9 Thu Sep 26, 2019 10:06 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us