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


  • Subject: Re: RPG400-L Digest V3 #74
  • From: Scott Klement <klemscot@xxxxxxxxxxxx>
  • Date: Fri, 2 Feb 2001 18:05:24 -0600 (CST)


On Fri, 2 Feb 2001, Terry Herrin wrote:
>
> I agree.  Something like an API's by Example book would be a
> tremendous help.  I'd rather not admit how many hours I spent with an
> API that kept bombing, until somehow I realized that a field I had
> declared "4b 0" needed to be declared as "9b 0".  
 
Hmmm... thats weird.  My API manuals refer to these fields as "Binary(4)",
not "4B 0".   Maybe your books are defective?

> <eval sarcasm = *on>
> Silly me, the documentation said the field is length 4 binary, but I
> should have known I really need to code it as length 9.  
> <eval sarcasm = *off>

And when I look to see what binary(4) means, I find this:

   1.2.2.3 Binary Data

   In the API parameter tables in this book, BINARY(2) and BINARY(4)
   represent numeric data. These parameters must be signed, 2- or 4-byte
   numeric values with a precision of 15 (halfword) or 31 (fullword) bits
   and one high-order bit for the sign. Numeric parameters that must be
   unsigned 4-byte numeric values are explicitly defined as BINARY(4)
   UNSIGNED.

You'll note that it does NOT say "length 4 binary", but is much more
specific.  It says "4-byte".   

Likewise, if I told you that my office is "10-length" I wouldn't be
specific enough, you wouldn't know if it was 10 feet, 10 yards, 10 meters,
or 10 cubits, would you?

You have to remember that these books are not RPG specific.  They are
intended to be used by CL, C, COBOL, RPG (etc) programmers.  Its not their
job to tell you how to code a 4-byte binary integer in RPG!   Their job is
to tell you to pass a 4-byte binary integer.   Its YOUR job to know how to
do so in your particular programming language.

In RPG, variables are defined by the number of digits that they can hold.
This, "7P 0" is a 7-digit packed number.  Not a 7-byte!  A 7-byte packed
number would be "13P 0".  Binary fields are the same way.  "9B 0" is a
9-digit binary variable, but its only 4 bytes long. 

In fact, 9B 0 isn't even the best type of field to use.   Even though 9B 0
is a 4-byte binary field, and it will be passed as such to the API, RPG
does not allow all possible values in the "9B 0" fields.  RPG cuts it off
at an even 9-digits.   Where a true 31-bit integer can store a value up to
2147483647, the 9B 0 limits you to 999999999.   

(This never made a lot of sense to me...  if you're going to call your
data type BINARY, why would you use DECIMAL digits to determine the
maximum value of the variable....  grrrr)

In RPG, the "true" binary(4) data type is "10I 0".  Instead of limiting
you to 9 decimal digits, it limits you to 31 bits (bit = binary digit)
saving that last bit for the positive/negative sign.   

Okay, I think I've pretty much beat THAT horse to death.

+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@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.