Continuously Read From As400 Data Queue Java

It's been nearly 20 years since Wayne O. Evans, a security expert and consultant who was working at IBM Rochester, came up with the idea of data queues. With the exception of messages and probably OPNQRYF, data queues are probably the most-used programmer resource on OS/400.

Data queues provide a "queue" onto which the programmer may stack data and then retrieve that data later. Since data queues are persistent objects, they may have data added to them in one job and that data may be retrieved in a secondary job. Often, in fact, multiple jobs will add data to a specific data queue, and a single batch job will retrieve the data off that data queue asynchronously. That batch job can wait for a specified period or forever for an entry to be added to the data queue.

The following commands are among the few CL commands that IBM ships with OS/400 for data queues:

  • CRTDTAQ--Create Data Queue
  • DLTDTAQ--Delete Data Queue
  • WRKDTAQ--Work with Data Queues

Displaying the Description of a *DTAQ

To take advantage of data queues, you have to use APIs. Ironically, while most RPG programmers wrongly treat APIs like a Latin course in college, you really can't use data queues without APIs. Consequently, most people are using APIs, at least when it comes to data queues.

IBM provides APIs to send and received data to and from a data queue, as well as to retrieve information about the data queue. The APIs that IBM provides to manipulate data queues are as follows:

  • QSNDDTAQ--Send Data Queue Data
  • QRCVDTAQ--Receive Data Queue Data
  • QCLRDTAQ--Clear Data Queue
  • QMHRDQM--Retrieve Data Queue Entry
  • QMHQRDQD--Retrieve Data Queue Description

The Send and Receive APIs are, of course, widely used throughout the RPG application world, so I won't bother explaining them.

The QCLRDTAQ API clears either all the entries on the specified data queue or a subset of entries identified by a "key" parameter. You specify a key to delete, and the API deletes the entries in the data queue that match that key. Normally, entries in a data queue are removed when they are retrieved with the QRCVDTAQ API, so the use of QCLRDTAQ is not widespread.

The QMHRDQM API retrieves one or more entries from a data queue. This is similar to what is done with the conventional QRCVDTAQ API, but that is where the similarity ends. The QMHRDQM API does not delete the data entries it retrieves.

The QMHRDQM and QCLRDTAQ APIs along with QRCVDTAQ and QSNDDTAQ APIs are interfaces that are used to manipulate the data on the data queue itself, whereas the QMHQRDQD API returns information about the data queue itself.

The QMHQRDQD API returns the description of the data queue along with information about the size and number of entries on the data queue. While this API is useful for testing for entries on a data queue before attempting to retrieve an entry, that capability is already integrated into the QRCVDTAQ API.

So what use is the QMHQRDQD API? It can be used to create a Display Data Queue Description (DSPDTAQD) command.

The DSPDTAQD command accepts a data queue name and displays the appropriate information about that data queue. Figure 1 contains the command definition source code for the DSPDTAQD command.

DSPDTAQD:    CMD        PROMPT('Display Data Queue Description') /* Command processing program is: DSPDTAQD  */              PARM       KWD(DTAQ) TYPE(QUAL) MIN( 1 ) +                           PROMPT('Data queue')  QUAL:       QUAL       TYPE(*NAME) MIN( 1 ) EXPR(*YES)              QUAL       TYPE(*NAME) DFT(*LIBL) SPCVAL((*LIBL) +                           (*CURLIB)) EXPR(*YES) PROMPT('Library')

Figure 1: DSPDTAQD (Display Data Queue Description) Command Source

To compile this command, use the CRTCMD command as follows:

CRTCMD  CMD(DSPDTAQD)

The command requires a command processing program (see Figure 3), which also requires a display file to display the data queue's information. The DDS source for this display file is listed in Figure 2.

     A                                      CA03 * SRCMBR: DSPDTAQDF ..... A *.........R.Format++++................Keywords++++++++++++++++++++++++      A          R FORMAT1 A   1   2 'DSPDTAQD' A   1  27 'Display Data Queue Description' A                                      DSPATR(HI)      A MYTIME    10A O   1  60 A MYDATE    10A O   1  71 A   3   4 'Data queue . . . .' A DTAQNAME    10A O   3  23 DSPATR(HI) A   3  42 'Remote name . . . .' A RMTQNAME    10A O   3  62 A   4   6 'Library  . . . .' A DTAQLIB    10A O   4  24 DSPATR(HI) A   4  44 'Library . . . . .' A RMTQLIB    10A O   4  63 A   5   4 'Text . . . . . . .' A TEXTDESC    50A O   5  23 A   7   6 'Maximum entry length  . . . . . . - A                                      . . . . :'      A MAXLEN    10A O   7  51 A   8   6 'Entry sequence. . . . . . . . . . - A                                      . . . . :'      A DTAQSEQ    10A O   8  51 A   9   6 'Key length  . . . . . . . . . . . - A                                      . . . . :'      A KEYLEN    10A O   9  51 A  10   6 'Force to aux storage  . . . . . . - A                                      . . . . :'      A FORCEWRITE    10A O  10  51 A  11   6 'Include Sender ID . . . . . . . . - A                                      . . . . :'      A SENDERID    10A O  11  51 A  12   6 'Size: Max entries . . . . . . . . - A                                      . . . . :'      A MAXENTRY    10A O  12  51 A  13  12 'Initial entries . . . . . . . . . - A                                      . :'      A INITENTRY    10A O  13  51 A  14   6 'Automatic reclaim . . . . . . . . - A                                      . . . . :'      A AUTORCL    10A O  14  51 A  15   6 'Current number of msgs  . . . . . - A                                      . . . . :'      A CURMSGS    10A O  15  51 A  16   6 'Current allocation size . . . . . - A                                      . . . . :'      A CURCAP    10A O  16  51 A  18   6 'APPC device description . . . . . - A                                      . . . . :'      A APPCDEVD    10A O  18  51 A  19   6 'Local location name . . . . . . . - A                                      . . . . :'      A LCLLOCNAME    10A O  19  51 A  20   6 'Remote location name  . . . . . . - A                                      . . . . :'      A RMTLOCNAME    10A O  20  51 A  21   6 'Mode name . . . . . . . . . . . . - A                                      . . . . :'      A MODENAME    10A O  21  51 A  22   6 'Remote network ID . . . . . . . . - A                                      . . . . :'      A RMTNETID    10A O  22  51 A  24   6 'F3=Exit' A                                      COLOR(BLU)

Figure 2: DSPDTAQDF Source

The final piece of this puzzle is the command processing program for the DSPDTAQD command. The RPG IV program DSPDTAQD receives the name of the data queue and uses the QMHQRDQD API to retrieve the description of that data queue. The source for the DSPDDTAQD RPG IV program is listed in Figure 3.

H DFTACTGRP ( *NO ) BNDDIR ( 'QC2LE' ) H OPTION ( *NODEBUGIO  : *SRCSTMT ) **  DSPDTAQD – Download at: http://www.rpgiv.com/newsletter /IF DEFIN ED(TOOLKIT ) H BNDDIR('TOOLKIT/TOOLKIT') /ENDIF F DSPDTAQDF C F E WORKSTN INFDS(WSDS) D  DspDtaQD PR D   DtaQ      20 A D  DspDtaQD PI D   DtaQ      20 A D  GetDtaQD PR                  Extpgm('QMHQRDQD') D   RtnVariable    2000 A OPTIONS(*VARSIZE) D   RtnVarLen      10 I  0 Const D   APIFMT       8 A Const D   DTAQ      20 A Const /IF DEFIN ED(TOOLKIT ) D /COPY TOOLKIT/TOOLKIT /ENDIF D  wsds DS D   FKey       1 A Overlay(WSDS:369) D  PSDS S DS D   CPFMSGID       7 A Overlay(PSDS:40) D   CPFMSGD      80 A Overlay(PSDS:91) D   MSGTEXT      50 A Overlay(PSDS:91) D  F3 C                   Const(X'33') D  ENTER C                   Const(X'F1') D  DQDataF1 DS                  Inz D   BytesRtn      10 I  0 D   BytesAvail      10 I  0 Inz(%size(DQDataF1)) D   Max_Len      10 I  0 D   Key_Len      10 I  0 D   Q_Seq       1 A D   Sender_ID       1 A D   Force_Write       1 A D   TextDesc      50 A D   DtaQ_Type       1 A D   Auto_Rcl       1 A D   Reserved1       1 A D   Cur_Msgs      10 I  0 D   CurEntry_Cap      10 I  0 D   DtaQName      10 A D   DtaQLib      10 A D   Max_Entry      10 I  0 D   Init_Entry      10 I  0 D  DQDataF2 DS                  Inz D   BytesRtn2      10 I  0 D   BytesAvail2      10 I  0 Inz(%size(DQDataF2)) D   APPCDevD      10 A D   ModeName      10 A D   RmtLocName      10 A D   LclLocName      10 A D   RmtNetID      10 A D   RmtDtaQName      10 A D   RmtDtaQLib      10 A D   DtaQName2      10 A D   DtaQLib2      10 A D  QSYSDATE S D Datfmt(*USA) Inz(*SYS) D  QSYSTIME S T Timfmt(*USA) Inz(*SYS) C MOVE *ON *INLR      C callp(E) GetDtaQD(DQDataF1 : %size(DQDataF1) : C           'RDQD0100' : DtaQ ) C if %ERROR and CPFMSGID = 'CPF9801' C MSGTEXT DSPLY C return C endif C if DtaQ_Type = '1' and NOT %ERROR C callp(E) GetDtaQD(DQDataF2 : %size(DQDataF2) : C           'RDQD0200' : DtaQ ) C endif C If Auto_Rcl = '1' C eval AutoRcl = '*YES' C else C eval AutoRcl = '*NO' C endif C If Force_Write = 'Y' C eval ForceWrite = '*YES' C else C eval ForceWrite = '*NO' C endif C If Sender_ID= 'Y' C eval SenderID= '*YES' C else C eval SenderID= '*NO' C endif C Select C When Q_Seq = 'F' C eval DtaQSeq= '*FIFO' C When Q_Seq = 'K' C eval DtaQSeq= '*KEYED' C When Q_Seq = 'L' C eval DtaQSeq= '*LIFO' C endSL **  Convert the numeric entries to left-justified char values C eval MaxLen = %Char(Max_Len) C if Q_Seq = 'K' C eval KeyLen = %Char(Key_Len) C else C eval KeyLen = 'N/A' C endif C eval CurMsgs= %Char(Cur_Msgs) C eval CurCap = %Char(CurEntry_Cap) C eval MaxEntry = %Char(Max_Entry) C eval InitEntry = %Char(Init_Entry) C eval myDate = %Char(QSysDate) C eval myTime = %Char(QSysTime) C Dou FKey = F3 or FKey = ENTER C Exfmt Format1 C enddo

Figure 3: RPG IV Source for DSPDTAQD Program

Once this command is compiled, you can use it to display the description of any data queue for which you have authority.

Figure 4 illustrates an example of the information that is displayed by the DSPDTAQD command.

http://www.mcpressonline.com/articles/images/2002/Display%20Data%20Queue%20Description00.png

Figure 4: The Display from the DSPDTAQD Command (Click image to enlarge.)

Bob Cozzi has been programming in RPG since 1978. Since then, he has written many articles and several books, including The Modern RPG Language --the most widely used RPG reference manual in the world. Bob is also a very popular speaker at industry events such as RPG World and is the author of his own Web site and of the RPG ToolKit, an add-on library for RPG IV programmers.

Robert Cozzi

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.


MC Press books written by Robert Cozzi available now on the MC Press Bookstore .

RPG TnT RPG TnT
Get this jam-packed resource of quick, easy-to-implement RPG tips!
List Price $65.00

Now On Sale

The Modern RPG IV Language The Modern RPG IV Language
Cozzi on everything RPG! What more could you want?
List Price $99.95

Now On Sale

thomasgralwyn.blogspot.com

Source: https://www.mcpressonline.com/programming/rpg/display-data-queue-description

0 Response to "Continuously Read From As400 Data Queue Java"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel