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 

Arranging records

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


Joined: 12 Sep 2003
Posts: 3
Topics: 2

PostPosted: Wed Nov 03, 2004 6:31 am    Post subject: Arranging records Reply with quote

Hi,
Can you help me out in this:

I've a file in which 15th byte will have values 164,148 or 149.
I need to sort the file in 164, 148 and 149.
ie.,the input is
XXXXXXXXXXXXXX,148,.........
XXXXXXXXXXXXXX,149,.........
XXXXXXXXXXXXXX,164,.........

the Output must be
XXXXXXXXXXXXXX,164,.........
XXXXXXXXXXXXXX,148,.........
XXXXXXXXXXXXXX,149,.........


Can I achieve this using SORT/EZTRIEVE/SAS?
Please help. Else I need to do this in program.
Back to top
View user's profile Send private message Send e-mail
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Wed Nov 03, 2004 6:56 am    Post subject: Reply with quote

Padma,

The following job will help you to do the sorting. I assumed that your input file is LRECL=80 & RECFM=FB. If not you need to change the job appropriately. If you have difficulty get back to us.

Code:

//R010      EXEC  PGM=SORT                     
//SORTIN   DD   *                             
XXXXXXXXXXXXXX148,.........                   
XXXXXXXXXXXXXX149,.........                   
XXXXXXXXXXXXXX164,.........                   
/*                                             
//SORTOUT  DD  SYSOUT=*                       
//SYSOUT    DD  SYSOUT=*                       
//SYSIN       DD  *                           
  INREC FIELDS=(1,80,                         
                15,3,CHANGE=(1,C'164',C'1'),   
                    NOMATCH=(C'2'))           
  SORT FIELDS=(81,1,CH,A,                     
               15,3,CH,A)                     
  OUTREC FIELDS=(1,80)                         
/*                                             


Here is the explanation.

1. In Inrec I copy the 3 chars from Col. 15 and populate them in position 81-84 (after the end of the layout).

2. At the same time, I use the Change command to replace 164 by '1' and any other values by '2'.

3. Now Sort on 81st col (which will have either 1 or 2 - '1' for 164 & '2' for other values) and the next level of sort is on the original position 15,3. This way 164 will come on top since the first level of sort 81,1 has the lowest value '1' (for 164). For other records 148, 149.....the 81st col will be same '2'. So the second level of sorting takes place putting the records in the correct order.

4. Remove the newly added constants & output only 80 chars.

Hope this helps,

Thanks,
Phantom
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Wed Nov 03, 2004 7:00 am    Post subject: Reply with quote

Padama,

Try this Job.You can use ALTSEQ to reverse the sorting order treating the numbers provided . Here in this we need to treat 8 as higher than 9. so we simply interchange them using ALTSEQ. The AQ is used to sort in the ALTSEQ format while assuming x'F8' (HEX OF NUMBER 8 ) is to be treated as x'F9' (hex of 9). And similary x'F9' (HEX OF NUMBER 9) is to be treated as x'F8' (hex of 8 ).


Code:

//STEP0100 EXEC PGM=SORT     
//SYSOUT   DD SYSOUT=*       
//SORTIN   DD *               
XXXXXXXXXXXXXX,148,......... 
XXXXXXXXXXXXXX,149,......... 
XXXXXXXXXXXXXX,164,......... 
//SORTOUT  DD SYSOUT=*       
//SYSIN    DD *               
  SORT FIELDS=(16,3,AQ,D)     
  ALTSEQ CODE=(F8F9,F9F8)     
/*                           


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Wed Nov 03, 2004 7:22 am    Post subject: Reply with quote

Wow, This is great kolusu.

padma,

You need to clarify one thing here. Do you have only 3 options 164, 148 & 149 ?

If not then you cannot use the second solution. Kolusu's solution will bring 164 on top of everything but if you have other items that end in 9 then it may not sort them in the order that you may be looking for.

Example:
Code:

Input:
XXXXXXXXXXXXXX,148,.........
XXXXXXXXXXXXXX,149,.........
XXXXXXXXXXXXXX,159,.........
XXXXXXXXXXXXXX,139,.........
XXXXXXXXXXXXXX,164,.........


Output:
XXXXXXXXXXXXXX,164,.........
XXXXXXXXXXXXXX,159,.........
XXXXXXXXXXXXXX,148,.........
XXXXXXXXXXXXXX,149,.........
XXXXXXXXXXXXXX,139,.........


You can see that 159 remains on top and 139 is pushed to the bottom.

Thanks,
Phantom
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