Previous Next

LOOKUP function
Returns an INTEGER value giving the position of an expression in a list. Returns a 0 if the expression is not in the list.
Syntax 
 
LOOKUP ( expression , list [ , character ] )
expression
A constant, field name, variable name, or expression that results in a character value that you want to look up within a list of character expressions. If the value of expression is the Unknown value (?), the result of the LOOKUP function is the Unknown value (?).
list
A character expression that contains the expression you name with the expression argument. Each entry in the list is separated with a delimiter. The list can be a variable of type CHARACTER or LONGCHAR. If list contains the Unknown value (?), LOOKUP returns the Unknown value (?).
character
A delimiter you define for the list. The default is a comma. This allows the LOOKUP function to operate on non-comma-separated lists.
Examples 
This procedure prompts the user for a New England state. The LOOKUP function tests the value against the list of states stored in the stlist variable. If there is no match (the result is 0), the procedure displays a message. Otherwise, the procedure prompts the user for another New England state.
 
DEFINE VARIABLE stlist AS CHARACTER NO-UNDO
  INITIAL "ME,MA,VT,RI,CT,NH".
DEFINE VARIABLE state  AS CHARACTER NO-UNDO FORMAT "x(2)".
 
REPEAT:
  SET state LABEL "Enter a New England state, 2 characters".
  IF LOOKUP(state, stlist) = 0 THEN 
    MESSAGE "This is not a New England state".
END.
The following example uses a different delimiter, which list all fields that have “sls” or “sales” as words in their standard Dictionary labels:
 
FOR EACH _Field
  WHERE LOOKUP("sls",_Field._Label," ") > 0
     OR LOOKUP("sales",_Field._Label," ") > 0:
 
  DISPLAY _Field._Field-Name _Field._Label.
END.
Notes 
*
If expression contains a delimiter, LOOKUP returns the beginning of a series of entries in list. For example, LOOKUP("a,b,c","x,a,b,c") returns a 2.
*
*
The LOOKUP function is double-byte enabled. The specified expression can yield a string value that contains double-byte characters and the character delimiter can be a double-byte character.
*
See also 
ENTRY function, ENTRY statement, INDEX function

Previous Next
© 2013 Progress Software Corporation and/or its subsidiaries or affiliates.