Import from textfile using Codeunit - Trim spaces?

WaldoWaldo Member Posts: 3,412
edited 2004-05-16 in Navision Attain
I have a problem using this code to import a fixed-length textfile into a temporary Navision-table:
  ...
  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?

Eric Wauters
MVP - Microsoft Dynamics NAV
My blog

Comments

  • Tommy_SchouTommy_Schou Member Posts: 117
    edited 2004-05-11
    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
    Tommy
  • RobertMoRobertMo Member Posts: 484
    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           
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  • WaldoWaldo Member Posts: 3,412
    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.

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • RobertMoRobertMo Member Posts: 484
    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           
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Sign In or Register to comment.