假设您的 VSAM 文件已正确初始化并且您的 JCL 的编码与您的程序要求一致,那么应该没有问题。
VARYING 子句只是告诉 COBOL 在缓冲区中为最大预期记录大小保留足够的空间,并指示文件包含预期在一次 I/O 调用到下一次的大小上会发生变化的记录。如果它是 FB(固定块),COBOL 期望记录是一个恒定大小,如果记录偏离预期大小,将触发状态代码 04。对于 VB(变量块),如果您的记录大小超过 VARYING 定义的最大限制,仍可能出现返回代码 04。
我个人觉得 COBOL I/O 状态条件有点难以理解。
这是一个 ANSI COBOL I/O 状态代码表,我可以方便地进行文件 i/o 调试:
0x - Successful Completion
00 - No futher information
02 - Duplicate Key detected
04 - Wrong Length Record
05 - File created when opened. With sequential VSAM 00 is returned.
07 - CLOSE with NO REWIND or REEL for non-tape dataset.
1x - End of File conditions
10 - No futher information
14 - Relative record READ outside boundry.
2x - Invalid Key condition
21 - Sequence Error
22 - Duplicate Key
23 - No Record found
24 - Key outside boundry
3x - Permanent I/O Errors
30 - No further information
34 - Record outside file boundry
35 - OPEN and required file not found.
37 - OPEN with invalid mode
38 - OPEN of file closed with a LOCK
39 - OPEN unsuccessful due to conflicting file attributes
4x - Logic Errors
41 - OPEN of file already open
42 - CLOSE of file not open
43 - READ not executed before REWRITE
44 - REWRITE of different size record
46 - READ after EOF reached
47 - READ attempted for file not opened I-O or EXTEND
48 - WRITE for file not opened OUTPUT, I-O, or EXTEND
49 - DELETE or REWRITE for file not opened I-O
9x - Specific Compiler defined exceptions
90 - No further information
91 - VSAM Password failure
92 - Logic Error
93 - VSAM Resource unavailable
94 - VSAM Sequence record not available
95 - VSAM invalid or incomplete file information
96 - VSAM no DD statement
97 - VSAM OPEN successful, file integrity verified.