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

COBOL Ascending and descending sort number array


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

New User


Joined: 05 Nov 2022
Posts: 2
Location: United States

PostPosted: Sat Nov 05, 2022 11:26 pm
Reply with quote

Hello everyone, I have chosen to used COBOL to write a quick program for a class I am taking and I have the basic coding down, I have an array that holds 10 numbers and I need to sort them either ascending or descending. I need to use a simple menu that gives the user (teacher) the option to pick which sort he wants. The menu and the sorting is what has me stumped right now. I hope someone can help ASAP. I do appreciate all of your help.

I would also love all advice on how to improve my code.

Here is the code so far:
Code:


WORKING-STORAGE SECTION.       
       *> Declare a single digit integer between 0-9
       *> with a starting value of 0
       *> ZEROS is a constant equal to 0
       01 NUMBER-TABLE.
           05 NUMBER-PRD OCCURS 10 TIMES PIC X(9).
       01 Num0 PIC 9 VALUE ZEROS.
       01 counter PIC  S999 VALUE 1.
       01 MyLoop PIC 99.
       
      *----------------------       
       PROCEDURE DIVISION.
      *----------------------
      *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
       MAIN-PROCEDURE.
      **
      * The main procedure of the program
      **   
           DISPLAY "############################################### ".
           DISPLAY "############################################### ".
           DISPLAY "Enter 1st number : ".
           ACCEPT NUMBER-PRD(1).
           DISPLAY "Enter 2nd number : ".
           ACCEPT NUMBER-PRD(2).
           DISPLAY "Enter 3rd number : ".
           ACCEPT NUMBER-PRD(3).
           DISPLAY "Enter 4th number : ".
           ACCEPT NUMBER-PRD(4).
           DISPLAY "Enter 5th number : ".
           ACCEPT NUMBER-PRD(5).
           DISPLAY "Enter 6th number : ".
           ACCEPT NUMBER-PRD(6).
           DISPLAY "Enter 7th number : ".
           ACCEPT NUMBER-PRD(7).
           DISPLAY "Enter 8th number : ".
           ACCEPT NUMBER-PRD(8).
           DISPLAY "Enter 9th number : ".
           ACCEPT NUMBER-PRD(9).
           DISPLAY "Enter 10th number : ".
           ACCEPT NUMBER-PRD(10).
           DISPLAY "HERE ARE YOUR NUMBERS: ".
           DISPLAY" NUMBER 1: " NUMBER-PRD(1).
           DISPLAY" NUMBER 2: " NUMBER-PRD(2).
           DISPLAY" NUMBER 3: " NUMBER-PRD(3).
           DISPLAY" NUMBER 4: " NUMBER-PRD(4).
           DISPLAY" NUMBER 5: " NUMBER-PRD(5).
           DISPLAY" NUMBER 6: " NUMBER-PRD(6).
           DISPLAY" NUMBER 7: " NUMBER-PRD(7).
           DISPLAY" NUMBER 8: " NUMBER-PRD(8).
           DISPLAY" NUMBER 9: " NUMBER-PRD(9).
           DISPLAY" NUMBER 10: " NUMBER-PRD(10).
           
           
           
           
           STOP RUN.


Thank you,
Jim
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 1650

PostPosted: Sun Nov 06, 2022 12:21 am
Reply with quote

Before COBOL, you strongly need to find and to learn the SORT algorithm.

There are plenty of them. Use Google Search on “sort algorithm”
Back to top
View user's profile Send private message
JimBrumbaugh

New User


Joined: 05 Nov 2022
Posts: 2
Location: United States

PostPosted: Sun Nov 06, 2022 1:54 am
Reply with quote

sergeyken wrote:
Before COBOL, you strongly need to find and to learn the SORT algorithm.

There are plenty of them. Use Google Search on “sort algorithm”


Thank you sir for the input and I agree it would be a great idea to understand the sorting algorithm prior to trying this but I do not have a few weeks to figure this out, I need to turn in the work tomorrow. So just a few pointers ot tips would be a huge help icon_smile.gif

Jim
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 1650

PostPosted: Sun Nov 06, 2022 3:47 am
Reply with quote

JimBrumbaugh wrote:
sergeyken wrote:
Before COBOL, you strongly need to find and to learn the SORT algorithm.

There are plenty of them. Use Google Search on “sort algorithm”


Thank you sir for the input and I agree it would be a great idea to understand the sorting algorithm prior to trying this but I do not have a few weeks to figure this out, I need to turn in the work tomorrow. So just a few pointers ot tips would be a huge help icon_smile.gif

Jim

It took me about 10 seconds to find an almost ready-to-use solution:

CODING COBOL: A BUBBLESORT

I will never adjust it to your specific variable names etc.
If you are not able to do it by yourself, then I strongly recommend you to change your job. Seriously.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2963
Location: NYC,USA

PostPosted: Sun Nov 06, 2022 9:43 am
Reply with quote

Welcome!
Basic question - How are you planning to give a menu ? CICS ?
www.ibm.com/docs/en/cobol-zos/6.2?topic=tables-sorting-table
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 745
Location: Whitby, ON, Canada

PostPosted: Mon Nov 07, 2022 3:29 am
Reply with quote

FYI for the non students: IBM Enterprise COBOL now has built in support for sorting tables defined in the Data Division. The SORT verb accepts a table as input.
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 Can EATTR be coded in an IMS COBOL pgm? IMS DB/DC 1
No new posts Cobol transactions in SYSVIEW COBOL Programming 0
No new posts executing XCTL command in COBOL witho... CICS 4
No new posts JCL SORT to compress the student's de... DFSORT/ICETOOL 7
No new posts Capturing COBOL job and program names... All Other Mainframe Topics 2
Search our Forums:

Back to Top