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

problem facing in Array Sorting in COBOL


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 54
Location: Madrid

PostPosted: Mon Sep 03, 2007 8:18 pm
Reply with quote

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
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Mon Sep 03, 2007 8:43 pm
Reply with quote

Boy, does that code su**....
Go look at this Bubble Sort....
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Mon Sep 03, 2007 11:11 pm
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Sep 04, 2007 2:11 am
Reply with quote

If, as indicated, the filler does not matter, go with the solution....
Back to top
View user's profile Send private message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 54
Location: Madrid

PostPosted: Tue Sep 04, 2007 6:38 am
Reply with quote

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
View user's profile Send private message
balakrishna reddy

Active User


Joined: 13 Jul 2007
Posts: 128
Location: Guntur

PostPosted: Tue Sep 04, 2007 11:34 am
Reply with quote

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
View user's profile Send private message
balakrishna reddy

Active User


Joined: 13 Jul 2007
Posts: 128
Location: Guntur

PostPosted: Tue Sep 04, 2007 11:44 am
Reply with quote

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
View user's profile Send private message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 54
Location: Madrid

PostPosted: Tue Sep 04, 2007 12:06 pm
Reply with quote

[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
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top