View previous topic :: View next topic
|
Author |
Message |
anatol
Active User
Joined: 20 May 2010 Posts: 121 Location: canada
|
|
|
|
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 |
|
|
Kerry Ropar
New User
Joined: 14 Sep 2016 Posts: 25 Location: Australia
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
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 |
|
|
anatol
Active User
Joined: 20 May 2010 Posts: 121 Location: canada
|
|
|
|
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 |
|
|
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
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 |
|
|
anatol
Active User
Joined: 20 May 2010 Posts: 121 Location: canada
|
|
|
|
wow ... so elegant ... thank you |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
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 |
|
|
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
@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 |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Rahul - You're welcome! |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|