Alaska Software Inc. - DBT export
Username: Password:
AuthorTopic: DBT export
Slavko SlavicDBT export
on Sat, 18 Jul 2020 14:41:05 +0200
Hi all!
How to export DBT data to new DBF/DBT file with added new fields ? 
Structure of DBF file changed.
TIA,S


slavko_slavic.vcf
Andreas Gehrs-Pahl
Re: DBT export
on Sat, 18 Jul 2020 16:13:07 -0400
Slavko,

>How to export DBT data to new DBF/DBT file with added new fields ? 
>Structure of DBF file changed.

Just copy the values in a loop. If the field type and/or field length of the 
same fields in the new table have changed, you may want to replace the inner 
loop with more explicit code, doing the necessary conversions.

Procedure CopyTable(cOldDbf, cNewDbf, cOldDBE, cNewDBE)
LOCAL nFields := 0
LOCAL nField  := 0
   DbUseArea(.t., cOldDBE, cOldDbf, "Old", .f., .t.)
   DbUseArea(.t., cNewDBE, cNewDbf, "New", .f., .f.)
   nFields := Old->(FCount())
   while .not. Old->(EoF())
      DbAppend()
      for nField := 1 to nFields
         FieldPut(FieldPos(Old->(FieldName(nField))), ; 
                           Old->(FieldGet(nField)))
      next nField
*     Set Default values for new/added fields here, if applicable:
*     NewField1 := "NewFieldValue"
      Old->(DbSkip())
   enddo
   DbCloseAll()
return

Hope that helps,

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas@AbsoluteSoftwareLLC.com
web:   http://www.AbsoluteSoftwareLLC.com
[L]:   https://www.LinkedIn.com/in/AndreasGehrsPahl
[F]:   https://www.FaceBook.com/AbsoluteSoftwareLLC
Slavko SlavicRe: DBT export
on Sun, 19 Jul 2020 01:32:44 +0200
Andreas,
thank you very much,
excellent, seems to work
should make some effort about DEBRIS,
it is still empty ...

Concrete it is like this
Old DBF                       New DBF
-------------------------------------
ASSEMBLY   ,C ,5 ,0 ,
GENERLOC   ,C ,10 ,0 ,
VERTILOC   ,C ,2 ,0 ,
HORIZLOC   ,C ,5 ,0 ,
DEPOSITS   ,C ,1 ,0 ,
BOW_S      ,C ,2 ,0 ,
BOW_V      ,N ,3 ,0 ,
CORROSION  ,C ,1 ,0 ,
CRACKS_L   ,N ,3 ,0 ,
CRACKS_W   ,N ,3 ,0 ,
CRACKS_T   ,N ,3 ,0 ,
SCRATCH_L  ,N ,3 ,0 ,
SCRATCH_W  ,N ,3 ,0 ,
SCRATCH_T  ,N ,3 ,0 ,
                               DEBRIS, C, 1, 0
METHOD     ,C ,11 ,0 ,
RECORD     ,C ,40 ,0 ,
DATE       ,D ,8 ,0 ,
ACCEPT     ,C ,1 ,0 ,
CAUTION    ,C ,1 ,0 ,
CAUTION_M  ,M ,10 ,0 ,

S.


Andreas Gehrs-Pahl wrote:
> Slavko,
>
>> How to export DBT data to new DBF/DBT file with added new fields ?
>> Structure of DBF file changed.
>
> Just copy the values in a loop. If the field type and/or field length of the
> same fields in the new table have changed, you may want to replace the inner
> loop with more explicit code, doing the necessary conversions.
>
> Procedure CopyTable(cOldDbf, cNewDbf, cOldDBE, cNewDBE)
> LOCAL nFields := 0
> LOCAL nField  := 0
>    DbUseArea(.t., cOldDBE, cOldDbf, "Old", .f., .t.)
>    DbUseArea(.t., cNewDBE, cNewDbf, "New", .f., .f.)
>    nFields := Old->(FCount())
>    while .not. Old->(EoF())
>       DbAppend()
>       for nField := 1 to nFields
>          FieldPut(FieldPos(Old->(FieldName(nField))), ;
>                            Old->(FieldGet(nField)))
>       next nField
> *     Set Default values for new/added fields here, if applicable:
> *     NewField1 := "NewFieldValue"
>       Old->(DbSkip())
>    enddo
>    DbCloseAll()
> return
>
> Hope that helps,
>
> Andreas
>


slavko_slavic.vcf