Previous Topic: &MAISPUT

Next Topic: &MSGCONT


&MASKCHK

Returns a string that indicates the matching of a value against a nominated wildcard mask.

&MASKCHK mask data [ wildcard | * ]

&MASKCHK is a built-in function and must be used to the right of an assignment statement.

&MASKCHK is used to perform generic pattern matching. The mask is a string of characters containing wildcard characters, by default asterisks (*), which imply that any character is accepted in positions occupied by wildcard characters, when testing the data string.

This provides a rapid way of determining if the target data is within an acceptable range, or matches specific selection criteria.

Testing the mask against data is performed on a character by character basis moving from left to right. After this comparison, one of the following values is returned:

EQ

The data matches the supplied mask and is the same length as the mask.

EQL

The data matches the supplied mask, but is longer than the mask. This implies the supplied mask contains a wildcard character as its last character.

EQS

The data matches the supplied mask, but is shorter than the mask.

NE

The data does not match the supplied mask.

Operands:

mask

A selection mask from 1 to 256 characters in length containing one or more wildcard characters. By default the wildcard character is an asterisk (*), but an alternative character is specified. A wildcard character within mask implies that any value in that data position is accepted. If the last character of mask is a wildcard character, then no further data checking is performed and any trailing characters are accepted.

data

1 to 256 characters of target data to be scanned to see if it matches the selection criteria established by mask.

wildcard | *

A single character regarded as a wildcard character. By default an asterisk is used. Multiple occurrences of this character, in any position of mask is acceptable.

Examples: &MASKCHK

&A = &MASKCHK IST* &MSGID
&IF &A = EQ &THEN +
   &GOSUB .PROCESSIST
&A = &MASKCHK ABC* ABCD   -* &A will be set to EQ
&A = &MASKCHK A*C* ABCD   -* &A will be set to EQ
&A = &MASKCHK %%C% A*CD % -* &A will be set to EQ
&A = &MASKCHK ABC* ABCDE  -* &A will be set to EQL
&A = &MASKCHK ABC* ABC    - * &A will be set to EQS
&A = &MASKCHK ABC* DEF    -* &A will be set to NE

Note:

When using &MASKCHK, a procedure must allow for when a value of EQ, EQL, or EQS is returned. In such cases the following approach is used:

&A = &MASKCHK P* &TERM &IF &A NE NE &THEN &WRITE Mask matched successfully