Lookup Table Functions
Last updated
Last updated
Lookup table functions serve for lookup and manipulation with lookup tables. (See .) To use the lookup table function, you need to specify the name of the lookup table as an argument of the lookup()
function.
Do not use the functions shown below in the init(), preExecute() or postExecute() functions of CTL template!
The count()
function returns the number of records whose key value equals to keyValue
.
The count()
function used with DB lookup tables may return -1 instead of real count of record with specified key value (if you do not set Max cached size to a non-zero value).
The lookup name
is simply a name of the lookup table. It is **not **specified as a string enclosed with "
character.
The keyValue
is a value of a key of the lookup table. If the lookup table has a key of one field, keyValue
is one string. If the lookup table has a key of more fields, keyValue
is specified as series of the values of particular key parts.
See the documentation of the particular lookup table for handling of duplicated keys.
Example 334. Usage of count A lookup table with a one-field key.
A lookup table with a key of two fields.
See also: get, Allow key duplicates
The function get
searches the first record whose key value is equal to the value specified in the get(keyValue)
function.
It returns the record of the lookup table. You can map it to other records in CTL2 (with the same metadata). If you want to get the value of the field, you can add the .
part to the expression or .* to get the values of all fields.
If there is no record with the requested keyValue
in the lookup table, the function returns null
.
The keyVal
in the function is a sequence of values of the field names separated by comma (not semicolon!). The key has the following form: keyValuePart1,keyValuePart2,…​,keyValuePartN
.
Example 335. Usage of get
There is a lookup table users
having fields name, surname, phone
. The key is formed by fields name
and surname
.
The phone of John Smith
is acquired by the statement:
You can get the whole record:
As the get()
function returns null
if no record is found, getting the whole records allows you to do better error handling.
See also: count, next, put
The next()
function allows you to iterate the result of the search. It moves the pointer to the next record and returns this record.
It returns the next record with the same key. If there is no such record, it returns null
.
Example 336. Usage of next The basic usage:
The next()
function is generally used in combination with get()
function:
See also: get, isnull
The put()
function stores the record passed as its argument in the selected lookup table.
It returns a boolean result indicating whether the operation has succeeded or not.
Note that the metadata of the passed record must match the metadata of the lookup table.
The operation may not be supported by all types of lookup tables (it is not supported by Database lookup tables, for example) and its exact semantics is implementation-specific (in particular, the stored records may not be immediately available for reading in the same phase).
Example 337. Usage of put
Example 338. Usage of Lookup Table Functions A UsersLookup lookup table contains Firstname, Surname, and Username columns. Firstname and Surname fields form the key. Lookup all Usernames for each particular Firstname and Surname tuple received from an input port.
See also: ,