%PROC (Return Name of Current Procedure)
%PROC({*OWNER | *ONEXIT})
%PROC returns the external name of the current procedure.
%PROC can only be specified in calculation statements.
A parameter is not allowed for %PROC unless it specified in the ON-EXIT section of a procedure.
In the ON-EXIT
section of a procedure, a
parameter is required.
- %PROC(*OWNER) returns the external name of the procedure containing the ON-EXIT section.
- %PROC(*ONEXIT) returns the external name of the procedure that implements the ON-EXIT section.
The value returned by %PROC
depends on where it is specified:
- For a cycle-main procedure, the external name of the procedure is the name of the module when it was compiled.
- For a linear-main procedure, the external name of the procedure is the uppercase form of name of the main procedure. See 1 in the example below.
- For a subprocedure where EXTPROC was not specified, the external name of the procedure is the uppercase form of the name of the procedure. See 2 in the example below.
- For a subprocedure where EXTPROC was specified, the external name of the procedure is the value specified by EXTPROC. See 3 in the example below.
- For a Java procedure, the external name of the procedure is in the form "Java_classname_methodname". See 4 in the example below.
- For examples of %PROC(*OWNER), see 5 in the procedures below.
- For examples of %PROC(*ONEXIT), see 6 in the procedures below.
CTL-OPT MAIN(myPgm) DFTACTGRP(*NO);
DCL-S x VARCHAR(100);
DCL-PR myPgm EXTPGM('MYLIB/MYPGM345') END-PR;
DCL-PR proc1 END-PR;
DCL-PR proc2 EXTPROC('myProc2') END-PR;
DCL-PR proc3 EXTPROC(*JAVA:'MyClass':'proc3') END-PR;
DCL-PROC myPgm; // 1
x = %PROC();
// x = "MYPGM"
ON-EXIT;
x = %PROC(*OWNER); // 5
// x = "MYPGM"
x = %PROC(*ONEXIT); // 6
// x = "_QRNI_ON_EXIT_MYPGM"
END-PROC;
DCL-PROC proc1; // 2
x = %PROC();
// x = "PROC1"
ON-EXIT;
x = %PROC(*OWNER); // 5
// x = "PROC1"
x = %PROC(*ONEXIT); // 6
// x = "_QRNI_ON_EXIT_PROC1"
END-PROC;
DCL-PROC proc2; // 3
x = %PROC();
// x = "myProc2"
ON-EXIT;
x = %PROC(*OWNER); // 5
// x = "myProc2"
x = %PROC(*ONEXIT); // 6
// x = "_QRNI_ON_EXIT_myProc2"
END-PROC;
DCL-PROC proc3 EXPORT; // 4
x = %PROC();
// x = "Java_MyClass_proc3"
END-PROC;