What to do if you need to read fields containing all mask characters in Ideal programs.
Release: Ideal for Datacom
Suppose your application needs to retrieve records from a database based on selection criteria entered by the user at the terminal. The program needs to use any selection value specified by the user, but should ignore any value not provided by the user.
For example, the user may be requesting order records. If only the order date is entered, the program will display all orders for that date. If the customer number is also entered, the program will limit the orders to that date and customer number. You will retrieve only those orders that match the specified criteria.
You can program this retrieval with a single FOR statement. The trick is to code a WHERE condition with all search fields as objects of CONTAINS relational operators and to fill any fields that have not been specified with the mask character.
Note: | CONTAINS is a CBS-only operator. SQL has a similar LIKE operator, but it is not identical in operation, so you will have to modify this technique a little for SQL dataviews. |
The mask character is used in a WHERE condition to "skip" one or more characters in a CONTAINS or NOT CONTAINS expression. The default mask character is an asterisk (*). For example:
WHERE FIELD-A CONTAINS ‘*A*BC*’
This expression searches for values of FIELD-A that have an A in position 2 and a BC in positions 4 and 5, respectively, regardless of what characters are in positions 1, 3, and 6.
A CONTAINS expression consisting of only the mask character, of the same length as the subject field, matches all candidate records. For example:
WHERE FIELD-A CONTAINS ‘******’
Note: | This test does not incur any significant overhead; it always evaluates TRUE without having to read any data. |
Using this feature, you can program the application described above as follows:
The following example retrieves the first ten records based on the values supplied by the user for any of three fields – CUST-NO defined as X(4), CUST-PO defined as X(10), and ORD-DT defined as X(6). To make clear what is going on, the example uses a SELECT construct to move mask characters into any empty fields. If you make the input fill character the same as the mask character, eliminate this code.
LOOP
TRANSMIT ORD-ASK CLEAR
WHILE $PANEL-ERROR
ENDLOOP
:
SELECT EVERY ACTION
WHEN $EMPTY (ORD-ASK.CUST-NO)
MOVE ‘****’ TO ORD-ASK.CUST-NO
WHEN $EMPTY (ORD-ASK.CUST-PO)
MOVE ‘**********’ TO ORD-ASK.CUST-PO
WHEN $EMPTY (ORD-ASK.ORD-DT)
MOVE ‘******’ TO ORD-ASK.ORD-DT
ENDSEL
:
REFRESH ORD-LOOK
FOR FIRST 10 ORDER-DV
WHERE ORDER-DV.CUST-NO CONTAINS ORD-ASK.CUST-NO
AND ORDER-DV.CUST-PO CONTAINS ORD-ASK.CUST-PO
AND ORDER-DV.ORD-DT CONTAINS ORD-ASK.ORD-DT
MOVE $COUNT (FOR10) TO KOUNT
MOVE ORDER-DV.ORD-ID TO ORD-LOOK.ORD-ID (KOUNT)
MOVE ORDER-DV.CUST-NO TO ORD-LOOK.CUST-NO (KOUNT)
MOVE ORDER-DV.CUST-PO TO ORD-LOOK.CUST-PO (KOUNT)
MOVE ORDER-DV.ORD-DT TO ORD-LOOK.ORD-DT (KOUNT)
WHEN NONE
MOVE ‘NOT FOUND’ TO ORD-LOOK.ORD-MSG
ENDFOR
TRANSMIT ORD-LOOK
. . .
If the user does not enter any values, the program retrieves the first ten records regardless of field value.
ORDER LOOK-UP
Please Identify Orders. Customer Number: ____ |
ORDER LOOK-UP RESULTS
Order# Cust# P.O.# Date |
If the user enters values for Customer Number and Order Date, the program retrieves records that match those field values (up to 10 records).
ORDER LOOK-UP
Please Identify Orders. Customer Number: __30 |
ORDER LOOK-UP RESULTS
Order# Cust# P.O.# Date |