Here’s a sample which is narrowed down from a code of our production system.
define data local
1 #i1 (I1)
for #i1 = 1 to 5
define subroutine sub-esc
callnat 'ESCTOP-N' #i1
While ESCTOP-N is:
define data parameter
1 #i1 (I1)
if #i1 = 3
I’m shocked. I would expect a NAT1324…
So ESCAPE TOP has similar behaviour as REINPUT.
From the manual:
The ESCAPE statement is used to interrupt the linear flow of execution of a processing loop or a routine.
With the keywords TOP, BOTTOM and ROUTINE you indicate where processing is to continue when the ESCAPE statement is encountered.
An ESCAPE TOP/BOTTOM statement, when encountered for processing, will internally refer to the innermost active processing loop. The ESCAPE statement need not be physically placed within the processing loop.
If an ESCAPE TOP/BOTTOM statement is placed in a routine (subroutine, subprogram, function, or a program invoked with FETCH RETURN), the routine(s) entered during execution of the processing loop will be terminated automatically.
So, yes, the ESCAPE TOP works just as shown by your output.
Yes, it is similar to how a REINPUT works. For example, if you have an INPUT statement within a FOR loop and after the INPUT you invoke a callnat or perform, a REINPUT in the subroutine or subprogram will return to the INPUT statement. HOWEVER, if the FOR loop has been completed and you then do a callnat/perform within which you try a REINPUT you should get an error message.