• <Helps for GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • CSPro Statements and Functions
      • Statement Format Symbols
      • Alphabetical List of Functions and Statements
      • List of Reserved Words
      • Deprecated Features
      • Declaration Statements
      • Array Object
      • Audio Object
      • Barcode and QR Codes
      • 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
      • Image Object
      • List Object
      • Map Object
      • Path
      • Pff 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
      • Export Attributes
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Appendix
  • <Helps for CSEntry>
  • <Helps for CSBatch>
  • <Helps for CSTab>
  • <Helps for DataViewer>
  • <Helps for TextView>
  • <Helps for TblView>
  • <Helps for TRSWin>
  • <Helps for CSDeploy>
  • <Helps for CSPack>
  • <Helps for CSFreq>
  • <Helps for CSSort>
  • <Helps for CSExport>
  • <Helps for CSReFmt>
  • <Helps for CSDiff>
  • <Helps for CSConcat>
  • <Helps for TRSSetup>
  • <Helps for ParadataViewer>
  • <Helps for ParadataConcat>
  • <Helps for CSIndex>
  • <Helps for Excel2CSPro>
  • <Helps for 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 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 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).
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