![]() |
| External stored procedure calling RPGLE program with Input parameter |
Here, we will call an external program with Input parameter using External stored procedure. So, at first we will create an SQLRPGLE prgram with some input paramters to it and then will be creating external stored procedure calling the same SQLRPGLE program with input parameters and finally instead of SQLRPGLE program we can now call external stored procedure from SQL call.
Example of an RPGLE Program with Input Parameter
D main pr extpgm('EXTPGM2')
D 10i 0
D 10a
D main pi
D n1 10i 0
D n2 10a
/Free
EXEC SQL
INSERT INTO EASYCLASS1.EXTPF1
(FLD1,FLD2)
VALUES(:n1,:n2);
*INLR = *ON;
/End-Free
Here, a program EXTPGM2 with two input parameters n1 and n2 of type integer and character respectively will be created and in this program we will be inserting the record into the file named EXTPF1 in column FLD1 and FLD2 using the input parameters to this program as an host variable.
Example of an External Stored Procedure Calling a RPGLE Program with Input Parameter
D sqlproc S 500a inz(*blanks)
/Free
sqlproc = 'CREATE PROCEDURE EASYCLASS1.EXTERNALSTOREDPROC2( ' +
'IN PARM1 INTEGER, IN PARM2 CHAR(10)) ' +
'LANGUAGE RPGLE ' +
'SPECIFIC EASYCLASS1.EXTPROCED2 ' +
'EXTERNAL NAME EASYCLASS1.EXTPGM2 ' +
'MODIFIES SQL DATA ' +
'PARAMETER STYLE GENERAL';
EXEC SQL
EXECUTE IMMEDIATE :sqlproc;
*INLR = *ON;
/End-Free
Explanation of the above code
> D sqlproc S 500a inz(*blanks)
/Free
sqlproc = 'CREATE PROCEDURE EASYCLASS1.EXTERNALSTOREDPROC2( ' +
'IN PARM1 INTEGER, IN PARM2 CHAR(10)) ' +
'LANGUAGE RPGLE ' +
'SPECIFIC EASYCLASS1.EXTPROCED2 ' +
'EXTERNAL NAME EASYCLASS1.EXTPGM2 ' +
'MODIFIES SQL DATA ' +
'PARAMETER STYLE GENERAL';
EXEC SQL
EXECUTE IMMEDIATE :sqlproc;
*INLR = *ON;
/End-Free
Calling the external stored procedure from RPGLE program with Input parameters
D parm1 s 10i 0 inz(2)
D parm2 s 10a inz('TEST2')
/Free
EXEC SQL
CALL EASYCLASS1.EXTERNALSTOREDPROC2(:parm1,:parm2);
*INLR = *ON;
/End-Free
