Page 1 of 1

Dynamic 2 dimensional array

PostPosted: Sat Sep 11, 2010 7:55 pm
by Ovia
Hi All,

I have a table declartion as follows:
01 EMPLOYEE-TABLE.                                 
 05 EMPLOYEE-COUNT               PIC 9(03).         
 05 EMPLOYEE-TBL   OCCURS 999 TIMES               
                       DEPENDING ON EMPLOYEE-COUNT   
                       INDEXED BY EMPLOYEE-COUNT-IDX.
    10 EMPLOYEE-NM            PIC X(30).         
    10 DEPARTMENT-CNT          PIC 9(03).         
    10 DEPT-TBL OCCURS 1 TO 20 TIMES           
                       DEPENDING ON DEPT-CNT   
                       INDEXED BY DEPT-IDX.     
       15 DEPT-NAME           PIC X(30).   



I have also defined DEPT-CNT in Working storage as 01 DEPT-CNT PIC 9(03).

When I try to populate this 2 dimensional array, I am getting over lay problems.

My piece of code to populate this array is:

ADD 1                                                 TO EMPLOYEE-COUNT               
SET EMPLOYEE-COUNT-IDX        TO EMPLOYEE-COUNT.       
SET DEPT-IDX                                   TO 1.                     
SET DATA-IDX                                 TO 1.                     
MOVE DATA-EMP-NM(DATA-IDX)
                                                             TO EMPLOYEE-NM (EMPLOYEE-COUNT-IDX).         
MOVE DATA-CNT
                                                             TO DEPARTMENT-CNT (EMPLOYEE-COUNT-IDX).       
INITIALIZE DEPT-CNT    .                                 
PERFORM UNTIL DEPT-CNT >= DATA-CNT                             
      MOVE DATA-DEPT-NM(DATA-IDX)        TO   DEPT-NAME(DEPT-IDX)           
      ADD 1                      TO DEPT-CNT 
       SET DEPT-IDX        UP BY 1           
       SET DATA-IDX       UP BY 1
END-PERFORM.       

The Dept count varies from employee to employee

For EG: Empl 1 can handle 2 dept and emp 2 can handle 4 depts.

Let me know where I am going wrong. Thanks!!

Regards,
Ovia.

Re: Dynamic 2 dimensional array

PostPosted: Sat Sep 11, 2010 9:43 pm
by dick scherrer
Hello,

When posting code, jcl, data, etc it is best to use the "Code" tag (your post has been "Code'd").

When I try to populate this 2 dimensional array, I am getting over lay problems.
Explain what is getting "overlayed".

Re: Dynamic 2 dimensional array

PostPosted: Sun Sep 12, 2010 6:45 am
by Robert Sample
One obvious problem: if you define the number of departments based on a counter that is not under the employee structure, you must manually change the variable DEPT-CNT for each employee or you'll be accessing data that is undefined or overlay existing data.