Dataqueues

180 Views


Communicating between programs and procedures

Programs and procedures can communicate by using data queues and data areas.

Using data queues

Data queues are a type of system object that you can create, to which a program can send data, and from which another program can receive data.

The receiving program can be already waiting for the data, or can receive the data later.

Journaling also provides for replication of the data queue journal to a remote system

The following example shows how data queues work. Several jobs place entries on a data queue and these entries are read by a server job. Any number of jobs can send to the same queue.

A primary job gets the work requests and sends the entries to a data queue (by calling the QSNDDTAQ program).

The server jobs receive the entries from the data queue (by calling the QRCVDTAQ program) and process the data.

The server jobs can report status back to the primary job using another data queue.

Data queues allow the primary job to route the work to the server jobs. This frees the primary job to receive the next work request. Any number of server jobs can receive from the same data queue.

When no entries are on a data queue, server jobs have the following options:

• Wait until an entry is placed on the queue

• Wait for a specific period of time; if the entry still has not arrived, then continue processing

• Do not wait, return immediately.

Example program which send entry into dataqueue. Progarm A.

0011.00              PGM           
0016.00              DCL        VAR(&DATA) TYPE(*CHAR) LEN(4034)      
0017.00              DCL        VAR(&LIB) TYPE(*CHAR) LEN(10)         
0022.00              DCL        VAR(&DATAQ) TYPE(*CHAR) LEN(10) +                 
0023.00                           VALUE('TESTDTAQ')                             
0024.00              DCL        VAR(&LEN) TYPE(*DEC) LEN(5 0) VALUE(4034)         
0036.00 /*---------------------------------------------------------------*/  
0037.00 /* Send data to data queue.                                      */  
0038.00 /*---------------------------------------------------------------*/  
0039.00  SENDDATA:   CALL       PGM(QSNDDTAQ) PARM(&DATAQ &LIB &LEN &DATA)   
0052.00 /*---------------------------------------------------------------*/       
0053.00 /* End Program.                                                  */       
0054.00 /*---------------------------------------------------------------*/       
0055.00  END:        ENDPGM                                                       

Example program which received dataqueue entry. Progarm B.

0029.01              PGM        PARM(&DTQNAME &DTAQLIB &DTAQLEN &FDATE &TDATE)                  
0029.02              DCL        VAR(&FDATE) TYPE(*CHAR) LEN(8)                                  
0029.03              DCL        VAR(&TDATE) TYPE(*CHAR) LEN(8)                                  
0039.11              DCL        VAR(&DTQNAME) TYPE(*CHAR) LEN(10)                               
0039.12              DCL        VAR(&DTAQLIB) TYPE(*CHAR) LEN(10)                               
0039.13              DCL        VAR(&DTAQLEN) TYPE(*DEC) LEN(5)                                 
0039.15              DCL        VAR(&DATA) TYPE(*CHAR) LEN(9)                                   
0039.16              DCL        VAR(&WAITTIM) TYPE(*DEC) LEN(5) VALUE(0)                        
0039.17 READDTQ:                                                                                
0040.15 /* Read Data Queue                                                   */                 
0040.17              CALL       QRCVDTAQ PARM(&DTQNAME &DTAQLIB &DTAQLEN +                      
0040.18                               &DATA &WAITTIM)                                           
0040.19                                                                                         
0041.00 /*If DTAQ not empty, call Pgm TESTPGM to process order */                 
0041.01              IF         COND(&DTAQLEN *NE 0) THEN(DO)                                   
0042.02              CALL       PGM(TESTPGM) PARM(' ' &DATA &FDATE &TDATE)                    
0042.32              GOTO       READDTQ                                                         
0042.34              ENDDO                                                                      
0042.35                                                                                         
0042.36 /*If DTAQ empty, go to end program                                   */                 
0069.00 END:        ENDPGM   

 

Remote data queues

Remote data queues are data queues that reside on a remote system.

You can access remote data queues with distributed data management (DDM) files.

DDM files make it possible for a program residing on one system to access a data queue on a remote system to perform any of the following functions:

• Send data to a data queue

• Receive data from a data queue

• Clear data from a data queue

An application program that currently uses a standard data queue can also access a remote DDM data queue without changing or compiling the application again.

To ensure the correct data queue is accessed, you may need to do one of the following:

• Delete the standard data queue and create a DDM data queue that has the same name as the original standard data queue.

• Rename the standard data queue. You can create a DDM data queue with the following command:

CRTDTAQ DTAQ(LOCALLIB/DDMDTAQ) TYPE(*DDM)
 RMTDTAQ(REMOTELIB/REMOTEDTAQ) RMTLOCNAME(SYSTEMB)
 TEXT('DDM data queue to access data queue on SYSTEMB')

The master job resides on SystemA; the data queues and server jobs are moved to SystemB.

After creating two DDM data queues (INPUT and STATUS), the master job continues to communicate asynchronously with the server jobs that reside on SystemB. The following example shows how to create a DDM data queue with remote data queues:

CRTDTAQ DTAQ(LOCALLIB/INPUT) TYPE(*DDM)
 RMTDTAQ(REMOTELIB/INPUT) RMTLOCNAME(SystemB)
 TEXT('DDM data queue to access INPUT on SYSTEMB')

CRTDTAQ DTAQ(LOCALLIB/STATUS) TYPE(*DDM)
 RMTDTAQ(REMOTELIB/STATUS) RMTLOCNAME(SystemB)
 TEXT('DDM data queue to access STATUS on SYSTEMB')

The master job calls QSNDDTAQ, then passes the data queue name of LOCALLIB/INPUT and sends the data to the remote data queue (REMOTELIB/INPUT) on SystemB. To receive data from the remote data queue, (REMOTELIB/STATUS), the master job passes the data queue name of LOCALLIB/STATUS for the call to QRCVDTAQ.

Data queues have been improved to communicate between active procedures and programs.

Prerequisites for using data queues

Before using a data queue, you must first create it using the Create Data Queue (CRTDTAQ) command.

The following is an example:

CRTDTAQ DTAQ(MYLIB/INPUT) MAXLEN(128) TEXT('Sample data queue')

Managing the storage used by a data queue

If a data queue has grown too large, delete the data queue by using the Delete Data Queue (DLTDTAQ) command.

On completion of the data queue deletion, re-create the queue by using the Create Data Queue (CRTDTAQ) command.

Allocating data queues If all users of a data queue allocate it before using it, this helps to ensure that a data queue is not accessed by more than one job at a time.

If your application requires that a data queue is not accessed by more than one job at a time, it should be coded to include an Allocate Object (ALCOBJ) command before using a data queue. The data queue should then be deallocated using the Deallocate Object (DLCOBJ) command when the application is finished using it.

Take this command to see entries in dataqueue: TAATOOL/DSPDTAQ DTAQ(TESTDTAQ)

Once the entry is put into dataqueue, it appears like this. Like this, it can have many entries.

When Option 1 is taken , this is now the dataqueue entry data looks like.

Post Comments