Scott,

As always, you have a way to do everything. Thanks. I'll have to figure
out how I can still get the null indicators to be set properly though,
because the IBM manuals indicate that when a record is read directly into a
data structure, the null indicators are not set. I think that's fixed in
v5r4 but I'm writing for v5r3 at least.

I'm sure I'll be doing something similar to your suggestion. Thanks again.

Best Regards,

Thomas Garvey
Office: 630-462-3991

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of Scott Klement
Sent: Friday, June 20, 2008 12:38 PM
To: RPG programming on the AS400 / iSeries
Subject: Re: Handling decimal data errors at the field level

Hi Thomas,

When you write code that reads directly into a data structure, the system
does a block copy from the record buffer to the program. Since this block
copy doesn't look at the individual field definitions, it won't produce a
decimal data error.

You could then interrogate each field one-by-one to determine which (if
any) produce an error. If you decide to try this, I definitely suggest
moving the read logic into a subprocedure -- it'd be too cumbersome to put
in-line with the rest of your code.

For example:

FMYFILE IF E K DISK

D Record_t ds likerec(MYRECFMT:*INPUT)

.
.

P ReadMyfile B
D ReadMyfile PI 1n
D Rec likeds(Record_t)

D Temp ds likeds(Record_t)

/free
read MYFILE Temp;
if %eof;
return *OFF;
endif;

monitor;
Rec.Field1 = Temp.Field1;
on-error;
LogError('Decimal data error in Field1');
Rec.Field1 = 0;
endmon;

monitor;
Rec.Field2 = Temp.Field2;
on-error;
LogError('Decimal data error in Field2');
Rec.Field2 = 0;
endmon;

monitor;
Rec.Field3 = Temp.Field3;
on-error;
LogError('Decimal data error in Field3');
Rec.Field3 = 0;
endmon;

return *ON;
/end-free
P E

This code is off the top of my head, and I haven't compiled or tested it, so
I may have made a mistake somewhere. But hopefully you get the idea.

With that procedure in place, you'd simply call

ReadMyFile( MyRec );

when you want to read a record. Any fields with decimal data errors would
be logged (you'd have to write a LogError() procedure to do that) and the
log would tell you the exact field name (though, you'd probably want to add
more info to identify the actual record, as well) then the values converted
to zero.

Hope that helps.

Thomas Garvey wrote:
Hi,

Has anyone had any experience handling decimal data errors at the
field level? I know you can trap for the decimal data error that
happens when a record is read that contains a decimal data error in
one of the field values, and I know you can set the FIXNBR parameter
on the RPG compile to automatically fix numeric values that are bad.
But I want to know which specific field(s) in the record were bad.
It's OK that the compiler will fix them for me, but I want to know which
field(s) in the record were fixed.

Any ideas?

Best Regards,

Thomas Garvey
630-462-3991


--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or
change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
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:
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.