Skip to Main Content
IBM Power Ideas Portal


This portal is to open public enhancement requests against IBM Power Systems products, including IBM i. To view all of your ideas submitted to IBM, create and manage groups of Ideas, or create an idea explicitly set to be either visible by all (public) or visible only to you and IBM (private), use the IBM Unified Ideas Portal (https://ideas.ibm.com).


Shape the future of IBM!

We invite you to shape the future of IBM, including product roadmaps, by submitting ideas that matter to you the most. Here's how it works:

Search existing ideas

Start by searching and reviewing ideas and requests to enhance a product or service. Take a look at ideas others have posted, and add a comment, vote, or subscribe to updates on them if they matter to you. If you can't find what you are looking for,

Post your ideas
  1. Post an idea.

  2. Get feedback from the IBM team and other customers to refine your idea.

  3. Follow the idea through the IBM Ideas process.


Specific links you will want to bookmark for future use

Welcome to the IBM Ideas Portal (https://www.ibm.com/ideas) - Use this site to find out additional information and details about the IBM Ideas process and statuses.

IBM Unified Ideas Portal (https://ideas.ibm.com) - Use this site to view all of your ideas, create new ideas for any IBM product, or search for ideas across all of IBM.

ideasibm@us.ibm.com - Use this email to suggest enhancements to the Ideas process or request help from IBM for submitting your Ideas.

Status Not under consideration
Workspace IBM i
Categories Languages - RPG
Created by Guest
Created on Aug 25, 2023

ENUM construct an function

ENUM


Similarly to java and other languages an enum construct may be useful to rpg programmer.

It involves declaring key-value pairs and an instruction to find the value corresponding to the key provided


e.g.:

declare the enumeration name (enumerationName1) and its key availables (1, 2, 3, 4, 5)

each key has its own corresponding value; you must use the %list construct to declare lists.


for key

  • 1 --> red

  • 2 --> blue

  • 3 --> yellow and so on.


sample1

-------

dcl-enum enumerationName1;

dcl-key %list(1: 2: 3: 4: 5);

dcl-val %list('red' : 'blue' : 'yellow' : 'green': 'orange');

end-enum;

------



or (in actual rpg) deine keys and values:

dcl-s keys int dim(5);

dcl-s colors varchar(20) dim(5);


colors = %list('red' : 'blue' : 'yellow' : 'green': 'orange');

keys = %list(1: 2: 3: 4: 5)


or

colors = %list(var1 : var2 : var3 : var4: var5);

keys = %list(1: 2: 3: 4: 5)



sample2

----

dcl-enum enumerationName1;

dcl-key keys;

dcl-val colors;

end-enum;

----


the function to find the value corresponding to a key could therefore be %EnumValue


so


r = %EnumValue(enumerationName1: %EnumKey(1));

or more simply

r = %EnumValue(enumerationName1: 1);

where 1 is the key argument





Idea priority Low
  • Guest
    Reply
    |
    Oct 19, 2023
    IBM does not intend to provide a solution to this Idea at this time, so it is being closed.

    The concept of "enumeration" is already planned for RPG, but it is very different from what is described in this Idea. It is more similar to the concept of "enumeration" in other languages such as C, being simply a named collection of constants. See https://www.ibm.com/support/pages/node/7047175 for information about the future support for enumerations in RPG.

    However, part of this Idea would be useful for RPG enumerations. Please open another Idea to request that RPG add built-in functions to return the name or value of an enumeration constant. For example, if an enumeration constants was en1.blue with value 2, a new built-in function %enumname(en1 : 2) would return 'blue', and %enumvalue(en1 : 'blue') would return 2.

    To achieve the aspect of this Idea where the names and keys can be variables, this concept is already available in RPG by using %LOOKUP with a data structure array.

    dcl-ds colorKeys qualified dim(2);
    color varchar(10);
    key int(10);
    end-ds;
    dcl-s p int(10);

    colorKeys(1).color = 'red';
    colorKeys(1).key = 1;
    colorKeys(2).color = 'blue';
    colorKeys(2).key = 2;

    p = %lookup('blue' : colorKeys(*).color);
    dsply colorKeys(p).key;

    p = %lookup(2 : colorKeys(*).key);
    dsply colorKeys(p).color;

    - IBM Power Systems Development