Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

problem facing in Array Sorting in COBOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 50
Location: London

PostPosted: Mon Sep 03, 2007 8:18 pm    Post subject: problem facing in Array Sorting in COBOL
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: 2150
Location: At my coffee table

PostPosted: Mon Sep 03, 2007 8:43 pm    Post subject:
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    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Tue Sep 04, 2007 2:11 am    Post subject:
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: 50
Location: London

PostPosted: Tue Sep 04, 2007 6:38 am    Post subject: Reply to: problem facing in Array Sorting in COBOL
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: 130
Location: Guntur

PostPosted: Tue Sep 04, 2007 11:34 am    Post subject:
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: 130
Location: Guntur

PostPosted: Tue Sep 04, 2007 11:44 am    Post subject:
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: 50
Location: London

PostPosted: Tue Sep 04, 2007 12:06 pm    Post subject: Reply to: problem facing in Array Sorting in COBOL
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Strings with double quotes having pro... raja Arumugam IBM Tools 0 Thu Mar 30, 2017 10:34 am
No new posts RULES(NOEVENPACK) in cobol jackzhang75 COBOL Programming 5 Wed Mar 29, 2017 12:47 am
No new posts Problem reading GTF trace output danik56 ABENDS & Debugging 7 Thu Mar 16, 2017 1:02 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Execute TSO ACF commands from COBOL-I... supreethi.srid TSO/ISPF 0 Tue Feb 21, 2017 5:19 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us