IMHO it is not an (embedded) SQL, but an RPG Problem.
Just 2 things:
1st: Always initialize your Data Structures, i.e. add the key word INZ to the definition.
2nd: Add the H-Spec Keyword ExtBinInt(*YES).
Here is the description of the ExtBinInt H-Spec Keyword:
The EXTBININT keyword is used to process externally described fields with binary external format and zero decimal positions as if they had an external integer format. If not specified or specified with *NO, then an externally described binary field is processed with an external binary-decimal format. If EXTBININT is specified, optionally with *YES, then an externally described field is processed as follows:
DDS Definition
RPG external format
B(n,0) where 1 ≤ n ≤ 4
INT(5)
B(n,0) where 5 ≤ n ≤ 9
INT(10)
By specifying the EXTBININT keyword, your program can make use of the full range of DDS binary values available. (The range of DDS binary values is the same as for signed integers: -32768 to 32767 for a 5-digit field or -2147483648 to 2147483647 for a 10-digit field.)
Note: When the keyword EXTBININT is specified, any externally described subfields that are binary with zero decimal positions will be defined with an internal integer format.
Mit freundlichen Grüßen / Best regards
Birgitta Hauser
"Shoot for the moon, even if you miss, you'll land among the stars." (Les Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them and keeping them!"
„Train people well enough so they can leave, treat them well enough so they don't want to.“ (Richard Branson)
-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Chris Holko
Sent: Mittwoch, 27. Oktober 2021 13:45
To: RPG programming on IBM i <RPG400-L@xxxxxxxxxxxxxxxxxx>
Subject: %char and an identity column, as in binary
Please note, autocorrect was driving me insane
So in a file there is a field defined as
EDROW INT NOT NULL GENERATED AWAYS AS IDENTIFY
(START WITH 1 INCREMENT BY 1 MINVALUE 1 NO MAXVALUE NO CYCLE NO CACHE ORDER),
Anyway… the SQLRPGLE program is straightforward
Define an data structure with external name keyword to that file
Declare a cursor with each field selected from that file to load in the data structure
Fetch it.
then try to %char it into a string and voila, MCH1210 Receiver to small.
You can move the field into a BINDEC(9:0) and use that with %trim but not the field itself.
So why cannot I get the %Char over the data structure field to work? Is that not allowed?
V7R3 TR10
Error File
Create of Replace Table ErrorFile(
EDROW INT NOT NULL GENERATED AWAYS AS IDENTIFY (START WITH 1 INCREMENT BY 1 MINVALUE 1 NO MAXVALUE NO CYCLE NO CACHE ORDER)
Error_Identification for column ERRID CHAR(8),
Error_Text for column ERRTXT CHAR(500),
Sequence_Number for column ERRCOL dec(10,0),
Primary Key Key(ERRCOL)
)
RcdFmt ErrRcv;
Example. (auto correct is killing me)
dcl-s error string char(500);
dcl-ds errorfile_ds extname(‘ERRORFILE’) Prefix(Err_) Qualified End-Ds; dcl-s errbin bindec(9:0); dcl-s myerr char(8);
errbin=errorfile_ds.err_edrow;
error = ’The Error was ‘ + %trim(%char(errbin));
error = ’The Error was ‘ + %trim(%char(errorfile_ds.err_edrow)); <- that will MCH1210
sql to load is similar to
exec sql declare cursor mycursor for
select edrow, erred,errtxt,errcol
from errorfile
where errid=:myerr;
exec sql fetch next from mycursor into :errorfile_ds;
--
This is the RPG programming on IBM i (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link:
https://amazon.midrange.com
As an Amazon Associate we earn from qualifying purchases.