Reading Fields Containing all Mask Characters in CA-Ideal Programs

Document ID : KB000056296
Last Modified Date : 14/02/2018
Show Technical Document Details

Question:

What to do if you need to read fields containing all mask characters in CA Ideal Programs.

Environment:

z/OS

Answer:

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:

            Transmit a panel that prompts for as many field values as necessary.

            For each empty panel field, move a string that is the length of the field, containing all mask characters, into the panel field or in the panel definition, make the             input fill character the same as the mask character.

            Retrieve records from the database using a FOR, where each field contains the panel field value (either the value entered by the user or all mask characters).

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: ____
Purchase Order Number: __________
Order Date (yymmdd): ______



 

ORDER LOOK-UP RESULTS

Order#  Cust#   P.O.#        Date
01008   7290    0000001526   851106
01009   7350    0000009384   851106
01010   2690    0000003764   851106
01011   0030    0000008374   851106
01012   0030    0000001524   851108
01013   0230    0000002341   851108
01015   1210    0000002567   851108
01016   1450    0000008746   851108
01017   1630    0000002289   851108
01018   1890    0000007652   851108



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
Purchase Order Number: __________
Order Date (yymmdd): 851106



 

ORDER LOOK-UP RESULTS

Order#  Cust#   P.O.#        Date
01011   0030    0000008374   851106