Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpdave/c1fdb9793521b6f2350c to your computer and use it in GitHub Desktop.
Save phpdave/c1fdb9793521b6f2350c to your computer and use it in GitHub Desktop.
Example of how you can change the library list in a SQL stored procedure before calling an external RPG program that may require that Library.
CREATE PROCEDURE MYLIB.SQLSTOREDPROCEDURE (
IN MYNUMBER DECIMAL(9, 0),
INOUT RESULT CHAR(1) )
LANGUAGE SQL
BEGIN
DECLARE CMD CHAR ( 300 ) DEFAULT ' ' ;
DECLARE CURRENTDATE CHAR ( 8 ) DEFAULT ' ' ;
--Ignore the error message that occurs if you add the library list twice
--Create a variable that has the SQLSTATE value and create a CONTINUE HANDLER for that
--SQLSTATE
DECLARE LibraryAlreadyAdded CONDITION FOR SQLSTATE '38501';
DECLARE CONTINUE HANDLER FOR LibraryAlreadyAdded BEGIN END;
SET CMD = 'ADDLIBLE MYLIB2' ;
SET CURRENTDATE = YEAR(NOW()) || RIGHT('0' || MONTH(NOW()),2) || RIGHT('0' || DAY(NOW()),2) ;
--CALL Command to add MYLIB2 to the Library list
CALL QSYS . QCMDEXC ( CMD , 0000000300.00000 ) ;
--CALL EXTERNAL RPG PROGRAM WITH INOUT PARAM OUTPUTDATE
CALL MYLIB.MYRPGPGM (MYNUMBER,OUTPUTDATE);
IF (CURRENTDATE>OUTPUTDATE) THEN
SET RESULT = 'N';
ELSE
SET RESULT = 'Y';
END IF;
END ;
--Call the SQL Stored Procedure with a value
CALL MYLIB.SQLSTOREDPROCEDURE(987654321,' ');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment