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).
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.
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.