Creating an integer in RPGLE

1059320 pts.
Tags:
Integer
RPGLE
Looking for a way to create an integer in RPGLE in a way that is similar to the int command in Java. Is there anything like this?

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 6  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • philpl1jb

    Discussion: http://search400.techtarget.com/tip/Making-sense-of-integer-representation-in-RPG-code

    Either of these D-spec declarations

    D myInteger1 S 4b 0
    D myInteger2 S 10i 0

    54,090 pointsBadges:
    report
  • TomLiotta

    The linked article is incorrect in its reference to the 'B' data type:

    In past releases of OS/400, it was common to represent integer data as 4B 0 fields (4 byte binary integer). Many of the IBM API manuals still reference a 2- or 4-byte binary representation,...

    A [4B 0] declaration does not represent a "4 byte binary integer". It means that values will be stored in binary integer format and that the maximum value cannot exceed four decimal digits. An actual "4 byte binary integer" can hold values much larger than 9999. A [4B 0] declaration is much more like a "2 byte binary integer", though it's still limited to 9999 as a maximum value.

    The IBM API documents correctly refer to "4 byte binary integer" variables and are not related directly to RPG's [4B 0] declarations. The nearly equivalent RPG 'B' data type declaration would require having starting and ending positions rather than a single 'length' specification.

    For reasons like that, the [4B 0] notation probably should never be used nowadays. Use 'I' data types for signed integers and 'U' for unsigned integers. The 'B' data type has only a very few specific uses in current RPG coding. It can be used as a way precisely to include fractional decimal digits in memory while using a kind of binary integer memory format. (It's not clear why anyone would need to do that rather than use packed-decimal.)

    Tom

    125,585 pointsBadges:
    report
  • philpl1jb

    Agreed -- picked up the 4b 0 from another process.  I think we used  9b 0 before integer.types were introduced.

    D myInteger2 S 10i 0

    or for unsigned...

    D myInteger2 S 10u 0

    54,090 pointsBadges:
    report
  • anandx
    Numbers are handled in RPGLE as packed, zoned, binary decimal, floating point, signed integer and unsigned integer data types. Of those the last two are binary integers (without decimal). 
    In binary, each bit of a byte holds a value of 2 power of the positional value of that bit. A single byte can hold a max value of 256 (11111111) for unsigned and 127 (s1111111) for unsigned where s is 0 or 1 for +ve and -ve numbers espectively. A single byte's max length (no of digits/precision) is 3, but size (in bytes) is 1. While declaring inside the pgm it is 3, but in memory it is 1, which is invisible inside the pgm. 1 byte can take a value from 0 to 255 (unsigned) or -127 to +127 (signed).
    Permissible sizes (of bytes) are: 1,2,4,and 8. Correspondingly, possible lengths (no of digits) are 3,5,10 and 19. Thus, 1,2,4... digits are disallowed.
    While declaring a binary variable consider no of digits, range of values it can take and the bytes it occupies in storage. Here is some sample:

    dcl-s f1  int(03) inz(256) ; digits-3; byte-1;  
    dcl-s f2  uns(05) inz(-32768) ; digits-5; byte-2;
    dcl-s f3  bindec(6:2) inz(1234.56) digits-6; byte-4;
    dcl-s f4  int(04) ; // invalid

    625 pointsBadges:
    report
  • anandx
    Correction. 
    dcl-s f1  int(03) inz(256) ; digits-3; byte-1;  
    should have been:
    dcl-s f1  int(03) inz(255) ; digits-3; byte-1;  
    sorry, my oversight
    625 pointsBadges:
    report
  • GregManzo
    @Tom. The old 4B 0 declaration was for a 4-digit field stored in binary format - ie 2-byte binary. As Philip suggests, 9B 0 is for a 4-byte binary field. I think the logic behind this was that they were keeping to the old packed format convention of declaring the number of digits, not the size in bytes. In any event, it seems we are all agreed that nowadays it's better to use 5i 0 and 10i 0 for signed integers & u for unsigned.
    1,995 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: