ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Free Format Rpgle - Field Declaration - Procedure Prototype

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

  • Free Format Rpgle - Field Declaration - Procedure Prototype

    I am new to free form rpgle,

    I am have written a new program in full free-format rpgle. Program has three input parameters - Field1(Integer(4)) , Field2(Char4), Field3(Integer(7). I understand, that in free form, we cannot declare integer with length except 3, 5 10 etc.,

    I cannot change my calling program which is in fixed form rpgle. I have to call the new program with integer variable of 4 length. How should i defined the procedure prototype?






  • #2
    When you say "integer(4)" and "integer(7)", do you mean they are coded as 4B and 7B in fixed-form? If so, then the free-form version of those are BINDEC(4) and BINDEC(7).

    RPG's "B" type isn't a true integer; it's actually a decimal type that is _stored_ in binary form.

    Comment


    • #3
      Example Script,

      PGM 1

      C Call 'PGM2'
      C Parm Field1 4 0
      C Parm Field2 4
      C Parm Field3 7 0

      PGM2

      dcl-pr PGM2 extpgm('PGM2');
      Field1 zoned(4) const;
      Field2 Char(4);
      Field3 zoned(7) const;
      end-pr;

      dcl-pi PGM2
      Field1 zoned(4) const;
      Field2 Char(4);
      Field3 zoned(7) const;
      end-pi;

      Not sure, I tried Zoned, it works when i call the program directly, but when i call from PGM1 - the values are corrupted. Agree, its wrong data types - but what should be the correct data types to be used in Pgm2.

      Comment


      • #4
        When you define a field on a C spec with a length and decimal positions, it defines it as a packed variable. So use PACKED(4) and PACKED(7) for the prototype.

        If you look at the Cross Reference section of the compiler listing for your calling program, you can see how Field1 and Field3 are defined. ("P" means "Packed".)
        Code:
              Global Field References:            
                 Field             Attributes     
                 FIELD1            P(4,0)         
                 FIELD2            A(4)           
                 FIELD3            P(7,0)

        Comment


        • #5
          OMG, How did I miss that.. Thanks a lot!

          Comment


          • #6
            Another great example of why numeric variables should always be declared using the P or S. People often don't realize that if they leave it out, it will be packed.

            Comment


            • tomliotta
              tomliotta commented
              Editing a comment
              More accurately, it might be packed; it depends on the rest of the declaration. As a DS subfield, a blank means zoned for a numeric field. Either way, leaving it blank is asking for eventual trouble.
          Working...
          X