$LIKE: Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (misc cleanup)
 
Line 30: Line 30:
</ul></li>
</ul></li>


<li>The optional <var class="term">eval-lang</var> argument specifies the language to use for evaluation.</li>
<li>The optional <var class="term">eval-lang</var> argument specifies the language to use for evaluation. Its requirements are identical to the <var class="term">parse-lang</var> argument.</li>
</ul>
</ul>



Latest revision as of 23:25, 8 March 2016

The $LIKE function provides total control over the parsing and evaluation languages used in pattern matching. It has two language parameters: one to control the parsing language, LANGUSER, and one to control the evaluation language, LANGFILE.

The LANGLIKE operator and $LIKE function in expressions coordinate to provide consistency between the FIND statement and the IF statement, and avoid complicating the interpretation of the evaluation language parameter.

Syntax

$LIKE(string,pattern[,parse-lang][,eval-lang]])

Where:

  • The string argument represents the characters to verify. It must be one of the following:
    • A literal enclosed in quotation marks.
    • %variable.
    • A field name without quotation marks. In this case, the function call must be embedded in a FOR EACH RECORD loop where the current value of the field is verified.
  • The required pattern argument is the string of characters to verify, which you can specify as a literal enclosed in quotation marks or as a %variable.
  • The optional parse-lang argument specifies the language to use for parsing. The parse-lang argument is handled as follows:
    • Omitting this argument instructs Model 204 to use U.S. English parsing rules, even if the value of the LANGUSER parameter is not US.
    • An asterisk enclosed in quotation marks ('*') instructs Model 204 to use the value of the LANGUSER parameter.
    • You can enter a literal name of a valid language enclosed in quotation marks. If you enter a name that is not supported, the request is canceled with an error message. See LANGUSER parameter for the valid values.
  • The optional eval-lang argument specifies the language to use for evaluation. Its requirements are identical to the parse-lang argument.

Example

The following request matches the field NAME against the pattern (A-Z)*@ using US as the parsing language and TURKISH as the evaluation language.

  • The parsing language, LANGUSER, determines the special characters that can be used in a pattern. The pattern is checked for syntax against these characters. The evaluation language, LANGFILE, is used when the pattern is matched against the data.
  • The evaluation language, LANGFILE, determines the collating sequence and the definition of alphabetic characters.

In this example, the evaluation language is Turkish. Therefore all character matching is done against the Turkish alphabet, and the range operation, (A-Z), uses the collating sequence of the Turkish language.

BEGIN FD1: IN DATA FIND ALL RECORDS END FIND %PAT='(A-Z)*@' FOR EACH RECORD IN FD1 %RC = $LIKE(NAME,%PAT,'US','TURKISH') IF %RC EQ 0 THEN PRINT 'STRING: 'WITH NAME WITH 'does not match PATTERN: - ' WITH %PAT END IF END FOR END