Data queues in RPG

5 pts.
Programming Languages
Has somebody used a data queue in a RPG program.If so, what is the advantage of using a data queue. Can I have an example.

Answer Wiki

Thanks. We'll let you know when a new response is added.

DDQNM S 10 INZ(‘dqueue name ‘)
D DQLIB S 10 INZ(‘lib name’)
D DQSZ S 5 0 INZ(2000)
D DQDTA S 1400
D#Go S 1 INZ(‘ ‘)

WriteQ BegSr




A data queue provides a communication pipe between two or more programs. Programs may place messages (entries) on the queue and other programs (or the same program) receives the messages from the queue. When a data queue entry is received by a program, the entry is automatically removed from the queue. (If two programs are receiving entries, only one of them will get the entry.)

The sending program can be in one job, and the receiving program can be in a different job. This is the primary reason that data queues may be considered to be communications objects.

A program requests an entry from the queue and specifies a time limit to wait. The program will either receive an entry and begin to process it or it will sit doing nothing until the time runs out. The first thing a program normally does after requesting an entry is to check the parameter that tells how long the entry is that was returned. If the length is zero, the program knows that the timeout was reached and no entry was returned.

Because the program can wait until an entry arrives, a data queue can be used as a kind of “wake-up call”. The program essentially sleeps for however much time goes by until some other program sends a message.

Data queues can be keyed. Programs can request entries that have specific key values. One program might wait for entries with keys like ‘ABCDE’ while a different program waits for keys like ‘12345’. Whichever entry shows up, the program that is waiting for that key will get the entry. The other program continues to wait.

More than one program can wait on queue entries. This allows you to have a bunch of programs in different jobs processing entries. If entries come in too fast, you can simply start an additional receiver job. One of the data queue APIs tells you how many entries are on a queue. This can let you know if entries are backing up.

You might have multiple receiver jobs for cases where processing entries takes much longer than generating entries. If it takes three times longer to process an entry than to generate one and entries are constantly arriving, then that might indicate you should have three receiver jobs running. You might have requests being entered from a web interface. One program receives the requests and places them on a queue, then goes back to wait for another request — it does no processing of the requests. Other jobs pull from the queue and do the request processing.

In any case, the “advantages” are the same as in any object you might use in programming. The advantages are in whatever you can imagine to do with them.


Discuss This Question: 5  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • RickMe
    Data queues are a nice place to store temporary data that needs to be retrieved/checked later in the program. Data can be read from the queue in any order you wish: based on a key value, in FIFO sequence, or LIFO sequence, depending on the type of queue created. This same data could also be held in array(s), but in cases where you don't know how many entries you'll have, how do you know how big to make your arrays? Also, how do you read arrays in key order without special sorting? Data queues handle this with ease. Data could also be written to a physical file, and read from the file in any sequence, but data queues handle this with no DDS. You can just create the data queue on the fly in QTEMP (or any other lib) and write and read to/from it as needed. API's QSNDDTAQ and QRCVDTAQ write and read data to/from the queue. The parms passed to/from these API's change a bit depending on the type of queue (keyed/FIFO,etc) but they are really easy to use. I've found good applications for them. Good luck.
    110 pointsBadges:
  • BikerDude
    I recently created an application where using data queues. The application was for printing UCC-128 labels. The process for printing the labels seemed to be a bit intensive for an interactive job to process. Therefore I created a NEP (Never Ending Program) that ran in batch and waited for an entry to arrive on the data queue. When the entry arrived it would print the labels as requested. So the only thing I had to do in my interactive program was to send the entry to the data queue. BTW - When I wanted the NEP to end...I just loaded the entry with a predetermined "code". In my case it was "*END*". When the NEP retrieved the entry with "*END*" as the first 5 characters, it would seton *INLR and end the program.
    0 pointsBadges:
    Hi. I need some help with net pgm. This is my stuff: 1- ADDPJE SBSD(LIBINO/INOSBS) PGM(LIBINO/TST44R) 2- TST44R read a InoDtaq 3- In WrkActJob I can view the INOSBS with TST44R 3 times (default) 4- I have a pgm TST43R that write a LIBINO/INODTAQ. I run it. 5- I run TST44R and in WorkActJob its appears only twice. When I run TST44R twice, its disapper from INOSBS. MY QUESTION: how I can do to not disappear (like NEP pgm) This is TST44R source: ddqname s 10A INZ('INODTAQ') ddqlib s 10A INZ('LIBINO') ddqsndlen s 5 0 INZ(14) ddqlen s 5 0 ddqsnddata s 50a dParm1 s Like(dqdata) ddqdata s 50a ddqwait s 5 0 Eval dqwait=-1 call 'QRCVDTAQ' parm dqname parm dqlib parm dqlen parm dqdata parm dqwait Eval Parm1=%Trim(dqdata) c/Exec sql C+ INSERT INTO QGPL/TSTPF (NAME) VALUES(:Parm1) c/End-exec Return
    30 pointsBadges:
  • TomLiotta
    ADDPJE SBSD(LIBINO/INOSBS) PGM(LIBINO/TST44R) What are the other parms? In particular, what are the values for INLJOBS(), THRESHOLD(), ADLJOBS(), MAXJOBS(), MAXUSE() and WAIT()? Also, why not code your program to process more data queue entries? It looks like it receives one entry, runs its INSERT and then RETURNs. Why not have it continue receiving entries until the data queue is empty? Also, you might consider preparing your INSERT statement. That should reduce processing significantly, especially if you need this to handle data queue entries quickly (which is often why data queues are used in the first place). Tom
    125,585 pointsBadges:
  • jescobar
    There any place where can i find an example of how to read and work with a record from data queue?  for example,  from JAVA,  I wrote data in the dtaq (four columns, idNumber, first name,last name, securityId),  now i need to work with it on a RPG program,  but i don't now how to access it,  i need to validate idNumber,  then validate First Name, etc.  Can you Help me?
    10 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: