MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Overlay, then sort then overlay again, if possible

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
Fab
Beginner


Joined: 15 Nov 2016
Posts: 47
Topics: 6

PostPosted: Fri Feb 10, 2017 9:26 am    Post subject: Overlay, then sort then overlay again, if possible Reply with quote

Hello,
actually I have to do the following jobs in this sequence:
1. if a column 9 there is a "T" then replave it with "1"
2. after 1. sort by the specified fields below, so including the newly substituted '1' (which should act like a placeholder that will cause all records which have 1 to come first every other records)
3. replace again all '1' at column 9 with original 'T' value.

at the moment my sort is like this:
Code:

//TEST02   EXEC PGM=SORT
//SYSOUT DD SYSOUT=*   
//SORTIN DD *           
0047 A 1T               
0037 A 1               
0017 B 2T               
0007 B 2               
0057 B 1T               
0077 B 1               
0787 C 1T               
0908 A 1T               
0108 B 2               
0098 B 2T               
0088 B 2               
0018 B 2T               
//SORTOUT DD SYSOUT=*   
//SYSIN DD *           
  SORT FIELDS=(1,4,CH,A,
               9,1,CH,A)
  INREC IFTHEN=(WHEN=(9,1,CH,EQ,C'T'),
    OVERLAY=(9:C'1'))               

Now the output is the following:
Code:

0007 B 2
0017 B 21
0018 B 21
0037 A 1
0047 A 11
0057 B 11
0077 B 1
0088 B 2
0098 B 21
0108 B 2
0787 C 11
0908 A 11

I am not sure all 3 tasks may be attained in just 1 sort, I guess I would need 2 sorts, but maybe someone could instruct me on how to make steps 1 and 2 with just one sort (so I could end up with 2 sort instead of 3)

Thanks in advance for any support.

PS
substitute T with 1 in step 1 is necessary because at that column I have many single letters, but I need all record with 'T' to come first than any other record. Sorry for my poor english.
Back to top
View user's profile Send private message
Fab
Beginner


Joined: 15 Nov 2016
Posts: 47
Topics: 6

PostPosted: Fri Feb 10, 2017 9:48 am    Post subject: Reply with quote

Well, after a further explanation with my colleague I finally understood what he needs.

At column 9 I can have many different letters, each one must be substituted with a specific number (this is because I need to sort by that letter, but in a customized order). Follows an example:
Code:

0047 A 1T -- 1
0037 A 1C -- 2
0017 B 2T     
0007 B 2A -- 3
0057 B 1T     
0077 B 1S -- 4
0787 C 1T     
0908 A 1T     
0108 B 2D -- 5
0098 B 2T     
0088 B 2G -- 6
0018 B 2T     

Now each 'T' must be substituted with 1 (this is because I want record with t to come first of each other, each 'C' must be substituted with 2 and so on...

According to that I changed my previous sort as follows:
Code:

SORT FIELDS=(1,4,CH,A,                               
             9,1,CH,A)                               
INREC IFTHEN=(WHEN=(9,1,CH,EQ,C'T'),OVERLAY=(9:C'1')),
      IFTHEN=(WHEN=(9,1,CH,EQ,C'C'),OVERLAY=(9:C'2')),
      IFTHEN=(WHEN=(9,1,CH,EQ,C'A'),OVERLAY=(9:C'3')),
      IFTHEN=(WHEN=(9,1,CH,EQ,C'S'),OVERLAY=(9:C'4')),
      IFTHEN=(WHEN=(9,1,CH,EQ,C'D'),OVERLAY=(9:C'5')),
      IFTHEN=(WHEN=(9,1,CH,EQ,C'G'),OVERLAY=(9:C'6'))

My output is:
Code:

0007 B 23 -- 3
0017 B 21 -- 1
0018 B 21     
0037 A 12 -- 2
0047 A 11 -- 1
0057 B 11     
0077 B 14 -- 4
0088 B 26 -- 6
0098 B 21     
0108 B 25 -- 5
0787 C 11     
0908 A 11     

which is not exactly good, because it seems that sort is executed just before substitution, I would like to execute (in just one sort step), after substitution. Is it that possible?

Thanks again
Back to top
View user's profile Send private message
Fab
Beginner


Joined: 15 Nov 2016
Posts: 47
Topics: 6

PostPosted: Fri Feb 10, 2017 10:03 am    Post subject: Reply with quote

I forgot to mention that I still have to execute step 3 after 1 and 2, so after substitution and subsequent sort I will have to reverse numbers to letters like before substitution, so '1' will again become 'T', '2' will become 'C' and so on, my apologies for having to post 3 times to explain this simple thing.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12358
Topics: 75
Location: San Jose

PostPosted: Fri Feb 10, 2017 10:45 am    Post subject: Reply with quote

Fab,

Please post your code using code tags. Check this topic which explains in detail about posting code tags so that it looks like a mainframe screenshot. I edited your previous posts.

http://www.mvsforums.com/helpboards/viewtopic.php?p=19031#19031

Coming to the requirement, you really don't need to substitute the characters using INREC, you can use ALTSEQ code. That ALTSEQ code will be used for sorting and the original record will stay the same.

I am not clear as to what your final output is but here is an example of how you can use ALTSEQ code
Code:

//STEP0100 EXEC PGM=SORT                                         
//SYSOUT   DD SYSOUT=*                                           
//SORTIN   DD *                                                 
C                                                               
A                                                               
T                                                               
Z                                                               
D                                                               
//SORTOUT  DD SYSOUT=*                                           
//SYSIN    DD *                                                 
  SORT FIELDS=(1,1,AQ,A),EQUALS                                 
                                                                 
  ALTSEQ CODE=(E340,      $ CHANGE 'T' TO C' ' TO SORT BEFORE A 
               E9C3)      $ CHANGE 'Z' TO C'C' TO SORT BEFORE D 
//*


You don't have to worry about putting back the original value as the ALTSEQ is only used for sorting but does not physically change the value.

You would quote the same for the value in position 9. You just need to provide the values in HEX

In your case you would need something like this

Code:

//SYSIN    DD *                                                 
  SORT FIELDS=(1,4,CH,A,                                         
               9,1,AQ,A),EQUALS                                 
                                                                 
  ALTSEQ CODE=(E340,      $ CHANGE 'T' TO C' ' TO SORT BEFORE A 
               C3C1,      $ CHANGE 'C' TO C'A' TO SORT AFTER ' '
               C1C3,      $ CHANGE 'A' TO C'C' TO SORT AFTER  B 
               E2C4,      $ CHANGE 'S' TO C'D' TO SORT BEFORE D 
               C4C5)      $ CHANGE 'D' TO C'E' TO SORT BEFORE E 
//*

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Fab
Beginner


Joined: 15 Nov 2016
Posts: 47
Topics: 6

PostPosted: Fri Feb 10, 2017 11:12 am    Post subject: Reply with quote

Hi Kolusu,
thanks, I really don't completely understant your answer, could you please use my previous input case and show me the ALTSEQ solution? so that I can test it and see results.

My input is like this:
Code:

0047 A 1T
0037 A 1C
0017 B 2T     
0007 B 2A
0057 B 1T     
0077 B 1S
0787 C 1T     
0908 A 1T     
0108 B 2D
0098 B 2T     
0088 B 2G
0018 B 2T     


my output should be like this:

Code:

0017 B 2T     
0018 B 2T     
0047 A 1T
0057 B 1T     
0098 B 2T     
0787 C 1T     
0908 A 1T     
0037 A 1C
0007 B 2A
0077 B 1S
0108 B 2D
0088 B 2G
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12358
Topics: 75
Location: San Jose

PostPosted: Fri Feb 10, 2017 11:40 am    Post subject: Reply with quote

Fab,

Looks like you need to treat the character at position 9 as your primary sort character and then the secondary is at position 1. So here is a JCL which will give you the desired results

Code:

//STEP0100 EXEC PGM=SORT                                         
//SYSOUT   DD SYSOUT=*                                           
//SORTIN   DD *                                                 
0047 A 1T                                                       
0037 A 1C                                                       
0017 B 2T                                                       
0007 B 2A                                                       
0057 B 1T                                                       
0077 B 1S                                                       
0787 C 1T                                                       
0908 A 1T                                                       
0108 B 2D                                                       
0098 B 2T                                                       
0088 B 2G                                                       
0018 B 2T                                                       
//SORTOUT  DD SYSOUT=*                                           
//SYSIN    DD *                                                 
  SORT FIELDS=(9,1,AQ,A,                                         
               1,4,CH,A),EQUALS                                       
                                                                 
  ALTSEQ CODE=(E340,      $ CHANGE 'T' TO C' ' TO SORT BEFORE A 
               C3C1,      $ CHANGE 'C' TO C'A' TO SORT AFTER ' '
               C1C3,      $ CHANGE 'A' TO C'C' TO SORT AFTER  B 
               E2C4,      $ CHANGE 'S' TO C'D' TO SORT BEFORE D 
               C4C5)      $ CHANGE 'D' TO C'E' TO SORT BEFORE E 
//*


will produce

Code:

0017 B 2T
0018 B 2T
0047 A 1T
0057 B 1T
0098 B 2T
0787 C 1T
0908 A 1T
0037 A 1C
0007 B 2A
0077 B 1S
0108 B 2D
0088 B 2G

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Fab
Beginner


Joined: 15 Nov 2016
Posts: 47
Topics: 6

PostPosted: Tue Feb 21, 2017 11:12 am    Post subject: Reply with quote

I did it, the sort worked as expected.
Many thanks Kolusu.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group