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

Sorting selectively


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

New User


Joined: 21 Sep 2013
Posts: 2
Location: India

PostPosted: Sat Sep 21, 2013 1:07 am
Reply with quote

Hi,

I am trying to sort a file based on below mentioned fields, file length = 145
Code:
SORT FIELDS=(81,1,CH)
( default ascending)

Column 81 data is mentioned below for 10 RECORDS
Code:
A
C
Z
H
Y
M
Y
D
B
H


The output gives me the sorted data as based on column 81
Code:
A
B
C
D
H
H
M
Y
Y
Z


I need to get the output like
Code:
A
B
C
D
H
Y
Y
H
M
Z


Sorted for all except dumps 'H' and 'Y' as they come exactly from the first instance of eithers' occurrence
is there a way to elegantly use sort to get this in a simple way .
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: Sat Sep 21, 2013 1:56 am
Reply with quote

I assume that whichever of H or Y comes first, all the H and Y are to be sotred at that position?

Elegant? You mean code that is easy to understand?
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: Sat Sep 21, 2013 3:38 am
Reply with quote

OK, tested with your one-byte keys as the entire record:

Code:
* ENSURE THAT INPUT ORDER IS PRESERVED FOR DUPLICATE KEYS
*
  OPTION EQUALS
                                                                     
* OUTPUT RECORD LENGTH FROM IFTHEN PROCESSING TO BE 2
*
  INREC IFOUTLEN=2,
                                                                     
* TREAT H,Y AS THE START OF A ONE-RECORD GROUP - TO KNOW THE
* FIRST OF THE H,Y WHEN ID=01
*
        IFTHEN=(WHEN=GROUP,BEGIN=(1,1,SS,EQ,C'H,Y'),
                PUSH=(2:1,1,ID=2),RECORDS=1),
                                                                     
* A SECOND GROUP, TO PLACE THE SORT-KEY OF THE ID=01 ON ALL SUBSEQUENT
* RECORDS AS AN "OUTSORT"
*
        IFTHEN=(WHEN=GROUP,
                BEGIN=(3,2,CH,EQ,C'01'),
                PUSH=(2:2,1)),
                                                                     
* FOR THOSE WHICH ARE NOT H,Y, OVERWRITE THE OUTSORT FIELD TO GET
* THE NORMAL ORDER FOR THOSE RECORDS
*
        IFTHEN=(WHEN=(1,1,SS,NE,C'H,Y'),
                OVERLAY=(2:1,1))
  SORT FIELDS=(2,1,CH,A)
                                                                     
* CUT THE OUTSORT KEY OFF THE RECORD (THIS WOULD BE 1,1, BUT IS
* 1,2 TO SHOW THE OUTSORT KEY)
*
  OUTREC BUILD=(1,2)


Output for:
Code:
A
C
Z
H
Y
M
Y
D
B
H


Is:
Code:
AA
BB
CC
DD
HH
YH
YH
HH
MM
ZZ


For:
Code:
A
C
Z
Y
H
M
Y
D
B
H


Is:
Code:
AA
BB
CC
DD
MM
YY
HY
YY
HY
ZZ
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Sat Sep 21, 2013 6:17 am
Reply with quote

I am not sure if I understood the question correctly but please check if this will work -
Code:
OPTION EQUALS
SORT FIELDS=(81,1,AQ,A)
 ALTSEQ CODE=(C8E8)


I will test this when I get a chance on Monday.
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: Sat Sep 21, 2013 1:22 pm
Reply with quote

"'H' and 'Y' as they come exactly from the first instance of eithers' occurrence"

If the answer to my previous question is different, the AQ would do it.
Back to top
View user's profile Send private message
K.Abhishek

New User


Joined: 21 Sep 2013
Posts: 2
Location: India

PostPosted: Sat Sep 21, 2013 4:36 pm
Reply with quote

Bill

Thanks, will come back on the process mentioned by you by Tuesday

As for your queries ,
I assume that whichever of H or Y comes first, all the H and Y are to be sorted at that position?
[Abhishek] -- Actually if you see the results shown below you would understand how it was required .
Elegant? You mean code that is easy to understand?
[Abhishek] -- I meant simple and small , not involving too many functions


agkshirsagar :Thankyou , I am sharing the results

Sort card used
Code:
OPTION EQUALS         
SORT FIELDS=(1,1,AQ,A)
 ALTSEQ CODE=(C8E8)   

results

Input
Code:
A 00000100
C 00000200
Z 00000300
H 00000400
Y 00000500
M 00000600
Y 00000700
D 00000800
B 00000900
H 00001000


Output
Code:
A 00000100
B 00000900
C 00000200
D 00000800
M 00000600
H 00000400
Y 00000500
Y 00000700
H 00001000
Z 00000300



changed ALTSEQ CODE=(C8E8) to (E8C8) got the result I wanted
Output
Code:
A 00000100
B 00000900
C 00000200
D 00000800
H 00000400
Y 00000500
Y 00000700
H 00001000
M 00000600
Z 00000300
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: Sat Sep 21, 2013 4:55 pm
Reply with quote

Well, happy if you are. Please describe your requirements better if there is a next time.

So Y is always to be sorted as H. Although we can't see that from your results. Even the "outsort" becomes ludicrously simple, but the ALTSEQ is more elegant.

agkshirsagar, good intuition.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Mon Sep 23, 2013 8:25 pm
Reply with quote

Thanks, Bill.

Abhishek, Glad to know it helped.
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
This topic is locked: you cannot edit posts or make replies. Automation need help in sorting the data DFSORT/ICETOOL 38
No new posts Sorting a record spanned over multipl... DFSORT/ICETOOL 13
No new posts selectively copy based on condition DFSORT/ICETOOL 3
No new posts Creating additional seqnum/Literal wh... DFSORT/ICETOOL 4
No new posts ICETOOL Sorting and Discarding DUPS SYNCSORT 11
Search our Forums:

Back to Top