Return to the SQL Tips
Run CL Commands From Interactive SQL
When I am using Interactive SQL/400 (i.e., STRSQL) and need to run a CL command, I have to exit SQL, run the command, and re-enter SQL. Is there any way to run system commands within an interactive SQL session?
Here's the deal. IBM has not provided a way to run CL commands from an SQL session, but you can create a stored procedure to run them. Here are two examples to get you started.
The first one creates a stored procedure, called EXCCMD, to run program QCMDEXC:
CREATE PROCEDURE mylib/exccmd (IN cmd CHAR (32000), IN len DEC (15,5)) LANGUAGE CL NOT DETERMINISTIC NO SQL EXTERNAL NAME QSYS/QCMDEXC PARAMETER STYLE GENERALOnce you have created this stored procedure, you will be able to run CL commands using the SQL CALL command:
call exccmd ('wrkoutq garbage',15)
Here's the SQL command to create a stored procedure called CMD, which brings up a pop-up window like the one you get when you press F21 from Screen Entry Utility (SEU):
CREATE PROCEDURE mylib/cmd LANGUAGE CL NOT DETERMINISTIC NO SQL EXTERNAL NAME QSYS/QUSCMDLN PARAMETER STYLE GENERALTo run CL commands, type the following command in your interactive SQL session:
call cmd
To resume entering SQL commands, press Enter with an empty command line, or press F12.
-- Ted Holt October 12, 2001 issue of the OS/400 Edition of the Midrange Guru technical tips newsletter.
Volume 1, Number 6
A publication from Midrange Server, Inc.
http://www.itjungle.com
[report a broken link by clicking here]