A procedure interface begins with a DCL-PI statement.
The DCL-PI statement is followed by
zero or more parameters, followed by an
END-PI statement.
DCL-PI statement to begin the procedure interface
The first statement begins with DCL-PI, followed by the
name of the procedure or *N if you
do not want to repeat the name of the procedure,
followed by keywords, and finally a semicolon.
- If you do not specify a prototype for a cycle-main
procedure, you use *N as the name for
the procedure interface.
- If you do not specify a prototype for a linear-main
procedure, you can specify the
EXTPGM keyword without
a parameter for the procedure interface.
END-PI statement to end the procedure interface
- END-PI may be followed by the name of the procedure.
- If there are no parameters, END-PI may be
specified as part of the DCL-PI statement, following the
keywords and before the semicolon.
In this case, END-PI cannot be followed by the name
of the procedure.
Examples of free-form procedure interfaces
- A procedure interface for a cycle-main procedure
where there is no prototype.
*N is specified for the procedure-interface name.
One parameter, name is specified
in the procedure interface.
(This example shows a complete program with a
cycle-main procedure.)
CTL-OPT OPTION(*SRCSTMT);
DCL-PI *N; 1
name CHAR(10) CONST;
END-PI;
DSPLY ('Hello ' + name);
RETURN;
- A procedure interface for a linear-main procedure
where there is no prototype.
The EXTPGM keyword is specified without a parameter.
(This example shows a complete program with a
linear-main procedure.)
CTL-OPT MAIN(sayHello) OPTION(*SRCSTMT);
DCL-PROC sayHello;
DCL-PI *N EXTPGM; 2
name CHAR(10) CONST;
END-PI;
DSPLY ('Hello ' + name);
END-PROC;
- A procedure interface with three parameters.
The END-PI statement is specified without a name.
DCL-PROC addNewOrder;
DCL-PI *N;
id INT(10) VALUE;
quantity INT(10) CONST;
price PACKED(7 : 2) CONST;
END-PI; 3
...
END-PROC;
- A name is specified for the END-PI statement
DCL-PROC addNewOrder;
DCL-PI *N;
id INT(10) CONST;
quantity INT(10) CONST;
price PACKED(7 : 2) CONST;
END-PI addNewOrder; 4
...
END-PROC;
- END-PI is specified as part of the DCL-PI statement.
(This example shows a complete procedure.)
DCL-PROC getCurrentUser;
DCL-PI *N CHAR(10) END-PI; 5
DCL-S currentUser CHAR(10) INZ(*USER);
RETURN currentUser;
END-PROC;
- A procedure interface using DCL-PARM to define
some of its subfields.
- Parameter select has the same
name as an operation code
allowed in free-form calculations.
DCL-PARM is required for this parameter.
See Table 1.
- Parameter name does not have the same name
as an operation code, so DCL-PARM is not required.
- Parameter address does not have
the same name as an operation code, so DCL-PARM is not
required, but it is valid.
DCL-PI *N;
DCL-PARM select CHAR(10); 6a
name CHAR(10); 6b
DCL-PARM address CHAR(25); 6c
END-PI;
- See Specifying *DCLCASE as the External Name for more examples.