>I changed the subfield spec from binary to
>integer and the program didn't blow.  But,
>I saw something very interesting.  I use
>curLine to check when to print exception
>headings; put the program into debug and
>checked the value before first output to
>the printer file.  When defined as integer
>curLine=6448.  But, if you define curLine
>as binary (per the specs in File Management)
>curLine=16448 before the write (dump value was
>curLine='4040'x) and you abend with "receiver
>too small to hold result."  Anyway, with the
>definition as integer, after the first write
>curLine=6, which is what I would expect.  I
>guess I'll leave it defined as integer, but
>I'd sure like to know why the binary definition
>isn't working.

Well, RPG's 'binary' data type does not support the full range of numbers
possible in a binary number.  Maybe I need to back up.  A binary number (in
the sense the manual uses the word binary) is one whereby each binary digit
is used to represent a numeric value in increasing powers of two.  So, a 2
digit binary number can hold numeric values as high(!) as 4:  2 (binary) to
the 2nd (two digits) power = 4.  An 8 digit binary number can hold numeric
values as high as 2^8, or 256.  A two byte binary number has 16 bits
(digits) so it can hold numeric values as high as 2^16, or 65536.  (I'm
ignoring the sign for this discussion.)

An RPG 'binary' data type can be two bytes or four.  Sneaking a peek at the
RPG Reference, Chapter 10 (Data types) we can see that the 2 byte 'binary'
gets defined with a length of 4.  Theoretically a two byte field should be
able to hold a value up to 65536 as described above.  But with length 4, we
can only store up to 9999!  That's why your printer's current line counter
drops the high-order digit when converting binary (b'100000001000000') to
decimal 16448.  There aren't enough positions to hold all 5 decimal digits
so you end up with 6448.

An RPG 'integer' data type is a Real, True, Honest implementation of the
binary data format (as laid out in the RPG Reference.)  'Integer' includes
interpreting the highest-order bit as the sign, so a two byte integer
actually can hold values between -32767 and +32767 (2^15=32768).  The
'unsigned' data type is what I was describing above.

  --buck

"This box Rocks!" - related to 2002 NE IBM
Conference attendees by IBM's Stephanie Joy


This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.