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 hashmaps 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 hashmaps 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).
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"));