HashMap ʃvalue_typeʅ hashmap_nameʃ(dimension_type1ʃ, ..., dimension_typeNʅ)ʅ ʃdefault(default_value)ʅ;
The
HashMap statement creates a
HashMap with the name
hashmap_name. The HashMap name must be unique and must contain only letters, numbers, or the underscore character. The name must begin with a letter. You can declare HashMap objects globally in
PROC GLOBAL or locally in functions or procedures.
HashMap values can be
numeric or
string. By default a HashMap is numeric, but the type can be modified by specifying the
value_type.
Unlike an
Array, a HashMap's dimensions are not of fixed size because HashMap objects dynamically grow or shrink in size as values are added or removed from the HashMap. A HashMap can have one or more dimensions, and when declaring the HashMap you must specify the type of each dimension. Each
dimension_type can be:
Dimension Type | Key Values |
all | Numeric or string values |
numeric | Numeric values |
string | String values |
If no dimensions are specified, then the HashMap is created with a single dimension of type all.
When assigning a value to a HashMap, all keys will be created as necessary to store the value. However, when retrieving a value, if the keys do not exist, you will get a runtime error and the value
default or a blank string will be returned. If you want to assign a default value for undefined keys, you can specify a
default_value, which must be either a numeric constant or a string literal (based on the value type).
The following variable modifiers apply to HashMap objects:
- persistent: to persist the variable's value from one run of an application to another.
HashMap string simple_hashmap;
simple_hashmap("Kwanzan") = "Cherry Tree";
simple_hashmap(1603) = "Beginning of Edo period";
errmsg("%s", simple_hashmap(1868)); // runtime error (1868 is an undefined key)
HashMap three_dimensional_hashmap(all, numeric, string) default(0);
// proper access:
three_dimensional_hashmap(1, 2, "Z");
three_dimensional_hashmap("A", 2, "Z");
// compile-time errors:
three_dimensional_hashmap("A", "M", "Z"); // the second key must be a number
three_dimensional_hashmap(1, 2, 3); // the third key must be a string
// with a default value defined, accessing this undefined key results in the displaying of 0
errmsg("%d", three_dimensional_hashmap(99, 88, "YY"));