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 Future consideration
Workspace IBM i
Categories Languages - RPG
Created by Guest
Created on Oct 23, 2017

RPG - Conditional (Ternary) Operator (?:) in EVAL operation

I'd like to be able to use conditional assignment (?:) in EVAL and EVALR operation in RPG.
C, C#, java and many other languages have a conditional (aka ternary) operator. This allows developers to make very terse choices between two values based on the truth of a condition, which makes expressions, including assignments, very concise.
Example :
result = conditional_operator ? what_if_true : what_it_false;

result =sql_null_ind1=-1 ? 'n/a' : address_1;


Use Case:

It would be easier to check and handle specific condition in one line instead of using common if-else clause; Developers would be more efficient and saving a lot of time and lines of code.


Idea priority Medium
  • Guest
    Reply
    |
    Jan 24, 2023

    dcl-s Apples ind;

    dcl-s Fruit varchar(10) INZ('PEACHES');

    apples = (fruit = 'APPLES'); // Works today

    apples = (fruit <> 'APPLES' and fruit <> 'PICKLES'); // Works today

    // Needed:

    fruit = %bif( <conditional-statement> : true-result : false-result);


    The only discussion is what the name of the %BIF should be. Clearly %IF is not a good choice, but for development purposes can be referred to as %IF. I'd prefer the following however:


    fruit = %case( apples = *ON or fruit <> 'PICKELS' : 'APPLES' : 'ORANGES');


    Why %CASE()? because it causes the user to understand what's going on, where as %IF makes my brain hurt.


  • Guest
    Reply
    |
    Oct 8, 2020

    I have an Iffa(condition: true value: false value) function in my toolbox which does this, but one advantage a built-in ternary operator could have over a user defined sub-procedure is that it could handle short circuit processing. That is when I call my procedure, all parameters are evaluated first. So if I call Iffa() with procedures that supply the true and false values, both are evaluated when only one is ever needed. I have come across a situation where this causes problems. Specifically if one or both procedures in the parameters depends on the truthiness of the condition, Iffa() will cause unexpected behavior. A ternary operator that can short circuit the evaluation of the operands alleviates this issue.

  • Guest
    Reply
    |
    Sep 7, 2020

    I have to agree with comments that suggest this construct is not needed and would cause confusion. Yes, it would be "nice" and C-like. But do I want a cryptic, C-like business language? I would rather the development funds be directed to things with a more pressing priority.

  • Guest
    Reply
    |
    Apr 17, 2020

    IBM will use this request as input to planning but no commitment is made or implied. This request will be updated in the future if IBM implements it. IBM will use votes and comments from others in the community to help prioritize this request.

  • Guest
    Reply
    |
    May 24, 2019

    RPG IV already is doing this partially.

    Eval myIndyVariable = ( X = Y);

    Sets myIndyVariable to 1 if true, otherwise 0.
    Adding a suffix to this logic whereby ? : were used would be fine with me.
    Creating something completely different in my view adds to the complexity of learning the language vs adapting to it from other C-like languages. So I would not prefer %IF/%MONITOR, as not only is it different it will confuse “legacy” programs who move to free format and see both IF and %IF in the same section of code. Argh! What a uncomfortable feeling that would be.

  • Guest
    Reply
    |
    Nov 5, 2018

    The BIF format sounds logical as it can be used in expressions which is more valuable.

    But if you need a name... please use %IIF as in most other languages.

  • Guest
    Reply
    |
    Mar 27, 2018

    The CAAC has reviewed this requirement and recommends that IBM view this as a medium priority requirement that should be addressed. People coming into RPG from other modern languages will expect this function to be there.

    Background: The COMMON Americas Advisory Council (CAAC) members have a broad range of experience in working with small and medium-sized IBM i customers. CAAC has a key role in working with IBM i development to help assess the value and impact of individual RFEs on the broader IBM i community, and has therefore reviewed your RFE.

    For more information about CAAC, see www.common.org/caac

    For more details about CAAC's role with RFEs, see http://www.ibmsystemsmag.com/Blogs/i-Can/May-2017/COMMON-Americas-Advisory-Council-%28CAAC%29-and-RFEs/

    Nancy Uthke-Schmucki - CAAC Program Manager

  • Guest
    Reply
    |
    Mar 22, 2018

    "Although it's true that %IF wouldn't work for the simple "a = 5 if b > c" case, since a built-in function has to return a value."

    Actually, %IF would work in that case by specifying the result field for the false value: "a = %IF(b > c : 5 : a)"

  • Guest
    Reply
    |
    Jan 29, 2018

    The CEAC has reviewed this requirement and recommends that IBM view this as a “nice to have” low priority feature.

    Although the '?' would be preferable, the %IF would be acceptable.

    Background: The COMMON Europe Advisory Council (CEAC) members have a broad range of experience in working with small and medium-sized IBM i customers. CEAC has a key role in working with IBM i development to help assess the value and impact of individual RFEs on the broader IBM i community, and has therefore reviewed your RFE.

    For more information about CEAC, see http://www.comeur.org/i4a/pages/index.cfm?pageid=3285

    Dawn May - CEAC Program Manager

  • Guest
    Reply
    |
    Jan 29, 2018

    I like the %IF() construct. I regularly wish for this type of function while coding. Lots of languages have it, and not all of them use the C style ternary operator.

  • Guest
    Reply
    |
    Jan 25, 2018

    @NielsLiisberg, the "a = 5 if b > c" syntax is nice, but it would likely be much more difficult to implement in the compiler than %IF would be.

    Although it's true that %IF wouldn't work for the simple "a = 5 if b > c" case, since a built-in function has to return a value.

    But %IF could be used in expressions, while it seems like "a = 5 if b > c" could only be used for assignments.
    pay = salary + %if(rating > 3 : bonus : 0);

  • Guest
    Reply
    |
    Jan 25, 2018

    Great idea. However i think a coffeescript like notation fits the RPG syntax better than the java/C/C# and will be easier to implement for IBM..

    a = 5 if b > c;
    a = 5 if b > c else 10;

  • Guest
    Reply
    |
    Jan 18, 2018

    The reasons given by some of the people who are not in favor of this enhancement are exaggerated in my opinion. Generally speaking, less code is easier to comprehend. This example code:

    If Field1 = 'somevalue';
    Result = 'value1';
    Else;
    Result = 'value2';
    End;

    can be changed to this:

    Result = %If(Field1 = 'somevalue' : 'value1' : 'value2');

    If you feel that's too hard to understand, then you always have the option not to use the function.

  • Guest
    Reply
    |
    Dec 12, 2017

    Code is much easier to read and understand without these constructs. Yes, you can try to write the complete program in one line of code using e.g. C++, but for the next one to take any maintenance on that code it's really no fun.

  • Guest
    Reply
    |
    Nov 2, 2017

    I think it is not needed. It will make even harder for newcomers to learn RPG. In C it is also not needed. It just splits the language to do the same thing in so many different ways, it hurts standardization.

  • Guest
    Reply
    |
    Oct 26, 2017

    IBM has received the requirement and is evaluating it. IBM will provide a response after evaluation is complete.

    If IBM provides this feature, it would most likely be in the form of a %IF built-in function rather than using the ? : syntax.

    %IF(condition : true value : false value)

    A related %MONITOR built-in function would likely be provided if %IF was provided.

    %MONITOR(expression : error value)

    Since these would be ordinary built-in functions, no special debugger support would be required.

  • Guest
    Reply
    |
    Oct 24, 2017

    I think that the usual IF after the EVAL is more understandable. Also this way of coding should collide with the usual debugging behavior of one instruction per line. In this case you have an eval, an evaluation and "another action" in the same line so the debugger should be also changed to manage this kind of sentence.

3 MERGED

Ternary opertor BIF - e.g. (%IIF Inline If)

Merged
A ternary operator/BIF improves readability, particularly when building strings or setting parameters on calls to programs or procedures as it reduces the number of if .. endif blocks in code and removes the need for a workfield to hold a paramete...
about 1 year ago in IBM i / Languages - RPG 2 Future consideration
2 MERGED

Short hand IF-Else statements

Merged
Coding is all about if statements and most of the times we code a simple "If this then that, else this " logic. It would be nice with a short hand format to this to ease the coding experience somewhat. The goal would be to have a quick, short (one...
about 1 year ago in IBM i / Languages - RPG 1 Future consideration