Record definition attributes

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

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 attributes to define 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_group RECORD
         cust1 t_cust,
         cust2 t_cust
     END RECORD

MAIN
    DEFINE g t_group

    LET g.cust1.cust_id = 998
    LET g.cust1.cust_name = "Scott Finley"
    LET g.cust2.cust_id = 999
    LET g.cust2.cust_name = "Mike Fergusson"

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

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

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.