Created On: 19 April 2011
Problem:
An issue has been found where a NESTED program containing a GLOBAL file with a split ALTERNATE key referenced in one of the sub programs returns the compiler error: ‘COBCH0012S Operand alt-key-definition is not declared’ – where alt-key-definition is the ALTERNATE access key as defined in the SELECT statement.
This was encountered in Net Express 5.1, but seems not to have been an issue in Net Express 3.1. So in exactly which version it happened is not clear, but it could have been as far back as Net Express 4.0.
Take the following SELECT statement for an INDEXED file in the calling program (as this is in a NESTED program the file does not need to be defined in the called sub programs):
SELECT TESTFILE
ASSIGN TO “TESTFILE.DAT”
ORGANIZATION IS INDEXED
ACCESS IS DYNAMIC
RECORD KEY IS TEST-KEY
ALTERNATE RECORD KEY TEST-ALT-KEY = TEST-KEY-2
TEST-KEY-3 DUPLICATES
FILE STATUS IS FILE-STAT.
ASSIGN TO “TESTFILE.DAT”
ORGANIZATION IS INDEXED
ACCESS IS DYNAMIC
RECORD KEY IS TEST-KEY
ALTERNATE RECORD KEY TEST-ALT-KEY = TEST-KEY-2
TEST-KEY-3 DUPLICATES
FILE STATUS IS FILE-STAT.
And then, with the FD specified as follows:
FD TESTFILE GLOBAL.
01 TEST-DATA-REC GLOBAL.
05 TEST-KEY.
10 TEST-KEY-1 PIC X(10).
10 TEST-KEY-2 PIC X(10).
10 TEST-KEY-3 PIC X(10).
05 TEST-DATA.
10 FILLER PIC X(80).
01 TEST-DATA-REC GLOBAL.
05 TEST-KEY.
10 TEST-KEY-1 PIC X(10).
10 TEST-KEY-2 PIC X(10).
10 TEST-KEY-3 PIC X(10).
05 TEST-DATA.
10 FILLER PIC X(80).
And then in the PROCEDURE DIVISION:
START TESTFILE KEY IS > TEST-ALT-KEY
INVALID KEY
MOVE 1 TO WF-END-FILE.
MOVE 1 TO WF-END-FILE.
Note the manner in which the ALTERNATE key is specified in the SELECT statement. Also, note that the file is specified as GLOBAL, meaning this record structure is able to be referenced directly by any sub program without the SELECT or FD having to be included in the sub program.
Note that the PROCEDURE DIVISION code is written to access the ALTERNATE RECORD KEY (eg a START on the ALT key). If the START is coded in the top level calling program it compiles fine. But if the code to access the ALTERNATE RECORD KEY is in the sub (i.e. called) program it will return the error: COBCH0012S Operand TEST-ALT-KEY is not declared.Resolution:
Firstly, this was found to be an error and was to be fixed in Net Express 5.1 WS6, Net Express 6.0 SP2 and VisualCOBOL R1.3.
However, if you are unable to upgrade to any of these versions immediately, there is a workaround. This requires changing both the SELECT statement and the GLOBAL FD.
SELECT TESTFILE
ASSIGN TO "TESTFILE.DAT"
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS TEST-KEY
ALTERNATE RECORD KEY TEST-ALT-KEY DUPLICATES
FILE STATUS IS FILE-STAT.
FILE STATUS IS FILE-STAT.
And then the FD
FD TESTFILE GLOBAL.
FD TESTFILE GLOBAL.
01 TEST-DATA-REC GLOBAL.
05 TEST-KEY.
10 TEST-KEY-1 PIC X(10).
10 TEST-KEY-1 PIC X(10).
05 TEST-ALT-KEY.
10 TEST-KEY-2 PIC X(10).
10 TEST-KEY-3 PIC X(10).
05 TEST-DATA.
10 FILLER PIC X(80).
10 TEST-KEY-2 PIC X(10).
10 TEST-KEY-3 PIC X(10).
05 TEST-DATA.
10 FILLER PIC X(80).
Old KB# 33912



