Example PL/I stored procedure with a GENERAL linkage convention

You can call a stored procedure that uses the GENERAL linkage convention from a PL/I program.

This example stored procedure searches the Db2 SYSIBM.SYSROUTINES catalog table for a row that matches the input parameters from the client program. The two input parameters contain values for NAME and SCHEMA.

The linkage convention for this stored procedure is GENERAL.

The output parameters from this stored procedure contain the SQLCODE from the SELECT operation, and the value of the RUNOPTS column retrieved from the SYSIBM.SYSROUTINES table.

The CREATE PROCEDURE statement for this stored procedure might look like this:
CREATE PROCEDURE GETPRML(PROCNM CHAR(18) IN, SCHEMA CHAR(8) IN,
  OUTCODE INTEGER OUT, PARMLST VARCHAR(254) OUT)
  LANGUAGE PLI
  DETERMINISTIC
  READS SQL DATA
  EXTERNAL NAME "GETPRML"
  COLLID GETPRML
  ASUTIME NO LIMIT
  PARAMETER STYLE GENERAL
  STAY RESIDENT NO
  RUN OPTIONS "MSGFILE(OUTFILE),RPTSTG(ON),RPTOPTS(ON)"
  WLM ENVIRONMENT SAMPPROG
  PROGRAM TYPE MAIN
  SECURITY DB2
  RESULT SETS 0
  COMMIT ON RETURN NO;

The following example is a PL/I stored procedure with linkage convention GENERAL.

*PROCESS SYSTEM(MVS);
 
 GETPRML:
   PROC(PROCNM, SCHEMA, OUT_CODE, PARMLST)
                       OPTIONS(MAIN NOEXECOPS REENTRANT);
 
   DECLARE PROCNM CHAR(18),    /* INPUT parm -- PROCEDURE name */
           SCHEMA CHAR(8),     /* INPUT parm -- User's SCHEMA  */
 
           OUT_CODE FIXED BIN(31), /* OUTPUT -- SQLCODE from   */
                                   /*   the SELECT operation.  */
           PARMLST CHAR(254)       /* OUTPUT -- RUNOPTS for    */
                   VARYING;        /*  the matching row in     */
                                   /*  SYSIBM.SYSROUTINES      */
 
   EXEC SQL INCLUDE SQLCA;
 
   /************************************************************/
   /* Execute SELECT from SYSIBM.SYSROUTINES in the catalog.   */
   /************************************************************/
   EXEC SQL
     SELECT RUNOPTS INTO :PARMLST
         FROM SYSIBM.SYSROUTINES
         WHERE NAME=:PROCNM AND
               SCHEMA=:SCHEMA;
 
   OUT_CODE = SQLCODE;         /* return SQLCODE to caller     */
   RETURN;
 END GETPRML;