Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Sorting an Array

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Sorting an Array
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    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10326
Location: italy

PostPosted: Fri Dec 28, 2007 12:46 pm    Post subject: Reply to: Sorting an Array
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    Post subject:
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    Post subject: Reply to: Sorting an Array
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: 149
Location: Ottawa Canada

PostPosted: Fri Jan 04, 2008 11:05 pm    Post subject:
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    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 Sorting on text - but in non-alphabet... Roy Ware SYNCSORT 5 Wed Aug 23, 2017 9:15 pm
No new posts Sorting of hex values Saurabh_mi DFSORT/ICETOOL 11 Thu May 25, 2017 3:49 pm
No new posts Dynamic array request/response contai... Suja.Sai CICS 2 Tue Jan 24, 2017 11:37 am
No new posts Sorting group data rajella DFSORT/ICETOOL 4 Sun Jan 22, 2017 11:32 pm
No new posts Efficient sorting chandracdac DFSORT/ICETOOL 5 Sat Oct 22, 2016 3:23 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us