Defining Long Variable Names

Q: I am new to definition specifications. What does the ‘…’ notation at the end of a D-spec name represent? For example:

D Qp01_Objtypes_List_T...
D   ypes         DS                              Based(Structuretemplate)
D                                                Qualified
D Number_of_ObjTypes...
D                                          10U 0

A: RPG IV supports definition names up to 4,096 characters long, with some restrictions. In fixed-column specifications, names can be as long as will fit in the entry (usually 14 characters). In D-specs , free-form calculations, and in those C-specs that allow the extended Factor 2, names can be longer.

To declare a long name, use the D-spec, as the following examples show:

D MothersMaidenName...
D                 S             35A
 
D HoursWorked...
D YearToDate      S              5S 0

D TheReadersDigestCondensedVersionOf...
D DatabaseDesignAndProgrammingForDB2_400...
D ByPaulConte     S           4096A

In the first example, MothersMaidenName won’t fit in the allotted 15 columns, so we use an ellipsis (…) to continue the rest of the D-spec to the next line. If the name alone is longer than a line, you can even include ellipses within the name, as in the next example, HoursWorkedYearToDate.

You can use the longer names nearly anywhere you can use a shorter name. The following example uses a longer name in the keyword portion of a D-spec:

D HrsWrkYTD       S                   LIKE(HoursWorkedYearToDate)

or

D HrsWrkYTD       S                   LIKE(HoursWorked...
D                                     YearToDate)

In the program’s calculations, you can use long names wherever they fit, using ellipses if necessary, such as in the following examples:

  If HoursWorkedYearToDate > 2000;
     Eligible401K = *ON;
   Endif;

or

C                   IF        HoursWorkedYearToDate > 2000
C                   EVAL      Password = MothersMaidenName

or

C                   EVAL      Password = MothersMaiden...
C                                        Name

For those fixed-form specifications that still remain, you can still use somewhat longer names, but you’ll have to restrict yourself to names that will fit. There is no alias function that would assign a short name as the equivalent of a long name.