Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

sort with previous record

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
anatol

Active User


Joined: 20 May 2010
Posts: 101
Location: canada

PostPosted: Thu Oct 06, 2016 2:36 am    Post subject: sort with previous record
Reply with quote

Hi,

I have file (I need just idea, lets it fb 80)
Code:

AAAAA       
AAAAA   8   
AAAAA   7   
AAAAA   6   
AAAAA   W   
AAAAA   0   
AAAAA   1
   


in position 7 if value is W i need in sort order previous record before record W

Code:

AAAAA     
AAAAA   0 
AAAAA   1 
AAAAA   6 
AAAAA   W 
AAAAA   7 
AAAAA   8 


Is it possible?
Back to top
View user's profile Send private message

Kerry Ropar

New User


Joined: 14 Sep 2016
Posts: 25
Location: Australia

PostPosted: Thu Oct 06, 2016 3:47 am    Post subject:
Reply with quote

anatol, not sure if other people did understood your problem statement, perhaps you would like to explain it again more elaborately with some real data.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10272
Location: italy

PostPosted: Thu Oct 06, 2016 3:51 am    Post subject: Reply to: sort with previous record
Reply with quote

the explanation seems clear to me ...
a W record is considered as an extension of the preceding record
and the relation should be kept in the sorted output

the only problem - the way the question is posed - is that the sort keys are not properly described
Back to top
View user's profile Send private message
anatol

Active User


Joined: 20 May 2010
Posts: 101
Location: canada

PostPosted: Thu Oct 06, 2016 4:03 am    Post subject: Reply to: sort with previous record
Reply with quote

oh, sorry Enrico ... yes - the sort key is first 5 positions ( i need just idea how)...
and you are right about what I try to get
Input like
Code:

AAAAA     
AAAAA   8
AAAAA   7
AAAAA   6
AAAAA   W
AAAAA   0
AAAAA   1
BBBBB   8
BBBBB   7
BBBBB   0
BBBBB   W


Output
Code:

AAAAA     
AAAAA   0
AAAAA   1
AAAAA   6
AAAAA   W
AAAAA   7
AAAAA   8
BBBBB   0
BBBBB   W
BBBBB   7
BBBBB   8
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 375
Location: USA

PostPosted: Thu Oct 06, 2016 9:52 pm    Post subject: Reply to: sort with previous record
Reply with quote

My idea:
I would push position 7 of previous record and add some decimal value myself and then sort on the value including decimal. But then we'll have to take care of the character 'W'. I think it's just simpler to show what I did to achieve what you want:
Code:
 INREC IFTHEN=(WHEN=GROUP,BEGIN=(7,1,CH,NE,C'W'),PUSH=(9:7,1)),
        IFTHEN=(WHEN=(7,1,CH,NE,C'W'),BUILD=(1:1,9,10:C'.1')),
        IFTHEN=(WHEN=(7,1,CH,EQ,C'W'),BUILD=(1:1,9,10:C'.2'))
 SORT FIELDS=(9,3,CH,A)
 OUTFIL BUILD=(1,7)

So, with input as this:
Code:
AAAAA
AAAAA 8
AAAAA 7
AAAAA 6
AAAAA W
AAAAA 0
AAAAA 1   

I get output as this:
Code:
AAAAA
AAAAA 0
AAAAA 1
AAAAA 6
AAAAA W
AAAAA 7
AAAAA 8


.
Back to top
View user's profile Send private message
anatol

Active User


Joined: 20 May 2010
Posts: 101
Location: canada

PostPosted: Thu Oct 06, 2016 10:15 pm    Post subject: Reply to: sort with previous record
Reply with quote

wow ... so elegant ... thank you
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2278
Location: @my desk

PostPosted: Thu Oct 06, 2016 10:54 pm    Post subject:
Reply with quote

Rahul,

Nice work. You can add the 'EQUALS' to the SORT and get rid of those 2 additional IFTHENs. Something like.
Code:
 INREC IFTHEN=(WHEN=GROUP,BEGIN=(7,1,CH,NE,C'W'),PUSH=(9:7,1))
 SORT FIELDS=(1,5,CH,A,9,1,CH,A),EQUALS                       
 OUTREC BUILD=(1,7)                               
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 375
Location: USA

PostPosted: Thu Oct 06, 2016 11:30 pm    Post subject: Reply to: sort with previous record
Reply with quote

@anatol: You're welcome!

@Arun Raj: I was trying to remember 'EQUALS' to preserve order, but I just couldn't get that word in my mind at the time of writing that. Thanks for reminding me.

.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2278
Location: @my desk

PostPosted: Thu Oct 06, 2016 11:37 pm    Post subject:
Reply with quote

Rahul - You're welcome!
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Thu Oct 06, 2016 11:48 pm    Post subject: Reply to: sort with previous record
Reply with quote

When you have an IFTHEN which simply negates the condition of the single IFTHEN before it, use WHEN=NONE, like an ELSE in COBOL.

Similarly, if you have more than one condition, and without HIT=NEXT, you have a COBOL EVALUATE structure, and WHEN=NONE is the equivalent of OTHER.
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 -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Reduce CPU Times for Join Sort santoshn SYNCSORT 12 Sat Jun 10, 2017 1:40 pm
No new posts Need to write record of PS File in ex... Chandan1993 JCL & VSAM 1 Wed Jun 07, 2017 1:35 am
No new posts Db2 load job abending in SORT mistah kurtz DB2 4 Mon Jun 05, 2017 3:58 pm
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts How to change 'K' or 'M' use Sort vice_versa DFSORT/ICETOOL 5 Thu May 18, 2017 7:11 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us