Link to home
Start Free TrialLog in
Avatar of karunamoorthy
karunamoorthyFlag for India

asked on

using foxpro2.5, append text with pipe delimited records

I am using foxpro2.5 for dos. I want to append a dbf file with text file having pipe '|' as field delimiter. How to append text file into dbf file with pipe delimited records.
Avatar of Cyril Joudieh
Cyril Joudieh
Flag of Lebanon image

APPEND FROM test.txt DELIMITED WITH CHARACTER |
Avatar of karunamoorthy

ASKER

My table is ename c(25), empno c(6)

My data is

PKM|123456
KSBKMM|234568
KMM|789456

I have tried APPEND FROM test.txt DELIMITED WITH CHARACTER |
but could not succeed!
SOLUTION
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or you can read the file using a low level function:

FOPEN
FREAD
FCLOSE
You could also import the file in excel and then export as something ou can append in fp 2.5

Bye, Olaf.
>>CaptainCyril,
You idea is ok but I am interested to know any easy single line command like append available so that I can avoid bulk coding.

>>Olaf_Doschke,
Your idea of uploading to excel file and then exporting to fp file is only process I am doing right now all along. Actually I am getting the file from some other sources which is to be processed further by me to get the correct format and also to check data validation and ensure correcness. Hence I am interested in automating the process without user intervention. Excel import and then export to fp 2.5, I feel manual intervention is required in that process.
>>pcelba,
Workaround given is ok for me to some extent. But now the problem is I have to search '|" and replace with \t is a problem for me.
Unfortunately the 2.5 and 2.6 versions of FoxPro on my laptop do not run because my laptop is 64-bit. The command I gave you works perfectly with VFP 9.2.

Half of my imports in 2.5 and 2.6 were using FOPEN since my software used to read exports from many accounting software.
>>CaptainCyril,
Any sample coding to use FOPEN for this, may find helpful to me.
hFile = FOPEN(cFileMap, 0)
IF hFile < 0
      = MESSAGEBOX("Could not open file!", 48, appname)
      lOK = .F.
      RETURN
ENDIF
nFileSize = FSEEK(hFile,0,2)
= FSEEK(hFile,0,0)
nBytesRead = 0
DO WHILE NOT FEOF(hFile)
      cLine = FGETS(hFile)
        ? cLine
      nBytesRead = nBytesRead + LEN(cLine) + 2
      oThermometer.update(nBytesRead/nFileSize*100) && this line calls my thermometer progress bar to display estimates to finish
ENDDO
= FCLOSE(hFile)
>>CaptainCyril,
Using the above code, I can able to read text file line by line. Till now, it is ok for me.
But again how to load the text file which is read already into dbf file.
The real problem I face is I have a quite large number of fields in the dbf file.
Right now I am using like this,


First I append the text file using
APPE FROM TEST1.TXT sdf
here the first field I am using is say F0 with 254 chrs and then  the real fields which I require (for example
empno, ename etc)
Now, I am filling the empno field like
REPL ALL empno WITH substr(f0,1,atc("|",f0)-1)
REPL ALL ename WITH substr(f0,atc("|",f0,1)+1,atc("|",f0,2)-atc("|",f0,1)-1)
...
...
...
etc

Any suggestion please.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>pcelba,
I have already tried find/replace option. It is working fine. It is ok for me.

The real problem is the text file is coming daily and I have to do the file manipulation on daily basis. My idea is to automate the process and no manual user intervention is required. After making prg, I convert the same into exe file and put it in a scheduler, so that automation can happen.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial