External stored procedure that writes to a data queue |
What is Data Queue?
Data queue is the type of system object that one can create to which a program or procedure can send data and from which another program or procedure can receive data.
How to create a stored procedure to write a Data Queue
First, we need a program that writes the data to the data queue. For example;
D QSNDDTAQ PR extpgm('QSNDDTAQ') D dtquenam 10A const D dtquelib 10A const D datalen 5P 0 const D databuf 32767A const options(*varsize) D main pr extpgm('EXTPGM5') D 10a D 10a D 20a D main pi D dtquenam 10a D dtquelib 10a D data 20a /Free QSNDDTAQ(dtquenam:dtquelib:%len(%trim(data)):data); *INLR = *ON; return; /End-Free
Explanation of the above code
D QSNDDTAQ PR extpgm('QSNDDTAQ') D dtquenam 10A const D dtquelib 10A const D datalen 5P 0 const D databuf 32767A const options(*varsize)
D main pr extpgm('EXTPGM5') D 10a D 10a D 20a D main pi D dtquenam 10a D dtquelib 10a D data 20a /Free QSNDDTAQ(dtquenam:dtquelib:%len(%trim(data)):data); *INLR = *ON; return; /End-Free
Example of an External stored procedure that writes to a data queue
D sqlproc S 500a inz(*blanks) /Free sqlproc = 'CREATE PROCEDURE EASYCLASS1.WRITETODATAQUEUE( ' + 'IN DQNAM CHAR(10), IN DQLIB CHAR(10), ' + 'IN DATA CHAR(20)) ' + 'LANGUAGE RPGLE ' + 'SPECIFIC EASYCLASS1.EXTPROCED5 ' + 'EXTERNAL NAME EASYCLASS1.EXTPGM5 ' + 'NOT DETERMINISTIC ' + 'NO SQL ' + 'CALLED ON NULL INPUT ' + 'PARAMETER STYLE GENERAL'; EXEC SQL EXECUTE IMMEDIATE :sqlproc; *INLR = *ON; /End-Free
Explanation of the above code
D sqlproc S 500a inz(*blanks) /Free sqlproc = 'CREATE PROCEDURE EASYCLASS1.WRITETODATAQUEUE( ' + 'IN DQNAM CHAR(10), IN DQLIB CHAR(10), ' + 'IN DATA CHAR(20)) ' + 'LANGUAGE RPGLE ' +
'SPECIFIC EASYCLASS1.EXTPROCED5 ' +
'EXTERNAL NAME EASYCLASS1.EXTPGM5 ' +
'NOT DETERMINISTIC ' + 'NO SQL ' + 'CALLED ON NULL INPUT ' + 'PARAMETER STYLE GENERAL';
Calling the external stored procedure in the RPGLE program
D parm1 s 10a inz('DATAQUEUE1') D parm2 s 10a inz('EASYCLASS1') D parm3 s 20a inz('TESTDATA') /Free EXEC SQL CALL EASYCLASS1.WRITETODATAQUEUE(:parm1,:parm2,:parm3); *INLR = *ON; /End-Free