2

I did find old posts on forums about this question. But as they were old, I was wondering if it changed.

I know that, back maybe in 2004, RPG did not have ternary operator. Having work a bit in C# and Java, I did use them and I like them. I was wondering if RPGLE eventually included them, somehow.

In C#, a ternary operation looks like this :

myvar = var1 > var2 ? var1 : var2;

So if var1 is greater than var2, myvar will get var1. This was a basic example.

So... do you guys know if there's a ternary operator in RPGLE and if there is, what's its syntax?

Arnaud Mongrain
  • 301
  • 1
  • 2
  • 19

3 Answers3

5

No, RPGLE does not have ternary-operators.

http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_72/rzasd/expropt.htm

Charles
  • 21,637
  • 1
  • 20
  • 44
2

ran across this function that emulates ternaries in RPGLE. also has some CLLE options listed.

https://www.itjungle.com/2005/11/09/fhg110905-story01/

D iif             pr           256a   varying                  
D  Condition                      n           value            
D  TrueValue                   256a   varying value            
D  FalseValue                  256a   varying value 
---------------------------------------------------
P iif             b                                    
D                 pi           256a   varying          
D  Condition                      n           value    
D  TrueValue                   256a   varying value    
D  FalseValue                  256a   varying value    
 /free                                                 
     if Condition;                                     
        return TrueValue;                              
     else;                                             
        return FalseValue;
endif;        
 /end-free         
P                 e
Kpgmr72
  • 21
  • 3
1

No but you can use similar for setting an indicator (boolean) to true or false. I do it all the time. If below numberOne variable is defined as an integer with initial value of 1 and numberTwo with initial value of 2.

*in99 = numberOne < numberTwo

99 = true because above statement tests true, else 99 would equal false. This syntax replaces below

if numberOne < numberTwo
  *in99 = *on
else
  *in99 = *off
endif
AdamVanBuskirk
  • 509
  • 4
  • 10