Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ONE FOR THE EXPERTS - Appending lines with different for
Message
From
11/05/1998 01:15:50
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00098397
Message ID:
00098423
Views:
56
>Howdy from Nashville!
>
>Forgive me if this is a "newbie" question, but...
>
>I have an SDF file that I must append into a set of tables. Every line in the file can have a different layout and length depending on what kind of record it is. The kind of record is determined by the first character of the line.
>
>Here is the basic situation:
>
>INCOMING.SDF can have different layouts on a line by line basis, so I need to be able to look at the first character of an entire line, then append the entire line into a set of tables, like so:
>
>Line Layout 1 --> Table1.dbf (which just holds Layout 1 records)
>Line Layout 2 --> Table2.dbf (etc.)
>Line Layout 3 --> Table3.dbf
>Line Layout 4 --> Table4.dbf
>Line Layout 5 --> Table5.dbf
>Line Layout 6 --> Table6.dbf
>
>I thought about appending the entire file, line by line, into 1 MEMO field (since these lines have over 254 character lengths) in a temporary database, then APPENDing from the temp table into my other DBFs based on left(MEMOFIELD,1).
>
>USE MEMOFILE IN 0
>APPEND FROM SDFFile.txt TYPE SDF
>USE
>
>USE Table1 in 0
>APPEND FROM (MEMOFILE's MEMO field) FOR left(MEMOFIELD,1) = "3"
>etc., etc.
>
>Alas, FoxPro 3 didn't like the idea of appending an entire line into a memo field, giving me an error message of "No fields found to process." Sigh.
>
>Can anyone give me an idea as to how I should approach this wacked out file?
>
>Thanks so much,
>
>John
Hi John,
I would think of two ways. 1) Parse and append via lowlevel. 2) Append dummy, parse then append to real tables. First way depends on how much newbie you are so I would suggest the easier second :
* Create and append to a dummy cursor
* Not to a memo which is hard to parse also
* If a maxline len could be determined use it or table limits
#define maxlinelen 4096
cCursorStruc = ""
for ix=1 to ceiling(maxlinelen/254)
  cCursorStruc = cCursorStruc + iif(empty(cCursorStruc),"",",")+ ;
                 "f"+ltrim(str(ix)) + ;
                 " c(254)"
endfor
create cursor dummy (&cCursorStruc)
append from mytext type sdf
* Now parse to different textfiles here & Collect them
* You now have different sdf files for each table
* =AppendXtable(Table1Name,cExpr1)

function AppendXtable
lparameters cTableName, cExpr
m.Alias = alias()
copy to (cTablename+".txt") ;
     type sdf ;
     for f1 = cExpr
use (cTablename)
append from (cTablename+".txt") type sdf
use
select (m.Alias)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform