Free-Form Procedure Interface Definition

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.

Procedure interface parameters

See Free-Form Parameter Definition.

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

  1. 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;
    
  2. 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;
    
  3. 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;
    
  4. 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;
    
  5. 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;
    
  6. A procedure interface using DCL-PARM to define some of its subfields.
    1. 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.
    2. Parameter name does not have the same name as an operation code, so DCL-PARM is not required.
    3. 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;
    
  7. See Specifying *DCLCASE as the External Name for more examples.