I have discovered an error when using fieldref’s in a 360 database. Observe the following code:
l_RecordRef.OPEN(DATABASE::TestCountry);
l_RecordRef.INIT;
l_FieldRef := l_RecordRef.FIELD(1);
l_FieldRef.VALUE := 'dk';
l_FieldRef := l_RecordRef.FIELD(2);
l_FieldRef.VALUE := 'Denmark';
l_RecordRef.INSERT;
l_RecordRef.INIT;
l_FieldRef := l_RecordRef.FIELD(1);
l_CodeVar := 'uk';
l_FieldRef.VALUE := l_CodeVar;
l_FieldRef := l_RecordRef.FIELD(2);
l_FieldRef.VALUE := 'United Kingdom';
l_RecordRef.INSERT;
The table “TestCountry” consists of 2 fields, field1 is a “Code 10” and field 2 is a “Text 30”.
When the first insert occurs, then value inserted in the “Code 10” field should have been “dk” but only “k” is inserted. The “d” is somehow removed, which leaves us with incorrect data. Furthermore, a lowercase value has now been inserted in a “code” field causing a “database structure error 1204 in module 19” (Corrupted data). When executing the code, no runtime errors occurs, you have to run a database test, or a backup, to see the error.
If you on the other hand take a look at the 2nd insert, the lowercase value “uk” is assigned to a local variable of the type “Code 10”, the “uk” is therefore changed to “UK” so no errors occurs here.
I can only produce this error in a 3.60 database, but a word of warning: Creating this code in a 3.70 database and importing the object in a 3.60 database causes the same error, even thou the code works fine in a 3.70 database, where the error seams to have been corrected.
Hope some of you can use this…
Regards
Mark Westergaard
0
Comments
when you assign a decimal to a decimal fieldreference, it is always truncated to 4 decimals.
Best way to avoid both: do a client upgrade.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
I tried assigning a text directly to a decimal field, this also causes a database structure error. Spooky that no runtime errors occurs here.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
It's always fun to go back to older DB versions :?
Epimatic Corp.
http://www.epimatic.com