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

Sorting an Array


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

New User


Joined: 26 Dec 2007
Posts: 8
Location: Chennai

PostPosted: Thu Dec 27, 2007 11:46 am
Reply with quote

Hi All,
If we have an array declared as
01 ARRY.
05 STUDENT PIC 9(06) OCCURS 12 TIMES.

Say, it has all the values declared, now we want to sort this array.....How is it possible.
Back to top
View user's profile Send private message
JAGAN_SRIRAM

New User


Joined: 21 Jul 2007
Posts: 4
Location: INDIA

PostPosted: Fri Dec 28, 2007 12:16 pm
Reply with quote

we cant do that directly, we have to go for bubble sort or quick sot method to sort the array
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Dec 28, 2007 12:46 pm
Reply with quote

Quote:
Say, it has all the values declared, now we want to sort this array.....How is it possible.


search the net and You will find a lot of samples
Back to top
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Fri Dec 28, 2007 1:55 pm
Reply with quote

mvkumar22,

Please check with the following sample cobol code for your requirement.
Code:
       IDENTIFICATION DIVISION.
       PROGRAM-ID. SORTTABL.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT SORT-FILE ASSIGN TO SORTFILE.
       DATA DIVISION.
       FILE SECTION.
       SD SORT-FILE.
       01 SORT-FILE-REC.
       02 STUDENT PIC 9(06) VALUE ZERO.
       WORKING-STORAGE SECTION.
       01 ARRY VALUE ZERO.
       05 ARRY-STUDENT PIC 9(06) OCCURS 12 TIMES.
       77 I PIC 99 VALUE ZERO.
       PROCEDURE DIVISION.
           PERFORM VARYING I FROM 1 BY 1 UNTIL I > 12
            ACCEPT ARRY-STUDENT(I)
            DISPLAY ARRY-STUDENT(I)
           END-PERFORM
           SORT SORT-FILE
           ON ASCENDING KEY STUDENT
           INPUT PROCEDURE I-P
           OUTPUT PROCEDURE O-P.
           PERFORM VARYING I FROM 1 BY 1 UNTIL I > 12
            DISPLAY ARRY-STUDENT(I)
           END-PERFORM
           GOBACK.
       I-P.
           PERFORM VARYING I FROM 1 BY 1 UNTIL I > 12
            RELEASE SORT-FILE-REC FROM ARRY-STUDENT(I)
           END-PERFORM.
       O-P.
           PERFORM VARYING I FROM 1 BY 1 UNTIL I > 12
            RETURN SORT-FILE INTO ARRY-STUDENT(I)
            AT END DISPLAY 'END'
            END-RETURN
           END-PERFORM.
Back to top
View user's profile Send private message
mvkumar22
Warnings : 1

New User


Joined: 26 Dec 2007
Posts: 8
Location: Chennai

PostPosted: Mon Dec 31, 2007 12:07 pm
Reply with quote

Hi Shankar,
Thanks 4 ur reply...........its working.Thanq
Back to top
View user's profile Send private message
TG Murphy

Active User


Joined: 23 Mar 2007
Posts: 148
Location: Ottawa Canada

PostPosted: Fri Jan 04, 2008 11:05 pm
Reply with quote

On December 10 I posted 2 copybooks that do exactly what you want to do. I asked folks to try them out. Nobody has responded yet which I did not expect because sorting is such a common requirement.

Why don't you give them a try? Based on what you describe you would use them as follows:

In your working storage section:

COPY SORTWORK.

In your procedure division:

COPY SORTPROC REPLACING
==:SUFFIX:== BY MYSORT
==:SORT-SEQUENCE:== BY SORT-ASCENDING
==:SORTROW:== BY STUDENT
==:SORTKEY:== BY STUDENT
==:NBR-OF-ELEMENTS:== BY 12

Read the post on Dec 10 for more details...
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
This topic is locked: you cannot edit posts or make replies. Automation need help in sorting the data DFSORT/ICETOOL 38
No new posts COBOL Ascending and descending sort n... COBOL Programming 5
No new posts Sorting a record spanned over multipl... DFSORT/ICETOOL 13
No new posts To find an array of words (sys-symbol... JCL & VSAM 9
No new posts How to move values from single dimens... COBOL Programming 1
Search our Forums:

Back to Top