ON COND(I_EOFC_D0) 怎么触发,请举例说明, PL/1
时间: 2023-11-28 08:47:38 浏览: 66
ON COND(I_EOFC_D0)是一种PL/1语言的异常处理机制,用于在遇到指定的异常情况时执行相应的操作。
具体来说,I_EOFC_D0是一个预定义的异常条件码,表示在读取输入数据时到达文件结尾(End-Of-File)。当程序运行到ON COND(I_EOFC_D0)时,如果遇到这种异常情况,就会执行后续的处理代码,否则会继续正常执行。
以下是一个示例代码,用于从文件中读取数据并进行处理:
```
DCL INFILE FILE RECORD INPUT;
DCL EOF_IND BIT(1) INIT(0);
OPEN FILE(INFILE INPUT) NAME('inputfile.txt');
READ FILE(INFILE) INTO(RECORD) END(FILE_END) ERROR(FILE_ERROR);
/* 如果到达文件末尾,设置EOF标志位 */
IF FILE_END THEN DO;
EOF_IND = 1;
END;
/* 如果遇到文件结尾异常,执行相应的处理 */
ON COND(I_EOFC_D0);
EOF_IND = 1;
END;
/* 其他异常情况的处理 */
ON ERROR;
PUT SKIP LIST('Error reading input file');
END;
DO WHILE(NOT EOF_IND);
/* 处理数据 */
...
READ FILE(INFILE) INTO(RECORD) END(FILE_END) ERROR(FILE_ERROR);
/* 如果到达文件末尾,设置EOF标志位 */
IF FILE_END THEN DO;
EOF_IND = 1;
END;
END;
CLOSE FILE(INFILE);
```
在上面的示例中,如果程序读取到文件末尾,就会设置EOF_IND标志位为1,然后执行ON COND(I_EOFC_D0)中指定的处理代码,即再次将EOF_IND标志位设置为1。这样可以确保程序能够正确处理所有的数据。
阅读全文
相关推荐

















