|
> From: Hopkins, Bill > > Understand code var. length " Inz(%Len(Receiver)) " which allows you to > change length of receiver(good idea). But I not seeing length of receiver > var. field size 10I? > > "Length of receiver variable > INPUT; BINARY(4) > The length of the receiver variable. If the length is larger than the size > of the receiver variable, the results are not predictable. The minimum > length is 8 bytes." This has caught me several times. BINARY(4) means a 4-byte binary field. Now, a little mathematics shows that a 4-byte binary field is 32 bits long, and so can hold a number up to 2^32, or 4,294,967,296. In order to define a decimal number large enough to hold the largest 4-byte binary number, you must specify 10 digits. Thus, to define a decimal integer that is equivalent to a 4-byte binary number, you specify 10I. In fact, I use this little table: 3I = 1 byte 5I = 2 bytes 10I = 4 bytes 20I = 8 bytes It gets even more confusing when you use RPG fields of type "B" rather than "I". For some reason that I'm not privy to, a 9B field is "equivalent" to a 10I (which is a 4-byte binary field), while a 4B is equivalent to a 5I, which is a two-byte field. It's the fact that 4B is NOT equivalent to BINARY(4) that catches most folks when they're first doing this. Maybe Jon can shed a little light on that particular mystery. In any event, because of the varying field types and their non-intuitive relationship to one another, it's quite easy to make a mistake. Finally, there's one more gotcha. Let's take a data structure field, where you can optional specify the from and to positions, or just the length. If you specify just a length of 4 for a field of type B, it will define a field of type 4B, which as we've seen is only two bytes long. However, if you specify a from and to position that defines the field to be four bytes long (for example, from position 1, to position 4), the compiler will create a field of 9B, which is four bytes long. Confused yet? So, when defining a field equivalent to BINARY(4), you have the following options: 1. Define a field of 10I, 10U or 9B 2. Define a subfield four positions long of any of those types (I/U/B) Since 99% of my uses of binary/integer fields are currently in data structures, I tend to always define from and to positions. It saves me grief. Joe
As an Amazon Associate we earn from qualifying purchases.
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.