$Oneof: Difference between revisions
(Automatically generated page update) |
|
(No difference)
|
Latest revision as of 14:06, 29 July 2014
The $ONEOF function is a table lookup function that can replace a series of IF conditions.
Syntax
$ONEOF('item','set',delimiter')
where:
- item is an element that might be in set.
- set is one or more items
- delimiter is the character used to separate the set items.
Example
$ONEOF('MALE','FEMALE/MALE','/') equals 1 $ONEOF('GRAY','BLACK*WHITE*GRAY','*') equals 1
- If the delimiter argument is omitted, the default delimiter value is a semicolon (;), which is used to separate items in the second argument. For example:
- If the second argument is null, or if the first argument is not an element of the second argument, 0 (false) is returned. For example:
- You can enter null values as the following examples show.
- If a long string of values is used frequently, a special record containing those values can be useful. In the following example, a record is created with a field consisting of a list of departments. The list is used in the second request to locate and process records for which the department is not known.
$ONEOF('FEMALE','FEMALE;MALE') equals 1
$ONEOF code is less confusing if you explicitly specify a delimiter value and do not accept the default delimiter value, a semicolon (;). Accepting the default value can cause confusion, because the default LINEND character is also a semicolon.
$ONEOF('BOY','FEMALE;MALE') equals 0 $ONEOF(",'FEMALE;MALE') equals 0 $ONEOF('BOY',") equals 0
$ONEOF(",';FEMALE;MALE') equals 1 $ONEOF(",'FEMALE;;MALE') equals 1 $ONEOF(",'FEMALE;MALE;') equals 1
BEGIN DECLARE %DEPT STRING LEN 50 STORE RECORD TABLE = VALS DEPT VALS = DEPT1/DEPT2/DEPT3/etc. END STORE END . . . BEGIN FIND.RECS: FIND ALL RECORDS FOR WHICH TABLE = VALS END FIND FOR EACH RECORD IN FIND.RECS %DEPT = DEPT VALS END FOR PAY.RECS: FIND ALL RECORDS FOR WHICH TYPE = PAYROLL END FIND FOR EACH RECORD IN PAY.RECS IF NOT $ONEOF(DEPT,%DEPT,'/') THEN . . .