I have 3 databases
dbf1 -> with just 1 record filled with fieldnames of dbf 2
ID : "STYLE"
NAME : "TITLE"
CATMAIN : "CAT1"
...
dbf2 -> actual datafile (source data)
STYLE : "200444"
TITLE : "Safetyshoes dassy"
CAT1 : "Safetyshoes"
....
dbf3 -> target datafile where i what to put the data from dbf2
ID : "CUST->STYLE" -> should be "200444"
NAME : "CUST->TITLE" -> should be 'Safetyshoes dassy"
CATMAIN : "CUST->CAT1" ->should be 'Safetyshoes"
So, I do something wrong with the & operator
Here I miss the logic of converting strings
- Code: Select all Expand view
if apos > 0 // if >0, it is a fieldname else a standard data like "21%"
cTarget = "slave->"+fieldname(i)
// cField = "CUST->"+aCustfields[i]
cField = "CUST->"+cLookup
// cData = &cField // not working
cData = cField
&cTarget = cData
else // standard data, but no fieldname
cData = cField
&cTarget = cData
endif
Full Function
- Code: Select all Expand view
function filldbf()
Local aCustfields:={}
use slave
select slave
zap
close
use DASSY NEW alias CUST
use slave NEW alias slave
use master NEW alias master
select cust
for i = 1 to cust->(FCOUNT())
AADD(aCustfields,Fieldname(i)) // make arry with all fieldnames from datafile
next
select master
master->(dbgotop())
nMasterfields = master->(fcount())
cust->(dbgotop())
nTel = 0
do while !cust->(eof())
slave->(dbappend())
for i = 1 to nMasterfields
cWelkField = "master->"+fieldname(i)
clookup = alltrim(&cWelkfield) // data from the masterfile, result = fieldname to look for next
if !empty(clookup)
apos = ascan(aCustfields,clookup) // to see if the data is a fieldname, could also be simple data
if apos > 0 // found as a fieldname
cTarget = "slave->"+fieldname(i)
// cField = "CUST->"+aCustfields[i]
cField = "CUST->"+cLookup
// cData = &cField // not working
cData = cField
&cTarget = cData
else // standard data, but no fieldname
cData = cField // GIVES THE DATA, BUT ERROR FOR THE NEXT DO/ENDDO LOOK
&cTarget = cData
endif
endif
next
cust->(dbskip())
enddo
select slave
xbrowse()
close all
return
The result is a database filled with the fieldnames, but not the fielddata