View previous topic :: View next topic
|
Author |
Message |
sreekusr Warnings : 1 New User
Joined: 28 Aug 2006 Posts: 54 Location: Madrid
|
|
|
|
Hi,
following is the scenario.
an array having the following format
01 Array
05 arrayA occurs 20 times
10 fieldA pic x(05).
10 Fieldb.
20 First pic x(03).
20 filler pix x(04).
20 second pic x(03).
10 fieldC pic x(05).
objective is to sort on the ascending order of
Field B(i.e on the values of First and Second)
following is the values in i/p array of field B,field A and C can have
other values
FieldB
First Filler Second
CDE CCC
ABC BBB
BCD AAA
ABC AAA
the Expected O/p after sorting
ABC AAA
ABC BBB
BCD AAA
CDE CCC
following is the perform we put fot it
i and J are WS variables
perform varying i from 1 by 1 until i > 20
perform varying j from 1 by 1 until i > 20
Fieldb (I) > Fieldb (J)
MOVE arrayA(I) TO TEMP
MOVE arrayA(j) TO arrayA(I)
MOVE TEMP TO arrayA(I)
END-PERFORM
END-PERFORM.
The O/p of the above logic is sorting only based on the values of
Field FIRST of FieldB.
Hope my query make sense.Please help me out in this.
Thanks,
Sree |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Boy, does that code su**....
Go look at this Bubble Sort.... |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
What are the values in filler between first and second, those values will effect the sort order. Is filler always set to the same value? And please look at different approaches for sorting arrays internally. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
If, as indicated, the filler does not matter, go with the solution.... |
|
Back to top |
|
|
sreekusr Warnings : 1 New User
Joined: 28 Aug 2006 Posts: 54 Location: Madrid
|
|
|
|
Hi All,
thanks for the response
Please let me know which one of the solution should i follow
and please let me know why the code that i mentioned is not
working in this case.
thanks,
sree |
|
Back to top |
|
|
balakrishna reddy
Active User
Joined: 13 Jul 2007 Posts: 128 Location: Guntur
|
|
|
|
Hi Sree,
Code: |
perform varying i from 1 by 1 until i > 20
perform varying j from 1 by 1 until i > 20
|
Its look a bit confusing, Wouldn't it go in infinite loop since you are checking only for i in both the performs. |
|
Back to top |
|
|
balakrishna reddy
Active User
Joined: 13 Jul 2007 Posts: 128 Location: Guntur
|
|
|
|
Hi Sree,
Code: |
perform varying i from 1 by 1 until i > 20
perform varying j from 1 by 1 until i > 20
|
Its look a bit confusing, Wouldn't it go in infinite loop since you are checking only for i in both the performs. |
|
Back to top |
|
|
sreekusr Warnings : 1 New User
Joined: 28 Aug 2006 Posts: 54 Location: Madrid
|
|
|
|
[perform varying i from 1 by 1 until i > 20
perform varying j from 1 by 1 until i > 20
Fieldb (I) > Fieldb (J)
MOVE arrayA(I) TO TEMP
MOVE arrayA(j) TO arrayA(I)
MOVE TEMP TO arrayA(J)
END-PERFORM
END-PERFORM.
]
Sorry for the typing mistake.
This time the code worked properly.
Previously the code was not working because the i/p array which i was trying to sort was not proper as the filler field conatined some high values.
After initializing the variables above code gave o/p as expected.
Thanks a lot for the replies.
Sree[/code] |
|
Back to top |
|
|
|