Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
printf to the Joblog using SQL
--
-- 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(1000) 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;
@kskuhlman

This comment has been minimized.

Copy link

commented Jun 18, 2019

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

@forstie

This comment has been minimized.

Copy link
Owner Author

commented Jun 19, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.