RECORD-ENDRECORD

Define a data record

WSupported on Windows
USupported on Unix
VSupported on OpenVMS
NSupported in Synergy .NET
[access] [rec_mod] RECORD [name] [,X]
  member_def
  .
  .
  .
[ENDRECORD]

access

(optional) For a class record only, one of the following access modifiers:

PUBLIC

Access is not restricted. This is the most accessible option.

PROTECTED

Access is limited to the containing class or types derived from the containing class.

PRIVATE

Access is limited to the containing type. This is the least accessible option. (default)

INTERNAL

Access is limited to the current assembly. (Synergy .NET only)

PROTECTED INTERNAL

Access is limited to the current assembly and types derived from the containing class. (Synergy .NET only)

rec_mod

(optional) One of the following record modifiers:

LOCAL

For a routine record only, the contents of the record persist for as long as the routine is activated and has not been removed from memory via segment reclamation or use of the -qrefresh compiler option (except on .NET and OpenVMS, where it is the same as STATIC).

STACK

For a routine record only, the contents of the record are unique for every activation of the routine.

CONST

For a class record only, field values are not changed once they are initialized. CONST implies STATIC.

READONLY

For a class record only, field values can only be set during declaration or in the constructor of the class. (Can be used with STATIC.)

STATIC

For both routine and class records, the contents of the record persist throughout the life of the program. (Can be used with READONLY.)

name

(optional) The name of the entire record area to define.

,X

(optional) Indicates that you’re defining an overlay for the most recent nonoverlay record or common.

member_def

Either the definition of a single field in the record or a group declaration. Each field definition has the syntax described in Defining a field. Each group declaration has the syntax described in GROUP-ENDGROUP. You can specify as many member definitions as you want.

Discussion

The RECORD statement defines a data structure and its component fields. A record can be declared within a class or within a routine. The record is either global or local, depending on whether or not the RECORD statement is part of a GLOBAL-ENDGLOBAL statement block.

You can specify an access modifier and the CONST or READONLY modifier only on a class record. These modifiers apply to all groups and fields in the record unless they are overridden at the field level. CONST and READONLY are mutually exclusive.

The LOCAL and STACK modifiers can be specified only on a routine record, not a class record. If you specify the LOCAL modifier, the record’s data is initialized on the associated routine’s initial activation, and any changes are guaranteed to remain in effect while the routine is activated at one or more levels. If the routine is not activated at any level, it can be removed from memory in some environments. If the routine is removed, the routine’s next activation is exactly equivalent to its initial activation. LOCAL is the default for non-re-entrant routines.

If you specify the STATIC modifier in a subroutine or function, the contents of the static record on entry are the same as they were when the routine was last exited. For a class record, fields are shared by all instances of the class. The record’s data is initialized when the program is started, and any changes are guaranteed to persist until the entire program is exited. If you specify the STATIC modifier in a REENTRANT subroutine or function, the data referenced is the same on every activation level. You don’t need to use the STATIC modifier in your main routine, because data defined in the main routine is never reinitialized; all records in the main routine are implicitly static.

Storage qualifiers (LOCAL, STACK, and STATIC) in the RECORD statement take precedence over those specified in the SUBROUTINE or FUNCTION statements, which in turn take precedence over equivalent compiler command line options (-qlocal, -qstack, and -qstatic). Since methods are implicitly REENTRANT (which gives stack records), -qstatic/-qlocal will not change the storage of unspecified records to static/local. If you want a static or local record, you must explicitly declare the record as STATIC or LOCAL or specify the data storage qualifier on the method as STATIC or LOCAL.

In Synergy .NET,

In traditional Synergy,

Access or record modifiers on an unnamed class record can be overridden by a modifier on one of its fields. If a field modifier is specified, it takes precedence over the record modifier. Widening accessibility is not allowed; if a record is public, a field can be specified as private, but not vice-versa.

If you don’t specify name, the record is unnamed. If you specify name, the record is accessed as data type alpha. The record name must be unique within the class or routine in which it is declared. If name is specified on a class record, it represents an instance variable of that record type within that class and can be used to access fields in that record within all instance methods of the class. If name is specified on a routine record, it represents a local variable of that record type within that routine and can be used to access fields in that record within that routine. For example,

method mymethod, void
record myrecord
    f1, i4
proc
     myrecord.f1 = 4
     mreturn
end

See Overlaying data for a list of rules that apply to overlay records, which are indicated by “,X”.

At least one field or group definition must be present after the RECORD statement.

If you declare a named group within a class record, the group and its members inherit the accessibility of the class record. Accessibility cannot be widened.

The ENDRECORD statement is optional. If you don’t specify ENDRECORD, the record is automatically terminated at the start of the next syntactical component.

Examples

The following example defines a global data section named gbl with 11 characters and a local area of 35 characters. The global data section consists of one global record named g1 and one unnamed alternate layout. The local area consists of one local record named rec1 (21 characters) and one unnamed record (14 characters). Record rec1 has one named alternate layout, or overlay, named r1 and one unnamed alternate layout. The unnamed record has an alternate layout named ovr.

global data section gbl         ,INIT
    record g1
      g1a       ,d5,    164
      g1b       ,3d2,   1, 27, 3
    record ,x
      govr1     ,d2
      govr2     ,a1
endglobal
record rec1
    alpha       ,a13,   "Initial value"
    beta        ,a2
    gamma       ,d6,    975126
record ,x
    r1fld1      ,a3
    r1fld2      ,a7
record r1 ,x
    r2fld1      ,a5
    r2fld2      ,a1
record
    xx1         ,a7
    xx2         ,d7,    11765
record ovr ,x
    xx10vr      ,a3
    xx1end      ,d4

The following example defines a class record.

namespace ns1
    class c1
        record r1
            f1          ,i4
            f2          ,i4
        endrecord
        public record r2
            f1             ,i4     ;This field inherits public accessibility
            private f2   ,i4       ;This field is explicitly private
        endrecord
    endclass
endnamespace