The following examples explain three methods to process data queue files.
In the following example, program B specifies to wait up to 2 hours (7200 seconds) to receive an entry from the data queue. Program A sends an entry to data queue DTAQ1 in library QGPL. If program A sends an entry within 2 hours, program B receives the entries from this data queue. Processing begins immediately. If 2 hours elapse without procedure A sending an entry, program B processes the time-out condition because the field length returned is 0. Program B continues receiving entries until this time-out condition occurs. The programs are written in CL; however, either program could be written in any high-level language.
The data queue is created with the following command:
CRTDTAQ DTAQ(QGPL/DTAQ1) MAXLEN(80)
In this example, all data queue entries are 80 bytes long.
In program A, the following statements relate to the data queue:
PGM DCL &FLDLEN *DEC LEN(5 0) VALUE(80) DCL &FIELD *CHAR LEN(80) . .(determine data to be sent to the queue) . CALL QSNDDTAQ PARM(DTAQ1 QGPL &FLDLEN &FIELD) . . .
In program B, the following statements relate to the data queue:
PGM DCL &FLDLEN *DEC LEN(5 0) VALUE(80) DCL &FIELD *CHAR LEN(80) DCL &WAIT *DEC LEN(5 0) VALUE(7200) /* 2 hours */ . . . LOOP: CALL QRCVDTAQ PARM(DTAQ1 QGPL &FLDLEN &FIELD &WAIT) IF (&FLDLEN *NE 0) DO /* Entry received */ . . (process data from data queue) . GOTO LOOP /* Get next entry from data queue */ ENDDO . . (no entries received for 2 hours; process time-out condition) .
The following example is different from the usual use of data queues
because there is only one job. The data queue serves as a
communications object within the job rather than between two jobs.
In this example, a program is waiting for input from a display file and an ICF file. Instead of alternately waiting for one and then the other, a data queue is used to allow the program to wait on one object (the data queue). The program calls QRCVDTAQ and waits for an entry to be placed on the data queue that was specified on the display file and the ICF file. Both files specify the same data queue. Two types of entries are put on the queue by display data management and ICF data management support when the data is available from either file. ICF file entries start with *ICFF and display file entries start with *DSPF.
The display file or ICF file entry that is put on the data queue is 80 characters in length and contains the field attributes described in the following list. Therefore, the data queue that is specified using the CRTDSPF, CHGDSPF, OVRDSPF, CRTICFF, CHGICFF, and OVRICFF commands must have a length of at least 80 characters.
If the job receiving the data from the data queue has only one display file or one ICF file open, then this is the only field needed to determine what type of entry has been received from the data queue.
The following example shows coding logic that the program previously described might use:
. . . . OPEN DSPFILE ... /* Open the Display file. DTAQ parameter specified on*/ /* CRTDSPF, CHGDSPF, or OVRDSPF for the file. */ OPEN ICFFILE ... /* Open the ICF file. DTAQ parameter specified on */ /* CRTICFF, CHGICFF, or OVRICFF for the file. */ . . DO WRITE DSPFILE /* Write with Invite for the Display file */ WRITE ICFFILE /* Write with Invite for the ICF file */ CALL QRCVDTAQ /* Receive an entry from the data queue specified */ /* on the DTAQ parameters for the files. Entries */ /* are placed on the data queue when the data is */ /* available from any invited device or session */ /* on either file. */ /* After the entry is received, determine which file */ /* has data available, read the data, process it, */ /* invite the file again and return to process the */ /* next entry on the data queue. */ IF 'ENTRY TYPE' FIELD = '*DSPF ' THEN /* Entry is from display */ DO /* file. Since this entry*/ /* does not contain the */ /* data received, the data*/ /* must be read from the */ /* file before it can be */ READ DATA FROM DISPLAY FILE /* processed. */ PROCESS INPUT DATA FROM DISPLAY FILE WRITE TO DISPLAY FILE /* Write with Invite */ END ELSE /* Entry is from ICF */ /* file. Since this entry*/ /* does not contain the */ /* data received, the data*/ /* must be read from the */ /* file before it can be */ /* processed. */ READ DATA FROM ICF FILE PROCESS INPUT DATA FROM ICF FILE WRITE TO ICF FILE /* Write with Invite */ LOOP BACK TO RECEIVE ENTRY FROM DATA QUEUE . . . END
In the following example, the program in Job B is waiting for input from a
display file that it is using and for input to arrive on the data queue from
Job A. Instead of alternately waiting for the display file and then the
data queue, the program waits for one object, the data queue.
The program calls QRCVDTAQ and waits for the placement of an entry on the data queue that was specified on the display file. Job A is also placing entries on the same data queue. There are two types of entries that are put on this queue, the display file entry, and the user-defined entry. Display data management places the display file entry on the data queue when data is available from the display file. Job A places the user-defined entry on the data queue.
The structure of the display file entry is described in the previous example.
The structure of the entry placed on the queue by Job A is defined by the application programmer.
The following example shows coding logic that the application program in Job B might use:
.
.
.
.
OPEN DSPFILE ... /* Open the Display file. DTAQ parameter specified on*/
/* CRTDSPF, CHGDSPF, or OVRDSPF for the file. */
.
.
DO
WRITE DSPFILE /* Write with Invite for the Display file */
CALL QRCVDTAQ /* Receive an entry from the data queue specified */
/* on the DTAQ parameter for the file. Entries */
/* are placed on the data queue either by Job A or */
/* by display data management when data is */
/* available from any invited device on the display */
/* file. */
/* After the entry is received, determine what type */
/* of entry it is, process it, and return to receive */
/* the next entry on the data queue. */
IF 'ENTRY TYPE' FIELD = '*DSPF ' THEN /* Entry is from display */
DO /* file. Since this entry*/
/* does not contain the */
/* data received, the data*/
/* must be read from the */
/* file before it can be */
READ DATA FROM DISPLAY FILE /* processed. */
PROCESS INPUT DATA FROM DISPLAY FILE
WRITE TO DISPLAY FILE /* Write with Invite */
END
ELSE /* Entry is from Job A. */
/* This entry contains */
/* the data from Job A, */
/* so no read is required*/
/* before processing the */
/* data. */
PROCESS DATA QUEUE ENTRY FROM JOB A
LOOP BACK TO RECEIVE ENTRY FROM DATA QUEUE
.
.
.
END
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.