From Adt to Dbf

Post Reply
rubenfernandez01
Posts: 23
Joined: Sun Sep 20, 2015 1:41 am

From Adt to Dbf

Post by rubenfernandez01 »

Hi friends.
How to create a dbf table from adt (ADS) table.
There's something automatic.?

Thank you.
Saludos.


Enviado desde mi Redmi Note 8 Pro mediante Tapatalk
User avatar
carlos vargas
Posts: 1421
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: From Adt to Dbf

Post by carlos vargas »

Code: Select all

   USE NOMTABLA0 NEW  ALIAS CTRL 
   ...
   USE NOMTABLA10 NEW  ALIAS CXDT
   ...
   Adt2Dbf()
   ...
 

Code: Select all

PROC Adt2Dbf()

   //RddSetDefault( "DBFCDX" )

   SELECT CTRL
   Mig("control")
   SELECT USUA
   Mig("usuarios")
   SELECT FERI
   Mig("feriados")
   SELECT PLAZ
   Mig("plazos")
   SELECT ZONA
   Mig("zonas")
   SELECT CIUD
   Mig("ciudades")
   SELECT GEST
   Mig("gestores")
   SELECT COBR
   Mig("cobradores")
   SELECT RUTA
   Mig("rutas")
   SELECT CLIE
   Mig("clientes")
   SELECT PROG
   Mig("programacion")
   SELECT PBAK
   Mig("programacion_bak")
   SELECT PRES
   Mig("prestamos")
   SELECT DIFE
   Mig("diferidos")
   SELECT MOVI
   Mig("movimientos")
   SELECT FLUJ
   Mig("flujos")
   SELECT MCXR
   Mig("mcobrosxruta")
   SELECT DCXR
   Mig("dcobrosxruta")
   SELECT CAJA
   Mig("caja")
   SELECT CXDI
   Mig("cobroxdia")
   SELECT CXDC
   Mig("cobroxdiac")
   SELECT CXDT
   Mig("cobroxdiat")

   RddSetDefault( "ads" )

RETURN

PROC Mig(cTabla)
   LOCAL cOldAlias := Alias()
   LOCAL xT,xT1
   LOCAL aTab
   LOCAL n,o,i

   aTab := DBStruct()

   FOR x:=1 TO Len( aTab )
      IF aTab[ x, 2 ]="D"
         aTab[ x, 3 ]=8
      ENDIF
   NEXT

   DbCreate( "d:\dbc\" + (cTabla), aTab, "DBFCDX", .T. )

   USE ( "d:\dbc\" + (cTabla) ) ALIAS TEMP VIA "dbfcdx"

//   SELECT (cAlias)
//
//   n:=1
//   DO WHILE .T.
//      IF Empty( OrdName(n) )
//         EXIT
//      ENDIF
//      TRY
//         TEMP->( OrdCondSet((cAlias)->( OrdFor(n)),,.t.,,,, nil, nil, nil, nil,, nil, .F., .F., .F., .F.))
//         TEMP->( dbGoTop() )
//         TEMP->( ordCreate(,(cAlias)->( OrdName(n) ), (cAlias)->( OrdKey(n) ), &("{||"+(cAlias)->( OrdKey(n) )+"}") ))
//      CATCH o
//         SELECT (cAlias)
//         ?cTabla,(cAlias)->( OrdName(n) ), (cAlias)->( ordKey(n) )
//      END
//      ++n
//   ENDDO

   SELECT ( cOldAlias )

   WaitOn("Procesando: " + cTabla )

   i:=0
   GO TOP
   DO WHILE !Eof()
      TEMP->( DBAppend() )
      FOR x:=1 TO FCount()
         xT := FieldGet( x )
         TEMP->( FieldPut( x, xT ) )
      NEXT
      SKIP
      IF Mod( ++i, 100 )=0
         SysRefresh()
      ENDIF
   ENDDO

   WaitOff()

   TEMP->( DBCloseArea() )

   SELECT (cOldAlias)

RETURN
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
D.Fernandez
Posts: 392
Joined: Wed Jul 31, 2013 1:14 pm
Location: Maldonado - Uruguay
Contact:

Re: From Adt to Dbf

Post by D.Fernandez »

Gracias Carlos.
Impresionante.

Estoy comenzando con Mysql y por las dudas se corta la conexion
dejo a una PC trabajando con los dbf.

Gracias, saludos.
Dario Fernandez
FWH, Harbour, BCC, MySql & MariaDB, tData, Dbf/Cdx
VSCode.
Maldonado - Uruguay
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: From Adt to Dbf

Post by nageswaragunupudi »

If the ADT file contains only fields of types "+CDLNTM", then this works

Code: Select all

USE CUSTADT NEW VIA "ADSADT" // "ADT" in xHarbour
COPY TO CUSTDBF VIA "DBFCDX"
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: From Adt to Dbf

Post by nageswaragunupudi »

Small sample converting CUSTOMER.DBF to CUSTADT.ADT and then back to CUSTDBF.DBF

Code: Select all

#include "fivewin.ch"
#include "ads.ch"

REQUEST DBFCDX
REQUEST ADSKEYCOUNT, ADSGETRELKEYPOS, ADSSETRELKEYPOS, ADSKEYNO

static cRddADT

function main()

   local aStruct

   RddRegister( "ADS", 1 )
   AdsSetServerType( ADS_LOCAL_SERVER )

   cRddAdt  := If( AScan( RddList(), "ADSADT" ) > 0, "ADSADT", "ADT" )

   // DBF TO ADT

   aStruct  := FW_DBFSTRUCT( "CUSTOMER.DBF" )  // no need to open the dbf
   AEval( aStruct, { |a| If( a[ 2 ] == "N", a[ 3 ] += 1, ) } )

   DBCREATE( "CUSTADT.ADT", aStruct, cRddAdt, .t., "DST" )
   APPEND FROM CUSTOMER VIA "DBFCDX"
   GO TOP
   XBROWSER

   // ADT TO DBF

   GO TOP
   COPY TO CUSTDBF VIA "DBFCDX"
   CLOSE DATA

   USE CUSTDBF VIA "DBFCDX"
   XBROWSER

return nil
 
Regards

G. N. Rao.
Hyderabad, India
D.Fernandez
Posts: 392
Joined: Wed Jul 31, 2013 1:14 pm
Location: Maldonado - Uruguay
Contact:

Re: From Adt to Dbf

Post by D.Fernandez »

Thank you Mr. Rao.
Excellent.

I'm trying to convert a app using only Fwh with Mysql, a dbf/cdx.
Until now it's ok.

Thank you very much.

Saludos..Ruben Dario Fernandez
Dario Fernandez
FWH, Harbour, BCC, MySql & MariaDB, tData, Dbf/Cdx
VSCode.
Maldonado - Uruguay
Post Reply