× 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.



The basic notion behind the B data type was to allow the definition of binary variables in RPG (and COBOL works the same way incidentally) in the traditional way i.e. in terms of number of digits or characters,

Numbers in packed or zoned were capable of holding the full range of values i.e. a 5 digit number could hold -99,999 to +99,999 so when the B type was introduced it was decided to constrain its capacity to the maximum number of digits whose full range could be expressed within it. A 4 byte binary can represent values with 10 digits, but RPG and COBOL constrained it to 9 digits because that was the highest number where the full capacity of that many digits could be expressed.

In order to maintain this limit, when a numeric operation is performed on a type B field the value is copied to a packed field of equivalent precision, the operation is performed (with potential overflow) and the resulting packed value copied back to the B type variable. The result is that a B data type - which should theoretically be the most efficient was to represent (say) loop counters, offsets etc, was actually the least efficient.

The decision was made back in the (I think) RPG III days on S/38. Personally I think it was silly - but then I think Int(10) instead of Int(4) was a mistake too - but the decision was made for similar reasons - i.e. defining numerics in terms of digits not storage occupancy.

When we developed RPG IV the decision was taken to add the U and I data types to allow for real integers. The old B type had to stay for compatibility but is strongly discouraged. Except that sadly a great many IBM examples were never updated (and have not been to this day) to get rid of the stupid B data types,



On Aug 25, 2020, at 5:33 PM, James H. H. Lampert <jamesl@xxxxxxxxxxxxxxxxx> wrote:

On 8/25/20 2:24 PM, Bruce Vining wrote:
Oh please, don't use the B data type, you (unless something in RPG has
changed) just made a mess of the RRN. Int is how IBM defines it and is how
the program should treat it.

Quite. As I recall, a "B" is only binary in a record within a file. Shocked my <E. asinius> across the room, the first time I got bit by that little "gotcha." What WERE they THINKING?

--
JHHL
--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link: https://amazon.midrange.com


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.