Dictionary part

Dictionary parts contain lists of data that you can access via a key. For example, you can create a message handling facility that uses a library and a dictionary populated with keys and messages read from a database.

A Dictionary part is always available; you do not define it. A variable that is based on a Dictionary part includes a set of keys and their related values. You can add and remove key/value entries at run time. Use the key names in a program just as you would field names in a record. The dictionary variable keeps the entries in the order that you entered them.

The following example shows a dictionary variable declaration:
  myRef Dictionary 
    {
      ID        = 5,
      lastName  = "Twain",
      firstName = "Mark"
    };

When you include entries in the declaration, each key name is an EGL identifier that must be consistent with EGL naming conventions. When you add entries at run time, you have greater flexibility; see "Dynamic types and dynamic access."

Here are some example assignments that add new key/value pairs to the dictionary:
  myRef.age = 30;
  myRef["Credit"] = 700;
If you attempt to assign a key that already exists, you override the existing key/value entry. The following assignment is valid and replaces "Twain" with "Clemens":
  myRef.lastname = "Clemens";
You can also use assignments to retrieve data:
  lastname STRING
  age, credit INT;

  lastname = myRef.lastname; 
  age = myRef["age"];
  credit = myRef.credit;
The value in a key/value entry is ANY type, so you can put different kinds of information into a single dictionary. You can put any of the following values into a dictionary entry:
Adding a variable to a dictionary assigns a copy of the variable. Consider the following Record part:
  Record ExampleRecord
	   x int;
	 end

The next example places an ExampleRecord variable into the dictionary, then changes the value of the original variable:

  testValue int;

  myRecord ExampleRecord;

  // sets a variable value and places
  // a copy of the variable into the dictionary.
  myRecord.x = 4; 
  myRef Dictionary
  {
    theRecord = myRecord
  };
	
  // Places a new value in the original record.
  myRecord.x = 700;

  // Accesses the dictionary's copy of the record, 
  // assigning 4 to testValue.
  testValue = myRef.theRecord.x;
Assigning one dictionary to another replaces the target content with the source content and overrides the properties of the target dictionary (see Dictionary properties). For example, the conditional statement in the following code is true:
  myRef Dictionary { age = 30 };

  newRef Dictionary { age = 50 };
  newRef = myRef;

  // resolves to true
  if (newRef.age == 30)
    ;
  end

Properties that you can specify in the declaration affect how the dictionary is processed; see "Dictionary properties." Dictionary-specific functions provide data and services to your code; see "Dictionary functions."

Compatibility

Table 1. Compatibility considerations for Dictionary parts
Platform Issue
COBOL generation The Dictionary part is not currently available in code generated for COBOL.

Feedback