Need Help Creating Two-dimensional Array



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Need Help Creating Two-dimensional Array

Postby mercurydrug » Mon Sep 13, 2010 8:45 pm

hello experts,

can you please give me a hint on how to make a 5x5 two-dimensional array, with DISPLAY and ACCEPT commands, and with sorting too.
this is the output i'd like to have..

Year----------Salesman----------Salesman----------Salesman----------Salesman----------Salesman----------Total
-----------------name1-------------name2--------------name3-------------name4--------------name5


2005----------(integer inputs for sales of each salesman, 5 times)-------------------------------------------(total sales of the year)
2006
2007
2008
2009

Total----------(total sales for each salesman)

Highest sales of salesman _________ is ______.
Lowest sales of salesman _________ is ______.
Year with the lowest sales:
Year with the highest sales:



i finished the 1 dimensional array for name, but i have no idea on how to add the two-dimensional arrays, and then sort it just to find the highest and lowest values for the inputs of each salesman and for each year..

i dont intend to make this your homework, i just need some help to know how to declare and perform the two-dimensional array and the SORTING part..

THnx in advance..
mercurydrug
 
Posts: 5
Joined: Mon Sep 13, 2010 8:26 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Need Help Creating Two-dimensional Array

Postby Robert Sample » Mon Sep 13, 2010 9:24 pm

05  WS-SALES              OCCURS 5
                          INDEXED BY SALES-IDX.
    10  WS-NAME           PIC X(20).
    10  WS-YEAR           PIC 9(04).
    10  WS-SALES-DATA     OCCURS 5
                          INDEXED BY YEAR-IDX.
        15  WS-GROSS      PIC 9(06).
Professional programs almost never use ACCEPT statements -- READ is the preferred way to get input into a program.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Need Help Creating Two-dimensional Array

Postby mercurydrug » Mon Sep 13, 2010 9:46 pm

thanks! but umm, im still new to COBOL, can i ask what 'INDEXED BY' does?

sorry to bother you sir..
mercurydrug
 
Posts: 5
Joined: Mon Sep 13, 2010 8:26 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Need Help Creating Two-dimensional Array

Postby Robert Sample » Mon Sep 13, 2010 10:32 pm

The IBM web site has all the COBOL manuals on it: http://www-01.ibm.com/software/awdtools/cobol/zos/library/ and you need to bookmark this site so you can read up on things like INDEXED BY.

The INDEXED BY variable allows you to access table entries without requiring a subscript variable.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Need Help Creating Two-dimensional Array

Postby mercurydrug » Mon Sep 13, 2010 10:35 pm

thanks again sir Robert, i might have to read this first, ahaha, but with a little pressure 'coz this will be passed on wednesday O_O
mercurydrug
 
Posts: 5
Joined: Mon Sep 13, 2010 8:26 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Need Help Creating Two-dimensional Array

Postby Robert Sample » Mon Sep 13, 2010 10:39 pm

In that case, just forget the INDEXED BY -- the data structure I provided will still accomplish your goals if you use subscript variables.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Need Help Creating Two-dimensional Array

Postby mercurydrug » Tue Sep 14, 2010 7:44 am

umm, sir, but how do i perform this in the procedure division? im still missing that, sorry T_T
mercurydrug
 
Posts: 5
Joined: Mon Sep 13, 2010 8:26 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Need Help Creating Two-dimensional Array

Postby Robert Sample » Tue Sep 14, 2010 8:25 am

Create two variables, call them WS-ROW and WS-COL, outside the table.

    PERFORM ROW-PARA VARYING WS-ROW FROM 1 BY 1 UNTIL WS-ROW > 5.
.
.
.
ROW-PARA.
    PERFORM COL-PARA VARYING WS-COL FROM 1 BY 1 UNTIL WS-COL > 5.
.
.
.
COL-PARA.
You'll need to add counter variables to accumulate the sales totals as your post indicated -- but you have to do some of the work yourself; you've been given 75% of what you need -- surely you can figure out the rest. If not, you may want to reconsider your career choice as logical thinking is a very important part of IT.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Need Help Creating Two-dimensional Array

Postby mercurydrug » Tue Sep 14, 2010 8:52 am

sorry sir, T_T i kinda though of what you said, and im just not sure if its right and my mistake was not trying it..
sorry, maybe the effect of pressure, and thanks a lot, i learned a lot sir :D
mercurydrug
 
Posts: 5
Joined: Mon Sep 13, 2010 8:26 pm
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post