ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Boolean in RPG ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Boolean in RPG ?

    Hello,

    I would like to understand, how the boolean works?

    For example, I have two variables: (number1 and number2)

    If number1 is smaller than number2, it's TRUE else it's FALSE.

    My error message is "RNF7416: The types of the right and left hand side do not match in the EVAL operation. "

    My problems are in the line Flag = 1; and Flag = 0;


    Code:
         H
         D Number1         S              3S 0
         D Number2         S              3S 0
         D Flag            S              1N
    
          *
          /Free
    
            dsply 'Enter your number1 please : ' '' Number1;
            dsply 'Enter your number2 please : ' '' Number2;
    
            If (Number1 < Number2);
              Flag = 1;
              dsply ('The value is true => ' + %Char(Flag));
    
            Else;
              Flag = 0;
              dsply ('The value is false => ' + %Char(Flag));
    
            ENDIF;
    
    
            *inlr = *on;
    
          /End-free

    I thank you for your help.

  • #2
    Booleans are character fields.

    Flag = '1';

    Comment


    • #3
      Instead of '1' you also can use *ON (or for '0' *OFF)
      Since booleans are character there is no need to use the %CHAR() built-in-function in the display statement.

      Code:
      If (Number1 < Number2);
         Flag = *On;
         Dsply ('The value is true => ' + Flag);
      EndIf;
      Or even simpler;
      Code:
      Flag = (Number1 < Number2);
      Birgitta

      Comment


      • #4
        Not sure if you know the all-free declaration of booleans (known as indicators):

        PHP Code:
        dcl-s myFlag ind inz

        Comment


        • #5
          Hello,

          Thank you for your explanations, it works perfectly.

          Comment


          • #6
            Although you may not realise it, *INLR is also an indicator, or boolean if you prefer, that is built into RPG so you are setting it to true on the last line - *INLR = *ON. I tend to use *ON/*OFF for code consistency.

            Comment


            • #7
              Although you may not realise it, *INLR is also an indicator, or boolean if you prefer, that is built into RPG so you are setting it to true on the last line - *INLR = *ON. I tend to use *ON/*OFF for code consistency.

              Comment


              • #8
                Although you may not realise it, *INLR is also an indicator, or boolean if you prefer, that is built into RPG so you are setting it to true on the last line - *INLR = *ON. I tend to use *ON/*OFF for code consistency.

                Comment

                Working...
                X