Dictionary attributes

Dictionaries can be defined with attributes, to complete the type description.

Syntax

where attributes-list is:
ATTRIBUTES ( attribute [ = "value" ] [,...] )
  1. attribute is the name of a definition attribute.
  2. value is the value for the definition attribute, it is optional for boolean attributes.

Usage

Dictionaries can be defined with the ATTRIBUTES() clause, to specify meta-data information for the dictionary.

In the next code example, the dictionary type definition gets definition attributes, to specify the corresponding field names for JSON serialization:
IMPORT util
  
TYPE t_items DICTIONARY ATTRIBUTES(json_name="items") OF
     RECORD
         item_num INTEGER ATTRIBUTES(json_name="id"),
         item_desc VARCHAR(50)
     END RECORD

DEFINE stock RECORD
         itemlist t_items
     END RECORD

MAIN

    LET stock.itemlist["cf311"].item_num = 998
    LET stock.itemlist["cf311"].item_desc = "Hand gloves"
    LET stock.itemlist["cx242"].item_num = 999
    LET stock.itemlist["cx242"].item_desc = "Blue hat"

    DISPLAY util.JSON.format(util.JSON.stringify(stock))

END MAIN
Output:
{
    "items": {
        "cf311": {
            "id": 998,
            "item_desc": "Hand gloves"
        },
        "cx242": {
            "id": 999,
            "item_desc": "Blue hat"
        }
    }
}

Dicitionary attributes are part of the attributes specification for variables.