• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
      • Introduction to CSPro Language
      • Data Requirements
      • CSPro Program Structure
      • Programming Standards
      • Code Folding
      • Debugging CSPro Applications
      • Declaration Section
        • Compiler Mode
        • Variables
        • Alias Statement
        • User-Defined Functions
        • Array Object
        • Audio Object
        • Case Object
        • Document Object
        • File Object
        • Freq Object
        • Geometry Object
        • HashMap Object
        • Image Object
        • List Object
        • Map Object
        • Pff Object
        • SystemApp Object
        • ValueSet Object
      • Procedural Sections
      • Logic
      • Language Elements
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

HashMap Object

In logic, a HashMap is similar to an Array but has dimensions that can be either non-consecutive numbers or strings. A HashMap is an associative array that can be used to store numbers or strings and can dynamically grow or shrink in size.
Functionality
A HashMap is a CSPro logic object and the following functions can be called via dot notation:
FunctionDescription
clearRemoves all values from the HashMap.
containsReturns whether a specified key exists.
getKeysFills a List with the HashMap's keys.
lengthReturns the number of keys.
removeRemoves a key.
 
getLabelReturns the symbol's label.
getNameReturns the symbol's name.
getJsonReturns the symbol's metadata and value represented in JSON.
getValueJsonReturns the symbol's value represented in JSON.
updateValueFromJsonModifies the symbol based on a JSON representation of the value.
Assignments
HashMap objects can be assigned to other HashMap objects, which will replace the initial HashMap with the values of the assigned HashMap:
hashmap_name = another_hashmap_name;
When assigning a HashMap to another HashMap, both must have the same value types, and the dimension types must be compatible.
Individual elements of HashMap objects can be retrieved or set by using an index to specify the dimension keys:
hashmap_name(key_value1ʃ, key_value2, ...ʅ) = value_to_set_or_modify;

value_to_retrieve = hashmap_name(key_value1ʃ, key_value2, ...ʅ);
When a HashMap is used as an argument to a user-defined function, it is passed by reference.
Example
PROC GLOBAL

HashMap invalidValuesByPerson default(0);

PROC CENSUS_LEVEL

   
List string person_list;

    invalidValuesByPerson.
getKeys(person_list);

   
do numeric counter = 1 while counter <= person_list.length()
       
errmsg("%s had %d invalid values", strip(person_list(counter)),
                                           invalidValuesByPerson(person_list(counter)));
   
enddo;

    invalidValuesByPerson.
clear();

PROC SEX

   
if not invalueset(SEX) then
       
inc(invalidValuesByPerson(PERSON_NAME));
   
endif;

PROC AGE

   
if not invalueset(AGE) then
       
inc(invalidValuesByPerson(PERSON_NAME));
   
endif;
See also: Array Object, List Object