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; |
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
Awesome. Thanks Scott.