• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
      • Statement Format Symbols
      • Alphabetical List of Functions and Statements
      • List of Reserved Words
      • Deprecated Features
      • Declaration Statements
      • Numeric Values
      • String Values
      • Symbol Functions
      • Item Functions
      • Array Object
      • Audio Object
      • Barcode and QR Codes
      • Case Object
      • Document Object
      • File Object
      • Freq Object
      • Geometry Object
      • HashMap Object
        • HashMap Statement
        • HashMap.getKeys Function
        • HashMap.contains Function
        • HashMap.length Function
        • HashMap.remove Function
        • HashMap.clear Function
        • JSON Representation
        • JavaScript Representation
      • Image Object
      • List Object
      • Map Object
      • Path
      • Pff Object
      • StringWriter Object
      • SystemApp Object
      • ValueSet Object
      • Program Control Statements
      • Assignment Statements
      • Data Entry Statements and Functions
      • Batch Edit Statements
      • Numeric Functions
      • String Functions
      • Multiple Occurrence Functions
      • General Functions
      • Date and Time Functions
      • External File Functions
      • Synchronization Functions
    • Text Templates
    • Templated Reporting System
    • HTML, Markdown, and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataManager>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

HashMap Statement

Format
HashMap ʃvalue_typeʅ hashmap_nameʃ(dimension_type1ʃ, ..., dimension_typeNʅ)ʅ ʃdefault(default_value)ʅ;
Description
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 TypeKey Values
allNumeric or string values
numericNumeric values
stringString 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).
Variable Modifiers
The following variable modifiers apply to HashMap objects:
  • persistent: to persist the variable's value from one run of an application to another.
Example 1
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)
Example 2
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"));
See also: HashMap Object, Array Object, List Object