Search code examples
ibm-midrangerpgle

I-Series RPGLE function to test multiple bits in array for a value


I'm trying to determine if there's a more efficient coding technique I can use for an if statement. I have a bit array that can contain 128 bits, either 0 or 1. Currently, my code looks like this:

if bi(64)='1' or bi(66)='1' or bi(67)='1' or bi(68)='1'
or bi(69)='1' or bi(70)='1' or bi(71)='1' or bi(72)='1'
or bi(73)='1' or bi(74)='1' or bi(75)='1' or bi(76)='1'
or bi(77)='1' or bi(78)='1' or bi(79)='1' or bi(80)='1'
or bi(81)='1';                                         

Obviously this doesn't work, but is there a method I could use to simplify this expression like this or something?

if bi(64) or bi(65) or bi(66) or bi(67) = '1'; 

I have actually tried the statement above, but the compiler doesn't like it.


Solution

  • Something like this should work:

    if %scan('1' : bi(64) + bi(65) + bi(66) + bi(67)) > 0;
    

    See the %SCAN function for more information.