News
Abstract
Information about the PTFs to provide the enhancement for ILE RPG to support enumerations.
Content
You are in: RPG Cafe Fall 2023: Enumerations
Short URL: https://ibm.biz/rpgcafe_fall_2023_enums
Fall 2023: Enumerations
Details
An enumeration is a list of named constants. It can be qualified or unqualified.
- The enumeration constants can be used anywhere that a named constant can be used.
- The enumeration names can be used as an array in most calculation operations where an array can be used.
Defining an enumeration
An enumeration starts with DCL-ENUM and ends with END-ENUM. It can be defined only in free-format, although the constants can be defined in free format or fixed format.
The enumeration constants are defined as named constants, but the DCL-C operation code is optional unless the name is an operation code allowed in free-form calculations. In this example, one constant is defined with the name DSPLY so it must begin with DCL-C.
dcl-enum colorCodes qualified; blue 1; green 2; yellow 3; end-enum; dcl-enum boolean; true '1'; false '0'; end-enum; dcl-enum nameSize qualified; system 10; path 5000; dcl-c dsply 52; // Name "DSPLY" needs DCL-C end-enum; dcl-s ifsFile varchar(nameSize.path); // Use the enum value in a definition dcl-s color int(10); dcl-s isValid ind; color = colorCodes.blue; // Use the qualified enum value isValid = true; // Use the unqualified enum value
Using an enumeration as an array
dcl-enum colorCodes qualified; blue 'b'; green 'gr'; yellow 'y'; end-enum; dcl-s array varchar(5) dim(3); dcl-s color varchar(10); for-each color in colorCodes; // Use an enum with FOR-EACH dsply color; // Displays "b", "gr", "y" endfor; if color in colorCodes; // Use an enum with the IN operator dsply 'valid'; endif; array = colorCodes; // Assign the values to an array // array(1) = "b" // array(2) = "gr" // array(3) = "y"
. .
. .
PTFs for 7.4, and 7.5
7.4:
- ILE RPG compiler: 5770WDS SI84886
7.5:
- ILE RPG compiler: 5770WDS SI85009
- ILE RPG compiler, TGTRLS(V7R4M0): 5770WDS SI85043
The PTFs are also available with Db2 for i Fix Packs. See Db2 for IBM i 2023 PTF Group Schedule.
SQL precompiler support
The SQL precompiler supports enumeration definitions.
RDi support
A later update for RDi will support this enhancement.
Documentation
The 7.4, and 7.5 ILE RPG Reference and ILE RPG Programmer's Guide are updated with full information about these enhancements. Start at the "What's new since 7.4", or "What's new since 7.5" section in the Reference.
- What's new since 7.4? https://www.ibm.com/docs/en/ssw_ibm_i_74/rzasl/rpgrelv7r4post.htm
- What's new since 7.5? https://www.ibm.com/docs/en/ssw_ibm_i_75/rzasl/rpgrelv7r5post.htm
Was this topic helpful?
Document Information
Modified date:
02 November 2023
UID
ibm17047175