-
-
Save forstie/314dde2d3e32ef9b7b83495e6d620fff to your computer and use it in GitHub Desktop.
-- | |
-- description: printf to the Joblog, using SQL | |
-- | |
cl:addlible qsysinc; | |
cl:crtsrcpf qtemp/qcsrc; | |
cl:addpfm file(qtemp/qcsrc) mbr(LPRINTF); | |
insert into qtemp.qcsrc values | |
(1,010101,'{'), | |
(2,010101,'extern int Qp0zLprintf (char *format, ...);'), | |
(3,010101,'Qp0zLprintf("%.*s\n", LPRINTF.PRINT_STRING.LEN, LPRINTF.PRINT_STRING.DAT);'), | |
(4,010101,'}'); | |
CREATE OR REPLACE PROCEDURE systools.LPRINTF(Print_string VARCHAR(30720) ccsid 37) | |
SET OPTION BINDOPT = 'BNDSRVPGM(QSYS/QP0ZCPA)' | |
BEGIN | |
IF Print_string IS NOT NULL THEN | |
INCLUDE QTEMP/QCSRC(LPRINTF); | |
END IF; | |
END; | |
call systools.LPRINTF('Hello World, the time is: ' concat current timestamp); | |
stop; |
Hi Ken,
Youbetcha, you can use the INCLUDE statement to pull in ILE C or SQL.
If you want to leverage "other" languages, use the bind service program support to bind to exports and call them from INCLUDE'ed code.
Hi Scott,
Awesome!
Thanks.
Awesome. Thanks Scott.
I extended the print_string parameter size from 1,000 to 30,720 to allow longer strings to be printed to the joblog.
Note that the data is "printed" to the joblog 512 characters at a time.
Scott, years (decades?) ago, I worked on something with Bruce Vining and show him how to merge the various binding directories. For example, we no longer need to specify QC2LE. I believe that includes the IBM-supplied binding directory that references QP0ZCPA so strictly speaking, the BINDOPT isn't needed. But I'll try it out on my system to confirm... Yes, neither the ADDLIBLE QSYSINC nor the BINDOPT are needed. But they don't hurt either.
Thanks for sharing! Awesome trick with that include. Can that be done with a real language or is that C only? ;-)
FWIW, I did another printf here: https://gist.github.com/kskuhlman/1c9e61a606a89ee0647bbd72b4de8d43