Record attributes

Records 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

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

In the next code example, the t_cust record type gets definition attributes to specify the corresponding field names for JSON serialization:
IMPORT util
  
TYPE t_cust RECORD ATTRIBUTES(json_name="customer")
         cust_id INTEGER ATTRIBUTES(json_name="id"),
         cust_name VARCHAR(50)
     END RECORD

TYPE t_custinfo RECORD
         cust t_cust
     END RECORD

MAIN
    DEFINE ci t_custinfo

    LET ci.cust.cust_id = 998
    LET ci.cust.cust_name = "Scott Finley"

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

END MAIN
Output:
{
    "customer": {
        "id": 998,
        "cust_name": "Scott Finley"
    }
}

Record attributes are part of the attributes specification for variables.

Note:

This feature is especially used when defining records for XML-based Web Services. For more details about XML attributes, see Attributes to customize XML serialization.