$LangSrt

From m204wiki
Revision as of 20:11, 9 March 2015 by JAL (talk | contribs) (misc cleanup)
Jump to navigation Jump to search

$LangSrt translates a given string according to the specified language into a language-neutral binary string against which you can sort.

By determining whether one string is greater or less than another string, you can use the $LangSrt function to compare two strings. First apply the $LangSrt function to the strings and then compare them using the SOUL greater-than (GT) and less-than-or-equal-to (LT) operators.

Syntax

$LangSrt('string'[,language])

Where:

  • The string argument is a literal enclosed in quotation marks or a %variable containing the original data to be translated into collating sequence.
  • The optional language argument is the name of one of the defined languages, which specifies which collating sequence to use. The language argument is handled as follows:
    • If you omit the language argument, Model 204 performs the validation in U.S. English, even if the value of the LANGUSER parameter is not US, and lowercase characters are not recognized.
    • An asterisk enclosed in quotation marks ('*') instructs Model 204 to use the value of the LANGUSER parameter.
    • You can enter the name of a valid language enclosed in quotation marks or a %variable containing a valid language. If you enter value that is not supported, the request is canceled with an error message. See the LANGUSER parameter for the valid values.

Note: The $LangSrt function returns the string unchanged if the language is U.S. English.

Example

The following procedure stores the value of NAME from each record into array %STR. The $LangSrt function translates each value of NAME into a language-specific collating sequence and stores the value into the array %SORTSTR. The procedure then calls a user-written subroutine, MYSORT, that sorts the %SORTSTR array in ascending order. At this point the procedure invokes the $LangSrt function to translate the collating string back to its original form and prints the names in language-specific order.

BEGIN DECLARE SUBROUTINE MYSORT (STRING LEN 20 ARRAY(*)) %STR STRING LEN 20 ARRAY (20) NO FS %SORTSTR STRING LEN 20 ARRAY (20) * FD1: IN DATA FIND ALL RECORDS END FIND %I = 1 FOR EACH RECORD IN FD1 %STR(%I) = NAME %I = %I + 1 END FOR FOR %J FROM 1 TO %I-1 %SORTSTR(%J) = $LANGSRT(%STR(%J),'TURKISH') END FOR * * SORT NAMES * CALL MYSORT(%SORTSTR) * FOR %J FROM 1 TO %I-1 %STR(%J) = $LANGUST(%SORTSTR(%J),'TURKISH') PRINT %STR(%J) END FOR END