IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

sort with previous record


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
anatol

Active User


Joined: 20 May 2010
Posts: 121
Location: canada

PostPosted: Thu Oct 06, 2016 2:36 am
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Thu Oct 06, 2016 3:51 am
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: 121
Location: canada

PostPosted: Thu Oct 06, 2016 4:03 am
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: 446
Location: USA

PostPosted: Thu Oct 06, 2016 9:52 pm
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: 121
Location: canada

PostPosted: Thu Oct 06, 2016 10:15 pm
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: 2481
Location: @my desk

PostPosted: Thu Oct 06, 2016 10:54 pm
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: 446
Location: USA

PostPosted: Thu Oct 06, 2016 11:30 pm
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: 2481
Location: @my desk

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

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Oct 06, 2016 11:48 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 8
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts JCL sort card - get first day and las... JCL & VSAM 9
No new posts To find whether record count are true... DFSORT/ICETOOL 6
Search our Forums:

Back to Top