MATCH


 

The MATCH instruction compares two character strings or two RECORDS. The instruction uses the following format:

 

 

[label]

MATCH

{source}{sep}{dest}[{sep}{wildcard}]

 

Where:

label

Optional. A Program Execution Label.

source

Required. A previously defined Character String Variable, National Character String Variable, Literal, National Character String Literal, or RECORD that is compared to the {dest} operand.

sep

Required. A comma or one of the following prepositions: BY, TO, OF, FROM, USING, WITH, IN, or INTO.

dest

Required. A previously defined Character String Variable, National Character String Variable, Literal, National Character String Literal, or RECORD that is compared to the {source} operand.

wildcard

Required. A previously defined Character String Variable, National Character String Variable, or constant character indicating source variable wildcard characters.

Flags Affected: EOS, LESS, ZERO

Note the following:

  1. Only the Logical String contents of the {source} and {dest} strings are compared.

  2. None of the operands, nor their Form Pointers or Length Pointers change.

  3. If either operand is a Null String, the LESS and EQUAL Condition Flags are not set (both FALSE) and the EOS Condition Flag is set.

  4. The operand length is defined as:

    LENGTH = Length Pointer - Form Pointer + 1
     

  5. If all characters matched are equal, the EQUAL (or ZERO) Condition Flag is set. The instruction then makes the following calculation:

    X = DESTINATION LOGICAL LENGTH - SOURCE LOGICAL LENGTH

    If X is negative, the LESS Condition Flag is set.
     

  6. If all characters compared are not equal, the instruction makes the following calculation based on the hexadecimal value of the first non-matching character:

    X = DESTINATION HEX VALUE - SOURCE HEX VALUE

    If X is negative, the LESS Condition Flag is set.
     

  7. The optional third parameter ({wildcard}) specifies a character that is treated as a don't care or wildcard character. If the specified character exists in the {source} operand, it matches any character in the destination operand that occupies the same relative position. If {wildcard} is a character string variable, the Form Pointed character is used.

  8. If the operands are RECORDs, the MATCH operation is an absolute comparison of each byte in {source} to the corresponding byte in {dest}. The comparison is not being performed on a per member basis and therefore the {wildcard} parameter is not allowed. Specification of the {wildcard} parameter will produce a warning message by the compiler. The MATCH instruction does not support record pointers.

 

Example 1:

 

  

MATCH

SENDING TO RECVING

 

 

Variable

PL

FP

LP

Contents

Before:

SENDING

12

1

5

12345ABCDE··

 

RECVING

12

6

10

ABCDE12345··

 

After:

Both variables remain unchanged.

 

The EQUAL (or ZERO) Condition Flag is set.

 

Example 2:

 

 

Variable

PL

FP

LP

Contents

Before:

SENDING

12

1

5

12345ABCDE··

 

RECVING

12

6

9

ABCDE12345··

 

After:

Both variables remain unchanged.

 

The EQUAL (or ZERO) Condition Flag is set. The LESS Condition Flag is also set because the destination field is shorter than the source field.

 

Example 3:

 

 

Variable

PL

FP

LP

Contents

Before:

SENDING

12

1

5

12345ABCDE··

 

RECVING

12

6

10

ABCDE12245··

 

After:

Both variables remain unchanged.

 

The LESS Condition Flag is set.

 

Example 4:

 

  

MATCH

"ABCD" TO RECV(4)

 

 

Variable

PL

FP

LP

Contents

Before:

RECV(4)

10

1

10

12345ABCDE

 

After:

RECV(4) remains unchanged.

 

The LESS Condition Flag is set. The hexadecimal value of numeric characters is less than that of alphabetic characters.

 

Example 5:

 

 

Variable

PL

FP

LP

Contents

Before:

RECV(4)

10

6

10

12345ABCDE

 

After:

RECV(4) remains unchanged.

 

The EQUAL (or ZERO) Condition Flag is set. The source operand was shorter than the destination operand. Therefore, the LESS Condition Flag is not set (FALSE).

 

Example 6:

 

 

Variable

PL

FP

LP

Contents

Before:

RECV(4)

10

6

10

12345ABXXX

 

After:

RECV(4) remains unchanged.

 

No Condition Flags are set (all FALSE). The first non-matching source character (C) is less than the first non-matching destination character (X).

 

Example 7:

 

  

MATCH

FIELD1 TO FIELD2 WITH "?"

 

 

Variable

PL

FP

LP

Contents

Before:

FIELD1

15

1

5

SM?TH··········

 

FIELD2

20

1

15

SMYTHE, JOHN A. ······

 

After:

Both variables remain unchanged.

 

The EQUAL (or ZERO) Condition Flag is set.

 

Example 8:

 

  

MATCH

RECORD1 TO RECORD2

 

 

Variable

PL

FP

LP

Contents

Before:

RECORD1.FIELD1

15

1

5

SMITH··········

 

RECORD1.FIELD2

20

1

7

JOHN A. ············

Before:

RECORD2.FIELD1

15

1

5

SMITH··········

 

RECORD2.FIELD2

20

1

7

JOHN A. ············

 

After:

Both RECORDs remain unchanged.

 

The EQUAL (or ZERO) Condition Flag is set.

 

Example 9:

 

  

MATCH

RECORD1 TO RECORD2

 

 

Variable

PL

FP

LP

Contents

Before:

RECORD1.FIELD1

15

1

5

SMITH··········

 

RECORD1.FIELD2

20

1

7

JOHN A. ············

 

RECORD2.FIELD1

15

1

5

SMITH··········

 

RECORD2.FIELD2

20

1

6

JOHN A. ············

 

After:

Both RECORDs remain unchanged.

 

The EQUAL (or ZERO) Condition Flag is cleared. The Logical Length of the second field is shorter in the second record.

 

 

 

See Also: MATCHLIST, CMATCH, Character String Instructions

 



PL/B Language Reference LOWERCASE MOVEFPTR