Finding Key Values in a Hash Object

The FIND Method

The FIND method searches the hash object for the current key values. The method returns a code of 0 if the key value is found, or matched. If the value is not found, then a nonzero value is returned. If the value is found, the FIND method copies the data component values to the PDV.
Syntax, FIND method:
object-name.FIND(<KEY: value-1, ... KEY: value-n>)
object-name
specifies the name of the component object.
value
specifies the key value whose type must match the corresponding key variable that is specified in a DEFINEKEY method call.
The number of “KEY:value” pairs depends on the number of key variables that you define by using the DEFINEKEY method.

Retrieving Matching Data

The following example retrieves the value of ContinentName from the hash object, ContName, based on the value of ContinentID. The KEY argument is not needed if the PDV column has the same name as the key component.
rc=ContName.find();
Figure 12.2 Retrieving Matching Data - Find Matching Value
Retrieving Matching Data - Find Matching Value
rc=ContName.find();
The FIND method returns Austrialia/Pacific as the continent name. A return value of 0 indicates success. If the value is not found, then the RC value is equal to a nonzero value. If the method does not find a match, no data is returned to the PDV.
Figure 12.3 Retrieving Matching Data - Find Matching Value
Retrieving Matching Data - Find Matching Value
The KEY argument is required if the PDV column has a different name from the key component.
rc=ContName.find(key:ID)
You can also use multiple KEY arguments. If your hash object has multiple key components, then the key arguments must be specified in the order in which the key components are defined in the DEFINEKEY method. In this example, the value for the CITY key component must be specified first, followed by values for the MONTH key component.
Monthly.definekey('City','Month');
Monthly.find(key:CityName,key:MonthName);
Last updated: October 16, 2019
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.19.130