Import from textfile using Codeunit - Trim spaces?

Waldo
Member Posts: 3,412
I have a problem using this code to import a fixed-length textfile into a temporary Navision-table:
I use this code in another database (3.01), where it trims the spaces automatically without any problems. When I use this code in my new database (3.70), it doesn't trim the spaces anymore.
Both database are on MS SQL Server.
What can be the cause of this?
... Number := COPYSTR(ptext,18,20); Name := COPYSTR(ptext,38,30); "Search Name" := COPYSTR(ptext,68,30); "Address line 1" := COPYSTR(ptext,98,30); "Address line 2" := COPYSTR(ptext,128,30); City := COPYSTR(ptext,158,30); Contact := COPYSTR(ptext,188,30); "Phone No." := COPYSTR(ptext,218,30); "Vendor Posting Group" := COPYSTR(ptext,248,10); "Currency Code" := COPYSTR(ptext,258,10); "Payment Terms Code" := COPYSTR(ptext,268,10); "Country Code" := COPYSTR(ptext,278,10); ...
I use this code in another database (3.01), where it trims the spaces automatically without any problems. When I use this code in my new database (3.70), it doesn't trim the spaces anymore.
Both database are on MS SQL Server.
What can be the cause of this?
0
Comments
-
I have no idea what the cause is. Unfortunately. But correcting the problem is simple enough.. just alter the code to be like this:
string := delchr(copystr(ptext,30,30),'>',' ');
That should make it work similarly to your 3.01 database and the code works on both db's without problems.Best regards
Tommy0 -
and if you want to trim also leading spaces (not only trailing) you should use:
string := delchr(copystr(ptext,30,30),'<>',' ');
And BTW, don't bother with "autotriming". although the code fields should be trimmed automaticaly. maybe the type has changed in new version ?®obi
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯0 -
Actually I'm pretty bothered with it, because I just upgraded my code from 3.01 to 3.70, and installed a new database with this code. My interfacing (with AS/400) works with a NAS, and it read files from a certain directory. Now, all these files are fixed (because of the AS/400), so I always have spaces when read with the code above.
Now, I'm interfacing a lot, so it means I have to do quite some changes, for which i really don't understand why? It has never been an issue in 3.01 on MS SQL Server 7.0 -
Sorry to hear that. What I meant is to check if only one field (of datatype CODE) is not trimmed or all of them?
It can be that NAS does not trim? Can you try running your function from navision client ?®obi
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions