I'm sick of it. If I see one more line of new code that uses a B data type, I'm going to blow a vein in my neck.
The old B (binary) data type was retired back in OS/400 V3. In its place, IBM introduced and recommended the new I (integer) data type. The I data type is compatible with the old B data type as well as with the C, C++, and Java languages and the new TYPE(*BIN) support in V5R3 CL.
The I data type is much more efficient than B was. It performs faster because no conversion to/from packed occurs. B data types are mapped into packed under the covers in the compiler to allow decimal positions. I have never heard of one single instance where a B field used decimal positions (and if you have used decimal positions in a B field, I recommend that you keep it to yourself).
What's so great about the I data type? One thing is the speed; integer fields are so fast that I now use them as my default data type for numeric work fields.
Of course, if you need decimal positions, you need to continue to use packed fields for those applications. For all others, use the I data type.
To specify an I data type, you need to specify the number of digits that can be stored in the value (not an intuitive task) and the I data type itself. You also need to specify the number of decimal positions, which is always 0.
For example, to declare a 4-byte integer field, the following D specification can be used:
D Int4 S 10I 0
Field INT4 is declared. You pronounce the length and type as a "ten eye zero" value.
I believe this is why so many people continue to use B (binary) fields. It may be too confusing to use 10 for the field's length, when it is actually 4 bytes. Specifying a 0 for decimal positions seems like overkill to me, but it's not a showstopper.
The following illustrates the size of each available I data type, along with the declaration option for that field size.
|
This is a 3I0 value, also known as Int1.
| |
| |
And here's a 5I0 value, also known as Int2.
| | | |
| | | |
And a 10I0 value, also known as Int4.
| | | | | | | |
| | | | | | | |
And finally, a 20I0 value, also known as Int8.
The API documentation often refers to Bin(4) and Bin(2) values. When a Bin(4) value is specified, the 10I0 value should be used; if Bin(2) is requested, then 5I0 is appropriate. In fact, I data types are more-correct data types than the old B data types when using OS/400 APIs.
Short, Long, and Long Long?
You'll note that in other languages, the way you declare the so-called "integer" data type is not always intuitive. Below is a table that illustrates the cross-reference for I data types in RPG IV and other languages.
| Int 1 | Int 2 | Int 4 | Int 8 |
RPGIV | 3I 0 | 5I 0 | 10I 0 | 20I 0 |
C | char | short | int or long | long long |
C++ | char | short | int or long | long long |
SQL | N/A | SMALLINT | INT | BIGINT |
Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.
LATEST COMMENTS
MC Press Online