Rational Developer for System z
Enterprise PL/I for z/OS, Version 3.8, Language Reference Manual

ON-units for file variables

An ON statement that specifies a file variable refers to the file constant that is the current value of the variable when the ON-unit is established.

Example 1

dcl  F file,
     G file variable;
     G = F;
L1:  on endfile(G);
L2:  on endfile(F);

The statements labeled L1 and L2 are equivalent.

Example 2

declare FV file variable,
FC1 file,
FC2 file;
FV = FC1;
on endfile(FV) go to Fin;

·
·
·
FV = FC2; read file(FC1) into (X1); read file(FV) into (X2);

An ENDFILE condition raised during the first READ statement causes the ON-unit to be entered, because the ON-unit refers to file FC1. If the condition is raised in the second READ statement, however, the ON-unit is not entered, because this READ refers to file FC2.

Example 3

E:  procedure;
declare F1 file;
on endfile (F1) goto L1;
call E1 (F1);

·
·
·
E1: procedure (F2); declare F2 file; on endfile (F2) go to L2; read file (F1); read file (F2); end E1;

An end-of-file encountered for F1 in E1 causes the ON-unit for F2 in E1 to be entered. If the ON-unit in E1 was not specified, an ENDFILE condition encountered for either F1 or F2 would cause entry to the ON-unit for F1 in E.

Example 4

declare FV file variable,
FC1 file,
FC2 file;

 
do FV=FC1,FC2;
on endfile(FV) go to Fin;
end;

If an ON statement specifying a file variable is executed more than once, and the variable has a different value each time, a different ON-unit is established at each execution.


Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)