IBM Support

RPG Cafe: Fall 2025: Define a variable like an enumeration

News


Abstract

Information about the PTFs to provide the ILE RPG enhancement to allow a variable to be defined like an enumeration

Content

You are in: RPG Cafe Fall 2025: Define a variable like an enumeration

Short URL: https://ibm.biz/rpgcafe_fall_2025_fld_like_enum

Fall 2025: Define a variable like an enumeration

Details

  • An enumeration can be defined with a data type.
              dcl-enum colorCodes int(3) qualified;
                 blue 1;
                 green 2;
                 yellow 3;
               end-enum;
    
  • Use the DFT keyword to identify one of the constants as the default value for the data type. This is the CLEAR value and the default initialization value.
              dcl-enum colorCodes int(3) qualified;
                 blue 1;
                 green 2;
                 yellow 3;
                 no_color -1 dft;
               end-enum;
    
  • A variable, prototyped parameter, or return value can be defined like the typed enumeration. Field color is initialized to the default colorCodes.no_color (-1).
              dcl-s color like(colorCodes);
              dcl-s my_favourite_color like(colorCodes) inz(colorCodes.blue);
              dcl-s other_num int(3);
    
              dcl-pr my_proc;
                 dcl-pi *n;
                    p1 like(colorCodes) const;
                    p2 like(colorCodes) const options(*exact);
                 end-pi;
              end-pr;
    
    
  • The values in the enumeration are the only valid values for the variable, parameter, or RETURN operation.
  • The compiler places some restrictions on the values you can use with a variable, parameter, or return value defined like an enumeration. For example, you can't assign a literal value even if it is one of the values in the enumeration. Instead, you use the named constants from the enumeration. You can also use another variable defined like the enumeration.
  • See https://www.ibm.com/docs/en/ssw_ibm_i_76/rzasd/typedenums.htm for complete information about the restrictions.
  •           color = 3;                    // Error, even though this is the same as colorCodes.yellow
              color = colorCodes.yellow;    // Ok, this is a constant in the enumeration
              color = other_num;            // Error, even though other_num has the same data type, int(3)
              color = my_favourite_color;   // Ok, my_favourite_color is also defined like the enum
              my_proc (colorCodes.red       // Ok, the parameter is a constant in the enumeration
                    :  my_favourite_color); // Ok, the parameter is defined like the enumeration
    

.                                                            .
.                                                            .

PTFs for 7.5, and 7.6

7.5:

  • ILE RPG compiler: 5770WDS (PTF number to be updated later)

7.6:

  • ILE RPG compiler: 5770WDS (PTF number to be updated later)
  • ILE RPG compiler, TGTRLS(V7R5M0): 5770WDS (PTF number to be updated later)

SQL precompiler support

The SQL precompiler supports defining variables like typed enumerations. See Db2 for IBM i Technology Updates

RDi support

A later update for RDi will support this enhancement.

Documentation

The 7.5, and 7.6 ILE RPG Reference and ILE RPG Programmer's Guide are updated with full information about this enhancement. Start at the "What's new since 7.5", or "What's new since 7.6" section in the Reference.

[{"Type":"MASTER","Line of Business":{"code":"LOB73","label":"Power TPS"},"Business Unit":{"code":"BU048","label":"IBM Software"},"Product":{"code":"SS69QP","label":"Rational Development Studio for i"},"ARM Category":[],"Platform":[{"code":"PF012","label":"IBM i"}],"Version":"and future releases;7.5.0;7.6.0"}]

Document Information

Modified date:
07 October 2025

UID

ibm17246937