Progress/400
Product Guide


Using the LOOKUP and SUBSTRING Functions with Send Data

When using the SUBSTRING function to process send data in conjunction with a LOOKUP function, do not use the following syntax:

IF LOOKUP(SUBSTRING(send-data,1,1),entry-list) = 0 THEN your-code 

The entry-list variable contains a list of values known to be in the first position, but this syntax fails. If you reassign the send-data variable to another CHARACTER variable within the same procedure as the LOOKUP function, the syntax works correctly.

If you use the SUBSTRING function without doing a LOOKUP, as shown in the following syntax, the SUBSTRING function works correctly:

IF SUBSTRING(send-data,1,1) = "A" THEN your-code 

RECEIVE DATA QUEUE (rcvdtaqe.p) API

Table 11–19 describes the parameters that you must pass to the RECEIVE DATA QUEUE API. You can use the same variable names or names of your own choice. Note that you must pass all of these parameters to the API, and they must be in the same order as in Table 11–19.

Table 11–19: RECEIVE DATA QUEUE (rcvdtaqe.p) Parameters
Parameter Name
Parameter Type and Data Type
Value
db-name
INPUT
CHARACTER
The name of a connected DB2/400 database that contains the QDTAQ-ENTRY table. The database must be connected before the call to the API because an alias will be defined for the database that allows any DB2/400 database to use the API.
que-name
INPUT
CHARACTER
The name of the data queue on the AS/400. This data queue must have been created before using the API.
library-name
INPUT
CHARACTER
The library name where the data queue resides.
key-data
INPUT
CHARACTER
If the data queue was created to use a key, the data for the key.
If the data queue is not keyed, assign this parameter to blank.
key-length
INPUT
INTEGER
If the data queue was created to use a key, the length of the key specified when the data queue was created.
If the data queue is not keyed, assign 0 to this parameter.
key-order
INPUT
CHARACTER
The operand for the key data. The parameter can contain one of the following values: EQ, GE, GT, LE, LT, NE, =, >=, <, <=, <, <>.
If the data queue is not keyed, assign blanks to this parameter.
wait-time
INPUT
INTEGER
The amount of time, in seconds to wait for an entry.
If a negative number is specified, the API waits until an entry is available.
If zero is specified, the API returns immediately.
A positive number specifies the number of seconds that the API should wait.
sender-Data
INPUT/OUTPUT
CHARACTER
Notifies the API whether the sender data is wanted and should be returned. Assign Y to the variable if you want data and N or blank if you do not.
The maximum length available is 64 bytes but the maximum length returned is 56: the first eight bytes are not valid to
Progress and are removed before being returned. See the IBM System API Reference for an explanation of the first eight bytes.
entry-data
OUTPUT
CHARACTER
The entry removed from the data queue. You must know what the data will contain in order to process it with the SUBSTRING function for use in your procedure. Be careful about having the hex character zero in the data:
Progress interprets the hex character zero as a NULL and the end of the data.
For additional information on using the SUBSTRING function, see the "Using the LOOKUP and SUBSTRING Functions with Send Data" section.
Status
OUTPUT
INTEGER
A return parameter that indicates whether the entry has been placed on the data queue.

The following example illustrates calling the RECEIVE DATA QUEUE API from your code:

RUN as4dict/rcvdtaqe.p (INPUT db-name, INPUT que-name, 
                        INPUT library-name, INPUT key-data, 
                        INPUT key-length, INPUT key-order, 
                        INPUT wait-time, INPUT/OUTPUT sender-data, 
                        OUTPUT entry-data, OUTPUT status), 

To verify that an entry has been received, check the value of the OUTPUT parameter. Table 11–20 lists possible return values.

Table 11–20: RECEIVE DATA QUEUE (rcvdtaqe.p) Return Values 
Status
Reason
Client
-1
Either the DB2/400 database name is incorrect or the database is not connected.
Remote only
-2
The named DB2/400 database does not contain the QDTAQ-ENTRY table.
Remote only
-3
The operand in the key-order parameter did not contain a correct value.
Remote and native
#
The length of the data entry. This number can be any value from 0, which means that no entry was returned, to the length of the data.
Remote and native

Data Queue Coding Examples

The examples in this section illustrate how to send and receive entries from unkeyed and keyed data queues.

The first example sends and receives an entry from an unkeyed data queue:

DEFINE VARIABLE db-name   AS CHARACTER NO-UNDO. 
DEFINE VARIABLE que-name  AS CHARACTER NO-UNDO. 
DEFINE VARIABLE lib-name  AS CHARACTER NO-UNDO. 
DEFINE VARIABLE ent-data  AS CHARACTER NO-UNDO. 
DEFINE VARIABLE ky-data   AS CHARACTER NO-UNDO. 
DEFINE VARIABLE ky-length AS INTEGER  NO-UNDO. 
DEFINE VARIABLE wait-time AS INTEGER  NO-UNDO. 
DEFINE VARIABLE key-order AS CHARACTER NO-UNDO. 
DEFINE VARIABLE stat      AS INTEGER   NO-UNDO. 
DEFINE VARIABLE send-data AS CHARACTER NO-UNDO. 
ASSIGN db-name   = "mydb" 
       que-name  = "dtaqnokey" 
       lib-name = "mydb" 
       ent-data  = "Sending data to unkeyed data queue" 
       ky-data   = "" 
       key-order = "" 
       ky-length = 0. 
/* An example of sending an entry to a data queue */ 
RUN as4dict/snddtaqe.p (INPUT db-name, INPUT que-name, 
                        INPUT lib-name, INPUT ent-data, 
                        INPUT ky-data,  INPUT ky-length, 
                        OUTPUT stat). 
/* Entry is placed on queue if stat variable equals 0 */ 
IF stat = 0 THEN DO: 
   ASSIGN wait-time = 0 
   send-data = "Y". 
/*An example of requesting an entry from a data queue */ 
RUN as4dict/rcvdtaqe.p (INPUT db-name, INPUT que-name, 
                        INPUT lib-name, INPUT ky-data, 
                        INPUT ky-length, INPUT key-order, 
                        INPUT wait-time INPUT-OUTPUT send-data, 
                        OUTPUT ent-data, OUTPUT stat). 
/* stat will be the length of the entry received or 0 if not received. */ 
IF STAT > 0 THEN 
   DISPLAY ent-data FORMAT "x(40)" send-data format "x(56)"  
   WITH FRAME entry NO-LABELS. 
ELSE 
   DISPLAY stat WITH FRAME status NO-LABELS. 
END. 

This example sends and receives an entry from a keyed data queue. This data queue was created with a key length of 10 and a request for sender information:

DEFINE VARIABLE db-name   AS CHARACTER NO-UNDO. 
DEFINE VARIABLE que-name  AS CHARACTER NO-UNDO. 
DEFINE VARIABLE lib-name  AS CHARACTER NO-UNDO. 
DEFINE VARIABLE ent-data  AS CHARACTER NO-UNDO. 
DEFINE VARIABLE ky-data   AS CHARACTER NO-UNDO. 
DEFINE VARIABLE ky-length AS INTEGER NO-UNDO. 
DEFINE VARIABLE wait-time AS INTEGER NO-UNDO. 
DEFINE VARIABLE key-order AS CHARACTER NO-UNDO. 
DEFINE VARIABLE stat      AS INTEGER   NO-UNDO. 
DEFINE VARIABLE send-data AS CHARACTER NO-UNDO. 
ASSIGN db-name    = "mydb" 
       que-name  = "keyedqueue" 
       lib-name  = "mydb" 
       ent-data  = "Sending data to a keyed queue" 
       ky-data   = "myname" 
       key-order = "EQ" 
       ky-length = 10. 
/* An example of sending an entry to a data queue */ 
RUN as4dict/snddtaqe.p (INPUT db-name, INPUT que-name, 
                        INPUT lib-name, INPUT ent-data, 
                        INPUT ky-data, INPUT ky-length, 
                        OUTPUT stat). 
/* Entry is placed on queue if stat variable equals 0 */ 
IF stat = 0 THEN DO: 
   ASSIGN wait-time = 0 
   send-data = "Y". 
/*An example of requesting an entry from a data queue */ 
RUN as4dict/rcvdtaqe.p (INPUT db-name, INPUT que-name, 
                        INPUT lib-name, INPUT ky-data, 
                        INPUT ky-length, INPUT key-order, 
                        INPUT wait-time INPUT-OUTPUT send-data, 
                        OUTPUT ent-data, OUTPUT stat). 
/* stat will be the length of the entry received or 0 if not received. */ 
IF STAT > 0 THEN 
   DISPLAY ent-data FORMAT "x(40)" send-data format "x(56)". 
ELSE 
   DISPLAY stat. 
END. 


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095