× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




I may be going against the grain here, but if the documentation says
4-byte binary I just specify 4-byte binary in my code, as shown below,
which works just fine, and the way we always used to define binary fields
prior to RPGIV.

The problem with this is that the "B" data type is not a true binary field. It's a decimal field (like packed or zoned) that's stored in memory according to it's binary value.


Whenever you do a math operation on a "B" field, it gets converted to packed before the operation occurs.

For example, you provided this definition:

0085.00 D                 DS
0086.00 D  MSGDLN                 1      4B 0

That will give you a 9-digit binary field. When any math operation is performed on it, it'll copy that 9-digit field to a 9-digit packed field, the math operation is performed on that, and then it's copied back.


The problem with that is that you can't use all 32 bits of the binary number. A true 4-byte (32-bit) binary number can store a value from -2147483648 to 2147483647. Note that that's a TEN digit number, and won't fit in a 9-digit packed field!

So there's two excellent reasons to use data type "I" (binary integer) rather than data type "B" (binary decimal)

a) Binary integer performs better.

b) Binary integer is a true BINARY(4) and supports all possible values that APIs can return.

The ONLY thing you have to do differntly in your code -- the absolute ONLY difference necessary from the programmer's perspective to gain these two benefits is to code the letter "I" instead of the letter "B".

For example:

     D                 DS
     D  MSGDLN                 1      4I 0


The problem lies if you code the field using the new sexy type 'S' for a
standalone field, when you only get the opportunity to specify the number
of DIGITS, rather than bytes.

It's not new or sexy, it's just you define variables in RPG IV. You defined variables using the number of digits in RPG II as well.


     C                     Z-ADD*ZEROS    MYNUM   70

Is that a 7 byte field? No. It's 7 digits. It's 4 bytes! Maybe that way is also new and sexy! :)

But, by all means, if you find it easier to define binary fields in a data structure, go ahead. But PLEASE PLEASE PLEASE don't use the "B" data type.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

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

This mailing list archive is Copyright 1997-2024 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.