×

Good News Everybody!

The new search engine is LIVE!

Please report any problems to david (at) midrange.com.




Thanks Joe

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.

I understand now.
Question Mike's code message also define last parm D SplfNumber as 8B 0 in
DataQueue DS. Should not that be a from 1 and to 4 or 9B or 10I since parm
is "8 Spooled file number Input Binary(4)".

Thanks
Bill Hopkins

-----Original Message-----
From: Joe Pluta [mailto:joepluta@PlutaBrothers.com]
Sent: Tuesday, September 17, 2002 9:15 AM
To: rpg400-l@midrange.com
Subject: RE: Problem Found! Need solution


> 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

_______________________________________________
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@midrange.com
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/cgi-bin/listinfo/rpg400-l
or email: RPG400-L-request@midrange.com
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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.