Page 1 of 1

Need Help Creating Two-dimensional Array

PostPosted: Mon Sep 13, 2010 8:45 pm
by mercurydrug
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..

Re: Need Help Creating Two-dimensional Array

PostPosted: Mon Sep 13, 2010 9:24 pm
by Robert Sample
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.

Re: Need Help Creating Two-dimensional Array

PostPosted: Mon Sep 13, 2010 9:46 pm
by mercurydrug
thanks! but umm, im still new to COBOL, can i ask what 'INDEXED BY' does?

sorry to bother you sir..

Re: Need Help Creating Two-dimensional Array

PostPosted: Mon Sep 13, 2010 10:32 pm
by Robert Sample
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.

Re: Need Help Creating Two-dimensional Array

PostPosted: Mon Sep 13, 2010 10:35 pm
by mercurydrug
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

Re: Need Help Creating Two-dimensional Array

PostPosted: Mon Sep 13, 2010 10:39 pm
by Robert Sample
In that case, just forget the INDEXED BY -- the data structure I provided will still accomplish your goals if you use subscript variables.

Re: Need Help Creating Two-dimensional Array

PostPosted: Tue Sep 14, 2010 7:44 am
by mercurydrug
umm, sir, but how do i perform this in the procedure division? im still missing that, sorry T_T

Re: Need Help Creating Two-dimensional Array

PostPosted: Tue Sep 14, 2010 8:25 am
by Robert Sample
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.

Re: Need Help Creating Two-dimensional Array

PostPosted: Tue Sep 14, 2010 8:52 am
by mercurydrug
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