Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Processing 2

Status
Not open for further replies.

cfranks

MIS
Apr 10, 2002
5
US
I am doing a project that deals with 2d array. I am having trouble with add 1 to the array to load the data into it. I am getting the message that the operand needs to be numeric. I have set it up to be numeric. I am not sure why this is happening


IDENTIFICATION DIVISION.
PROGRAM-ID. PROJECT4.
AUTHOR. CHAD FRANKS.
DATE-WRITTEN. APRIL 23, 2002.

******************************************************************
* THIS PROGRAM WILL DISPLAY THE AMOUNT OF EMPLOYEES PER
* DEPARTMENT FOR EACH AREA.
******************************************************************


ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.

SELECT EMP-FILE ASSIGN TO
'A:\EMP-FILE.DAT'
ORGANIZATION IS LINE SEQUENTIAL.

SELECT PRINT-FILE ASSIGN TO
'A:\PRINT.rpt'
ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.

******************************************************************
* THIS IS THE INPUT SECTION OF THE PROGRAM.
******************************************************************


FD EMP-FILE LABEL RECORDS ARE STANDARD.
01 EMP-REC.
05 DEPT-IN PIC 99.
05 AREA-IN PIC 99.
05 EMP-INFO PIC X(76).

FD PRINT-FILE LABEL RECORDS ARE STANDARD.
01 PRINT-REC PIC X(80).



WORKING-STORAGE SECTION.

01 ARE-THERE-MORE-RECORDS PIC X(3) VALUE 'YES'.


01 WS-COUNTERS.
05 WS-REC-CT PIC 999.
05 WS-ERR-CT PIC 999.
05 WS-WRITE-REC-CT PIC 999.
05 SUB1 PIC 99 VALUE 1.
05 SUB2 PIC 99 VALUE 1.


01 WS-DATE.
05 RUN-YEAR PIC 9999.
05 RUN-MONTH PIC 99.
05 RUN-DAY PIC 99.




01 DL-TITLE.
05 PIC X(30) VALUE SPACES.
05 PIC X(47)
VALUE 'TOTAL NO OF EMPLOYEES BY AREA WITHIN DEPARTMENT'.
05 PIC X(3) VALUE SPACES.
05 DATE-OF-RUN.
10 MON-OUT PIC 99.
10 PIC X VALUE '/'.
10 DAY-OUT PIC 99.
10 PIC X VALUE '/'.
10 YEAR-OUT PIC 9999.



01 DL-AREA-HEADINGS.
05 PIC X(20) VALUE SPACES.
05 PIC X(5) VALUE 'AREA1'.
05 PIC X(5) VALUE SPACES.
05 PIC X(5) VALUE 'AREA2'.
05 PIC X(5) VALUE SPACES.
05 PIC X(5) VALUE 'AREA3'.
05 PIC X(5) VALUE SPACES.
05 PIC X(5) VALUE 'AREA4'.
05 PIC X(5) VALUE SPACES.
05 PIC X(5) VALUE 'AREA5'.
05 PIC X(5) VALUE SPACES.
05 PIC X(5) VALUE 'AREA6'.



01 DETAIL-LINE.
05 PIC X(28) VALUE SPACES.
05 DEPT PIC X(5) VALUE 'DEPT-'.
05 DEPT-OUT PIC Z9.
05 PIC X(10) VALUE SPACES.
05 OUT-ROW OCCURS 6 TIMES.
10 OUT-NUM PIC Z9.
10 PIC X(2) VALUE SPACES.



01 TOTALS.
05 PIC X(4) VALUE SPACES.
05 REC-READ-OUT PIC X(12)
VALUE 'RECORDS READ'.
05 PIC X(4) VALUE SPACES.
05 ERROR-OUT PIC X(19)
VALUE 'RECORDS WITH ERRORS'.
05 PIC X(4) VALUE SPACES.
05 PRINTED-OUT PIC X(15)
VALUE 'RECORDS PRINTED'.



01 DEPT-TOTALS.
05 DEPT-1 OCCURS 10 TIMES.
10 AREA-1 OCCURS 6 TIMES.
15 EMP-NUM PIC 99.



PROCEDURE DIVISION.

100-MAIN-MODULE.

OPEN INPUT EMP-FILE
OUTPUT PRINT-FILE
PERFORM 120-INITIALIZE-WS-COUNTERS
PERFORM UNTIL ARE-THERE-MORE-RECORDS = ' NO'
READ EMP-FILE
AT END
MOVE 'NO' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 300-VALIDATION
ADD 1 TO WS-REC-CT
END-READ
END-PERFORM
Perform 500-detail
PERFORM 600-TOTALS
CLOSE EMP-FILE
CLOSE PRINT-FILE
STOP RUN.


120-INITIALIZE-WS-COUNTERS.

INITIALIZE WS-COUNTERS.

PERFORM 200-WRITE-HEADINGS.



200-WRITE-HEADINGS.
MOVE FUNCTION CURRENT-DATE TO WS-DATE
MOVE RUN-MONTH TO MON-OUT
MOVE RUN-DAY TO DAY-OUT
MOVE RUN-YEAR TO YEAR-OUT
WRITE PRINT-REC FROM DL-TITLE.
WRITE PRINT-REC FROM DL-AREA-HEADINGS.


300-VALIDATION.
IF (DEPT-IN >= 0 AND < 11)
AND (AREA-IN >= 0 AND < 07)
ADD 1 TO EMP-NUM (DEPT-1, DEPT-1)
ELSE ADD 1 TO WS-ERR-CT
END-IF.


500-DETAIL.
*MOVE SPACES TO DETAIL-LINE
*MOVE SPACES TO PRINT-REC

PERFORM VARYING SUB1 FROM 1 BY 1
UNTIL SUB1 > 10
MOVE SUB1 TO DEPT-OUT
PERFORM VARYING SUB2 FROM 1 BY 1
UNTIL SUB2 > 6
MOVE EMP-NUM (SUB1, SUB2) TO OUT-NUM (SUB2)
END-PERFORM
ADD 1 TO WS-WRITE-REC-CT
WRITE PRINT-REC FROM DETAIL-LINE
END-PERFORM.

600-TOTALS.

MOVE WS-WRITE-REC-CT TO PRINTED-OUT
MOVE WS-ERR-CT TO ERROR-OUT
MOVE WS-REC-CT TO REC-READ-OUT

WRITE PRINT-REC FROM TOTALS

 
You are most likely having a problem with:
Code:
ADD 1 TO EMP-NUM (DEPT-1, DEPT-1)

It is DEPT-1 that is nonnumeric.

You probably want:
Code:
ADD 1 TO EMP-NUM (DEPT-IN, AREA-IN)

Some of the paragraph names appear to be in the wrong column.

Hope you &quot;find this helpful.&quot;


Tom Morrison
 
Now I am getting a invalid character in numeric field in the emp-num..

arrrrgh!!!!

Chad
 
The EMP-NUM array is never initialized, perhaps?
Tom Morrison
 
Doesn't a perform varying initialize an array?

Chad F
 
Chad,

The short answer is: No.

Sorry.
Tom Morrison
 
Him

I added the line
INITIALIZE DEPT-TOTALS. Would this be the correct statement to initialize the array?
 
I got it to process all the records, but at the end its telling error 146 no current record defined for sequential read

Chad
 
This is usually caused by attempting to READ after you have done your AT END processing. Use the debugger, put a breakpoint in your AT END processing and then step through statement by statement. You will probably quickly determine the logic error.
Tom Morrison
 
Hey, Chad! Tom has given you a LOT of help! How about marking him as helpful?

Stephen J Spiro
 
All that help and Chad just disappears into the woodwork....

Ah well, Tom, I thought it was helpful. Your star is in the mail. :)

Regards, Jack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top