|Read data from data queue using QRCVDTAQ API in RPG AS400|
Receive Data Queue (QRCVDTAQ) API
The Receive Data Queue (QRCVDTAQ) API receives data from the specified data queue.
A data queue entry sent to the data queue is received by only one prorgram at a time even if multiple program are waiting for the entry.
We can use QRCVDTAQ API to receive data from the DDM data queues as well which is located on the remote system.
Technically speaking, when a Job uses this API a cache is created to allow faster access to the Data queue.
- Data Queue Name: Input parm and Char(10)
- Library Name: Input parm and Char(10)
- Length of Data: Output parm and Packed(5,0)
- Data: output parm and Char(*)
- Wait Time: input parm and Packed(5,0)
There are some optional parameters as well which are discussed here in this blog.
Coding QRCVDTAQ API in RPGLE Fixed, /Free and Fully Free format
D main pr extpgm('EXTPGM5') D 10a D 10a D 20a D main pi D dtquenam 10a D dtquelib 10a D receive 20a D len s 5P 0 inz D waittime s 5p 0 inz(10) C EVAL receive = ' ' C CALL 'QRCVDTAQ' C PARM dtquenam C PARM dtquelib C PARM len C PARM receive C PARM waittime C RECEIVE DSPLY C LEN DSPLY C SETON LR C RETURN
D QRCVDTAQ PR extpgm('QRCVDTAQ') D dtquenam 10A const D dtquelib 10A const D datalen 5P 0 const D databuf 32767A const options(*varsize) D waittime 5P 0 const D main pr extpgm('EXTPGM6') D 10a D 10a D 20a D main pi D dtquenam 10a D dtquelib 10a D receive 20a D len s 5P 0 inz D waittime c const(10) /Free receive = ' '; QRCVDTAQ(dtquenam:dtquelib:len:receive:waittime); dsply receive; dsply len; *INLR = *ON; return; /End-Free
**FREE dcl-pr QRCVDTAQ extpgm ; *n char(10) const; *n char(10) const; *n packed(5:0) const; *n char(32767) const options(*varsize); *n packed(5:0) const; end-pr; dcl-pi *N; dtquenam char(10); dtquelib char(10); receive char(20); end-pi; dcl-s len packed(5:0) inz; dcl-c waittime const(10); receive = ' '; QRCVDTAQ(dtquenam:dtquelib:len:receive:waittime); DSPLY receive; DSPLY len; *INLR = *ON; return;
Compile the program EXTPGM6 using option 14 against the SQLRPGLE source member or using the command CRTSQLRPGI.
Execute the QRCVDTAQ code
For testing the above code, we first need to create the data queue and some program using QSNDDTAQ to send entry to data queue using the below link.Create Data Queue and send entry to Data Queue using QSNDDTAQ API
CALL PGM(EXTPGM6) PARM('DATAQUEUE1' 'EASYCLASS1' ' ')
Data being read from the data queue named DATAQUEUE1 and displyed the data and its length.
DSPLY HELLO WORLD DSPLY 11
Data Queue in AS400
Write data to data queue using QSNDDTAQ API in RPG AS400
Post a Comment