JOB INPUT (FILE1 KEY (FILE1-KEY) +
FILE2 KEY (FILE2-KEY) +
) +
FINISH TOTALS
IF RECORD-COUNT(FILE1) = 1
WS-STORE-HEADER = FILE1-REC
END-IF
IF MATCHED
WS-MATCHED-COUNT = WS-MATCHED-COUNT + 1
ELSE
IF FILE1
FILEO-REC = FILE1-REC
PUT FILEO
WS-UNMATCHED0-COUNT = WS-UNMATCHED0-COUNT + 1
END-IF
IF FILE2
FILEO-REC = FILE2-REC
PUT FILEO
WS-UNMATCHED1-COUNT = WS-UNMATCHED1-COUNT + 1
END-IF
END-IF
GO TO JOB
TOTALS. PROC
IF WS-UNMATCHED0-COUNT = 0 AND WS-UNMATCHED1-COUNT = 0
FILEO-REC = WS-STORE-HEADER
PUT FILEO
END-IF
END-PROC.
FILE2 KEY (FILE2-KEY) +
) +
FINISH TOTALS
IF RECORD-COUNT(FILE1) = 1
WS-STORE-HEADER = FILE1-REC
END-IF
IF MATCHED
WS-MATCHED-COUNT = WS-MATCHED-COUNT + 1
ELSE
IF FILE1
FILEO-REC = FILE1-REC
PUT FILEO
WS-UNMATCHED0-COUNT = WS-UNMATCHED0-COUNT + 1
END-IF
IF FILE2
FILEO-REC = FILE2-REC
PUT FILEO
WS-UNMATCHED1-COUNT = WS-UNMATCHED1-COUNT + 1
END-IF
END-IF
GO TO JOB
TOTALS. PROC
IF WS-UNMATCHED0-COUNT = 0 AND WS-UNMATCHED1-COUNT = 0
FILEO-REC = WS-STORE-HEADER
PUT FILEO
END-IF
END-PROC.
This is some old code in production which fails with "A010 INVALID FILE REFERENCE - FILE1" when one of the files has just 1 record and the other has more than 1 records. For all other cases it works just fine.
Recrods in FILE1 Records in FILE2 JOB STATUS
0 0 SUCCESS
0 1 SUCCESS
0 M (Many) SUCCESS
1 0 SUCCESS
1 1 SUCCESS
1 M (Many) FAILS
M 0 SUCCESS
M 1 FAILS
M M (Many) SUCCESS
The program fails in the below highlighted statement. This is done so that there is atleast 1 record in the output file as the downstream is not designed to handle an empty file.
IF RECORD-COUNT(FILE1) = 1
WS-STORE-HEADER = FILE1-REC
END-IF
I think it has something to do with the way the synchronised file read happens in easytrieve.
Also, if there are 2 records in one of the file and more than 2 in the other the below code fails with the same error.
IF RECORD-COUNT(FILE1) = 2
WS-STORE-HEADER = FILE1-REC
END-IF
I have a solution in place but I just want to know why it is failing.