Last active
June 23, 2023 12:37
-
-
Save forstie/314dde2d3e32ef9b7b83495e6d620fff to your computer and use it in GitHub Desktop.
printf to the Joblog using SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- 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 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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.