On 30-Jan-2014 03:43 -0800, Nick Ballinger wrote:
> On Thursday, 30 January 2014 09:18:11 UTC, Nick Ballinger wrote:
>
> <<SNIP>> I have done some further testing.
>
> The problem occurs when trying to examine the DS item see below. In
> DEBUG the item is indeed hex 8004, but trying to do the comparison
> following, causes the receiver overflow issue.
>
> c if Qdb_Qdbwhkey.DataType = x'8004'
>
> Here is the DS
> Qdb_Qdbwhkey DS 64 qualified
> D based(Qdb_Qdbwhkey@)
> D IntName 1 10a
> D ExtName 11 20a
> D DataType 21 22b 0
> D FieldLen 23 24b 0
> D Digits 25 26b 0
> D Decimals 27 28b 0
> D Attributes1 29 29a
> D AltNameLen 30 31b 0
> D AltName 32 61a
> D Attributes2 63 63a
>
> Here is the code <<SNIP>>>
>
> I cannot see this issue is caused by our utility, which access the
> API and returns what is expected, but I would appreciate any ideas as
> to how we can sort this out, as there will be other varying length
> key fields which would cause us issues.
>
> Many thanks, in advance for any help or observations.
That line of code would fail whenever the value for
Qdb_Qdbwhkey.DataType is any value greater than 9999 or less than -9999.
Thus that line of code will fail when the value of
Qdb_Qdbwhkey.DataType = x'8004', no matter how ridiculous that might
seem, because the value x'8004' is not supported for *that particular*
declaration used for the BINARY(2) referenced in the API documentation.
Solving that issue can be done by simply changing the Internal Data
Type specification on the DataType variable declared in the DS, to use
instead, one of [if using A (or a Blank), then also remove the Decimal
Positions specification] the following:
• U - unsigned integer field
• I - signed integer field
• A - character field
Of the other B="a fixed binary field" representations, i.e. for the
other variables with 2-bytes of Internal Data Type of B, only the
FieldLen would require a similar change because that value can also
exceed 9999.
So without actually looking at the code {thus <snip>ped above} beyond
the above declarative and that specific failing line of code [i.e. the
IF OpCode for a comparison of the variable to the hex literal], the
problem for that line of code is a usage problem, albeit heavily
influenced\exacerbated by a variety of issues:
First, the documentation for the Data_Type under the Key Field
Description Array (Qdb_Qdbwhkey) is somewhat poor; i.e. the declarative
descriptive as documented for the Data_Type should have been shown
identical to the declarative of Qddfftyp as CHAR(2) under the Field
Header (Qdb_Qddffld) instead of being shown as BINARY(2).
Second, although BINARY(2) means the same as an SQL SMALLINT, the RPG
has a heritage, for which a two-byte binary integer value is limited to
four digits of precision. Thus the exception msg MCH1210 overflow
condition effecting a 103 error condition [aka msg RNX0103] leading to
the inquiry RNQ0103, whenever the integer value represented by the
type=B requires more than four digits. Using the data type designation
of I tells the RPG that a true INTEGER type is required; i.e. the legacy
restrictions of the Fixed-Binary data type are not an issue.
Third, the debugger EVAL for its character presentation of that type
of numeric values, honors the four-digit presentation rules, but warns
not, that the presented value is not really what is there; the onus is
on the user to review the hexadecimal presentation of the full variable
storage using the :X suffix\extension for the EVAL request.
Fourth, although the API documentation includes some "common errors"
and some effective "best practices" which should have informed *against*
that particular declarative, the first problem with the "poor"
documentation could have eliminated any issue; i.e. the data-type was
never intended to be declared nor utilized as a numeric, thus it should
have been consistently shown declared as clearly a non-numeric type...
which although IMO just as unclear, the CHARacter data type has
sufficiently served that purpose [the whole issue with
BINARY(nbrOfBytes) being used _incorrectly_ where INT(nbrOfBytes) was
intended, should have been dealt with before ever any API docs were
published]. Besides that, my inability to find the doc reference that
warns of the use of RPGLE\RPG B data type was fruitless; difficult for
someone to be aware if not made extremely conspicuous.
--
Regards, Chuck