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

New User


Joined: 20 May 2010
Posts: 99
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: 10203
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

New User


Joined: 20 May 2010
Posts: 99
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: 331
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

New User


Joined: 20 May 2010
Posts: 99
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: 2165
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: 331
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: 2165
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: 7236

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 Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
This topic is locked: you cannot edit posts or make replies. How to pass the previous month date i... Suganya87 DFSORT/ICETOOL 5 Mon Oct 31, 2016 4:13 pm
No new posts How to get previous month in SYMNAMES Suganya87 SYNCSORT 9 Fri Oct 28, 2016 1:37 pm


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