The DECLARE PROCEDURE statement defines an external procedure.
This statement can only be embedded in an application program. It is not an executable statement. It must not be specified in REXX.
None.
>>-DECLARE--procedure-name--PROCEDURE---------------------------> >--+-----------------------------------------+--option-list---->< '-(--+-------------------------------+--)-' | .-,-------------------------. | | V | | '-----parameter-declaration---+-'
parameter-declaration: .-IN----. |--+-------+--+----------------+--data-type--+------------+-----| +-OUT---+ '-parameter-name-' '-AS LOCATOR-' '-INOUT-' data-type: |--+-built-in-type------+---------------------------------------| '-distinct-type-name-'
option-list: (1) |--+-----------------------+------------------------------------> '-LANGUAGE--+-C-------+-' +-C++-----+ +-CL------+ +-COBOL---+ +-COBOLLE-+ +-FORTRAN-+ +-JAVA----+ +-PLI-----+ +-REXX----+ +-RPG-----+ '-RPGLE---' .-PARAMETER STYLE SQL---------------------. >--+-----------------------------------------+------------------> '-PARAMETER STYLE--+-DB2GENERAL---------+-' +-DB2SQL-------------+ +-GENERAL------------+ +-GENERAL WITH NULLS-+ '-JAVA---------------' .-NOT DETERMINISTIC-. .-MODIFIES SQL DATA-. >--+-------------------+--+-------------------+-----------------> '-DETERMINISTIC-----' +-NO SQL------------+ +-CONTAINS SQL------+ '-READS SQL DATA----' .-CALLED ON NULL INPUT-. .-DYNAMIC RESULT SETS--0-------. >--+----------------------+--+------------------------------+---> '-DYNAMIC RESULT SETS--integer-' .-NO DBINFO-. .-FENCED-----. .-PROGRAM TYPE MAIN-. >--+-----------+--+------------+--+-------------------+---------> '-DBINFO----' '-NOT FENCED-' .-EXTERNAL-----------------------------. >--+--------------------------------------+---------------------> '-EXTERNAL NAME--external-program-name-' >--+-------------------------+----------------------------------| '-SPECIFIC--specific-name-'
built-in-type: |--+-+---SMALLINT---+--------------------------------------------------------------------------+--| | +-+-INTEGER-+--+ | | | '-INT-----' | | | '---BIGINT-----' | | .-(5,0)------------------------. | +-+-+-DECIMAL-+-+--+------------------------------+-----------------------------------------+ | | '-DEC-----' | | .-,0--------. | | | '-NUMERIC-----' '-(--integer--+-----------+--)-' | | '-, integer-' | | .-(--53--)------. | +-+-FLOAT--+---------------+-+--------------------------------------------------------------+ | | '-(--integer--)-' | | | +-REAL---------------------+ | | | .-PRECISION-. | | | '-DOUBLE--+-----------+----' | | .-(--1--)-------. | +-+-+-+-CHARACTER-+--+---------------+----------+--+----------------+---------------------+-+ | | | '-CHAR------' '-(--integer--)-' | +-FOR BIT DATA---+ | | | | '-+-+-CHARACTER-+--VARYING-+--(--integer--)-' +-FOR SBCS DATA--+ | | | | | '-CHAR------' | +-FOR MIXED DATA-+ | | | | '-VARCHAR----------------' '-ccsid-clause---' | | | | .-(--1M--)-------------. | | | '-----+-+-CHARACTER-+--LARGE OBJECT-+------+----------------------+--+----------------+-' | | | '-CHAR------' | '-(--integer--+---+--)-' +-FOR SBCS DATA--+ | | '-CLOB------------------------' +-K-+ +-FOR MIXED DATA-+ | | +-M-+ '-ccsid-clause---' | | '-G-' | | .-(--1--)-------. | +-+---GRAPHIC----+---------------+-------+--+--------------+--------------------------------+ | | '-(--integer--)-' | '-ccsid-clause-' | | +-+-GRAPHIC VARYING-+--(--integer--)---+ | | | '-VARGRAPHIC------' | | | | .-(--1M--)-------------. | | | '---DBCLOB----+----------------------+-' | | '-(--integer--+---+--)-' | | +-K-+ | | +-M-+ | | '-G-' | | .-(--1--)-------. | +-+-+-BINARY--+---------------+---------+-----------------+---------------------------------+ | | | '-(--integer--)-' | | | | | '-+-BINARY VARYING-+--(--integer--)-' | | | | '-VARBINARY------' | | | | .-(--1M--)-------------. | | | '---+-BLOB----------------+----+----------------------+-' | | '-BINARY LARGE OBJECT-' '-(--integer--+---+--)-' | | +-K-+ | | +-M-+ | | '-G-' | +-+-DATE------+-----------------------------------------------------------------------------+ | +-TIME------+ | | '-TIMESTAMP-' | | .-(--200--)-----. | +---DATALINK--+---------------+--+--------------+-------------------------------------------+ | '-(--integer--)-' '-ccsid-clause-' | '---ROWID-----------------------------------------------------------------------------------' ccsid-clause: .-NOT NORMALIZED-. |--CCSID--integer--+----------------+---------------------------| '-NORMALIZED-----'
The maximum number of parameters allowed in DECLARE PROCEDURE depends on the language and the parameter style:
The maximum number of parameters is also limited by the maximum number of parameters allowed by the licensed program used to compile the external program or service program.
A DataLink or a distinct type based on a DataLink may not be specified as an output parameter.
A DataLink or a distinct type based on a DataLink may not be specified as an input and output parameter.
The data type must be valid for the language specified in the language clause. All data types are valid for SQL procedures. DataLinks are not valid for external procedures. For more information about data types, see CREATE TABLE, and the SQL Programming book.
If a CCSID is specified, the parameter will be converted to that CCSID prior to passing it to the procedure. If a CCSID is not specified, the CCSID is determined by the default CCSID at the current server at the time the procedure is called.
Result sets are only returned if the procedure is directly called or if the procedure is a RETURN TO CLIENT procedure and is indirectly called from ODBC, JDBC, OLE DB, .NET, the SQL Call Level Interface, or the iSeries Access Family Optimized SQL API. For more information about result sets, see SET RESULT SETS.
If LANGUAGE is not specified, the LANGUAGE is determined from the program attribute information associated with the external program. If the program attribute information associated with the program does not identify a recognizable language, then the language is assumed to be C.
If no qualifier is specified, the implicit or explicit qualifier of the procedure-name is used. If a qualifier is specified, the qualifier must be the same as the explicit or implicit qualifier of the procedure-name.
If specific-name is not specified, it is the same as the procedure name.
DBINFO is only allowed with PARAMETER STYLE DB2SQL.
Field | Data Type | Description |
---|---|---|
Relational database | VARCHAR(128) | The name of the current server. |
Authorization ID | VARCHAR(128) | The run-time authorization ID. |
CCSID Information |
INTEGER
INTEGER INTEGER INTEGER
INTEGER INTEGER INTEGER
INTEGER INTEGER INTEGER
CHAR(8) |
The CCSID information of the job. Three sets
of three CCSIDs are returned. The following information identifies the three
CCSIDs in each set:
If a CCSID is not explicitly specified for a parameter on the CREATE PROCEDURE statement, the input string is assumed to be encoded in the CCSID of the job at the time the procedure is executed. If the CCSID of the input string is not the same as the CCSID of the parameter, the input string passed to the external procedure will be converted before calling the external program. |
Target Column | VARCHAR(128)
VARCHAR(128)
VARCHAR(128) |
Not applicable for a call to a procedure. |
Version and release | CHAR(8) | The version, release, and modification level of the database manager. |
Platform | INTEGER | The server's platform type. |
The validity of the name is checked at the application server. If the format of the name is not correct, an error is returned.
If external-program-name is not specified, the external program name is assumed to be the same as the procedure name.
The user may set the SQLSTATE to any valid value in the external program to return an error or warning from the function.
PARAMETER STYLE SQL cannot be used with LANGUAGE JAVA.
PARAMETER STYLE DB2GENERAL can only be specified with LANGUAGE JAVA. For details on passing parameters in JAVA, see the IBM® Developer Kit for Java book.
PARAMETER STYLE DB2SQL cannot be used with LANGUAGE JAVA.
PARAMETER STYLE GENERAL cannot be used with LANGUAGE JAVA.
PARAMETER STYLE GENERAL WITH NULLS cannot be used with LANGUAGE JAVA.
PARAMETER STYLE JAVA can only be specified with LANGUAGE JAVA. For details on passing parameters in JAVA, see the IBM Developer Kit for Java book.
Note that the language of the external function determines how the parameters are passed. For example, in C, any VARCHAR or CHAR parameters are passed as NUL-terminated strings. For more information, see the SQL Programming book. For Java routines, see the IBM Developer Kit for Java.
DECLARE PROCEDURE scope: The scope of the procedure-name is the source program in which it is defined; that is, the program submitted to the precompiler. Thus, a program called from another separately compiled program or module will not use the attributes from a DECLARE PROCEDURE statement in the calling program.
DECLARE PROCEDURE rules: The DECLARE PROCEDURE statement should precede all CALL statements that reference that procedure.
The DECLARE PROCEDURE statement only applies to static CALL statements. It does not apply to any dynamically prepared CALL statements or a CALL statement where the procedure name is identified by a variable.
Syntax alternatives: The following keywords are synonyms supported for compatibility to prior releases. These keywords are non-standard and should not be used:
Declare an external procedure PROC1 in a C program. When the procedure is called using the CALL statement, a COBOL program named PGM1 in library LIB1 will be called.
EXEC SQL DECLARE PROC1 PROCEDURE (CHAR(10), CHAR(10)) EXTERNAL NAME LIB1.PGM1 LANGUAGE COBOL GENERAL; EXEC SQL CALL PROC1 ('FIRSTNAME ','LASTNAME ');