getdictionarykey(
DICTIONARY
,
VALUE
)

The getdictionarykey( function returns the key of an item in the dictionary, given its value). This is essentially the opposite of the getdictionaryvalue( function (see Data Dictionaries).


Parameters

This function has two parameters:

dictionary – is the name of the field or variable that contains the dictionary (must contain binary data).

value – is the value associated with the key you want to retrieve. If there are multiple objects with this value, it is indeterminate which key will be returned.


Description

The getdictionarykey( function takes a value and returns the corresponding key name from dictionary collection. If there are multiple objects with this value, it is indeterminate which key will be returned. For example, suppose you created a dictionary and stored it in a variable named mailto.

fileglobal mailto
mailto=initializedictionary("Address","3987 Olive","City","Tustin","State","CA","Zip","92841")

Later, you could use the getdictionarykey( function to retrieve different keys from the dictionary, based on the values:

getdictionarykey(mailto,"3987 Olive") ☞ Address
getdictionarykey(mailto,"Tustin") ☞ City
getdictionarykey(mailto,"CA") ☞ State
getdictionarykey(mailto,"92841") ☞ Zip

Dictionary values are not restricted to text – you can use any type of data that Panorama supports, including numbers, dates, and binary data. This example includes both numbers and a date.

fileglobal InventoryItem
InventoryItem=initializedictionary("SKU",10445,"Description","Widget","Price",12.95,
    "On Hand",687,"Last Order Date",date("12/17/2012"))

Later, you could use the getdictionarykey( function to retrieve different values from the dictionary:

getdictionarykey(InventoryItem,10445) ☞ SKU
getdictionarykey(InventoryItem,"Widget") ☞ Description
getdictionarykey(InventoryItem,12.95) ☞ Price

As these example show, the data type you supply must match the type of data originally stored in the dictionary. If the value was stored as a number, it must be supplied to the getdictionarykey( function as a number. For example, in this case the Price is stored as a number. If you search for it as a text value, there will be no match.

 getdictionarykey(InventoryItem,"12.95") ☞ 

If the getdictionarykey( function doesn’t find a matching value, the empty string ("") is returned. If there are multiple values that match, one of the keys will be returned. However, there is no way to know which key will be returned.


See Also


History

VersionStatusNotes
10.0UpdatedCarried over from Panorama 6.0, but now is available as a function as well as a statement. Since dictionaries can now contain numbers, dates or binary values in addition to text, you must supply the correct data type in the value parameter.