• <Helps for 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
      • Debugging CSPro Applications
      • Declaration Section
        • Compiler Mode
        • Variables
        • Alias Statement
        • Ensure Statement
        • User-Defined Functions
        • Array Object
        • Audio Object
        • File Object
        • Freq Object
        • HashMap Object
        • List Object
        • Map Object
        • Pff Object
        • SystemApp Object
        • ValueSet Object
      • Procedural Sections
      • Logic
      • Language Elements
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • CSPro Statements and Functions
    • Templated Reporting System
    • 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 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.
Hashmaps can be assigned to other hashmaps, 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 hashmaps 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, ...』);
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