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 

Need help in sorting

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


Joined: 25 Feb 2009
Posts: 5
Topics: 3

PostPosted: Mon Jul 06, 2009 8:48 am    Post subject: Need help in sorting Reply with quote

Hello All,

I have an input file with 80 LRECL and it contains data in the below format
Code:

08FN
02 N
01F
05 
09FN
07FN
03F
04 N
06 N
10 

Now I want the output in the below format:
Code:

02 N
04 N
06 N
07FN
08FN
09FN
01F
03F
05 
10 


Thanks in Advance...
Anand
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Mon Jul 06, 2009 10:13 am    Post subject: Reply with quote

anandmsteds,

try this

Code:

//STEP0100 EXEC PGM=SORT                               
//SYSOUT   DD SYSOUT=*                                 
//SORTIN   DD *                                       
08FN                                                   
02 N                                                   
01F                                                   
05                                                     
09FN                                                   
07FN                                                   
03F                                                   
04 N                                                   
06 N                                                   
10                                                     
//SORTOUT  DD SYSOUT=*                                 
//SYSIN    DD *                                       
  SORT FIELDS=(81,1,CH,A,3,1,CH,A,82,1,CH,A,1,2,CH,A) 
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:C'00')),         
  IFTHEN=(WHEN=(3,2,CH,EQ,C' '),OVERLAY=(81:C'9')),   
  IFTHEN=(WHEN=(4,1,CH,EQ,C' '),OVERLAY=(82:C'9'))     
  OUTFIL BUILD=(1,80)                                 
/*

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


Joined: 02 Dec 2002
Posts: 93
Topics: 0
Location: Orlando, FL

PostPosted: Mon Jul 06, 2009 2:09 pm    Post subject: Reply with quote

Wouldn't a simple

SORT FIELDS=(4,1,CH,D,1,3,CH,A)

accomplish the desired results more efficiently?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Mon Jul 06, 2009 2:22 pm    Post subject: Reply with quote

Ronb,

Yes it would give the desired results. For some reason I interpreted that 3rd byte is the driving factor in sorting. I guess we have to wait for OP to come up with the exact rules.
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
anandmsteds
Beginner


Joined: 25 Feb 2009
Posts: 5
Topics: 3

PostPosted: Tue Jul 07, 2009 12:09 am    Post subject: Reply with quote

Thanks Kolusu & Ronb for the quick solutions.

Using both sort cards, I got the desired output for the above sample data. However, Ronb solution didn't worked for another sample test data (mentioned below).

09
08FN
07
10F
01 N
05
04F
06 N
02FN
03F

I got the required output using Kolusu's solution for the above sample data also.

Kolusu,
Could you please explain in detail about the solution which you have provided. This will help me in understanding the sort functionality.

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


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

PostPosted: Tue Jul 07, 2009 10:06 am    Post subject: Reply with quote

anandmsteds,

It would have been nice if you explained the rules for sorting. Luckily my guess was correct but in future make sure to explain the requirement in detail

Anyway here is an explanation of the control cards

Code:
INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:C'00')),   


This statement will put 2 zeros in pos 81.

Code:
IFTHEN=(WHEN=(3,2,CH,EQ,C' '),OVERLAY=(81:C'9')),


when pos 3 for 2 bytes has spaces we overlay a value of 9 in pos 81

Code:
IFTHEN=(WHEN=(4,1,CH,EQ,C' '),OVERLAY=(82:C'9'))


when pos 4 for 1 bytes has spaces we overlay a value of 9 in pos 82

Code:
SORT FIELDS=(81,1,CH,A,3,1,CH,A,82,1,CH,A,1,2,CH,A) 


Now we sort on the indicator at pos 81 first so that all the records that have 2 spaces in pos 3 are pushed to the bottom. Then we sort on pos 3 and then followed again pos 82 which takes care of the 4th byte space records and then finally by the first 2 bytes.
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
anandmsteds
Beginner


Joined: 25 Feb 2009
Posts: 5
Topics: 3

PostPosted: Wed Jul 08, 2009 5:45 am    Post subject: Reply with quote

My Mistake....

And Thanks for the detailed explanation Kolusu... You are great...


Thanks
Anand
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