Page 1 of 2
Comparar tablas dbf de misma Estructura
Posted: Fri Aug 19, 2016 9:34 pm
by Ismach
necesito comparar muchas tablas .dbf version anterior y nueva version de igual estructura e igual nombre pero los datos no necesariamente sean iguales
el problemita que tengo es que son casi 2000 tablas a comparar
quiero hacer un programa que reciba como parametro el nombre de la tabla
y me compare el contenido de los campos, alguien hizo algo parecido o me puede orientar como hacerlo?
Re: Comparar tablas dbf de misma Estructura
Posted: Fri Aug 19, 2016 11:32 pm
by andyglezl
necesito comparar muchas tablas .dbf version anterior y nueva version de igual estructura e igual nombre pero los datos no necesariamente sean iguales
el problemita que tengo es que son casi 2000 tablas a comparar
quiero hacer un programa que reciba como parametro el nombre de la tabla
y me compare el contenido de los campos, alguien hizo algo parecido o me puede orientar como hacerlo?
No capte realmente tu necesidad, Tal vez de esta forma...
aDirect := DIRECTORY( "*.dbf" )
FOR i = 1 TO LEN( aDirect )
Compara( cPath1, cPath2, aDirect[ i ] )
NEXT i
------------------------------------------------------
FUNCTION Compara( cPath1, cPath2, DBF )
USE cPath1+DBF
Estruct1 := DBSTRUCT()
CLOSE
USE cPath2+DBF
Estruct2 := DBSTRUCT()
CLOSE
RETURN IF( Estruct1 = Estruct2, .T., .F. )
Tendrías que crear una funciona que compare cada elemento de los 2 arreglos...
Re: Comparar tablas dbf de misma Estructura
Posted: Sat Aug 20, 2016 7:03 am
by esgici
andyglezl wrote:
Code: Select all
aDirect := DIRECTORY( "*.dbf" )
FOR i = 1 TO LEN( aDirect )
Compara( cPath1, cPath2, aDirect[ i ] )
NEXT i
------------------------------------------------------
FUNCTION Compara( cPath1, cPath2, DBF )
USE cPath1+DBF
Estruct1 := DBSTRUCT()
CLOSE
USE cPath2+DBF
Estruct2 := DBSTRUCT()
CLOSE
RETURN IF( Estruct1 = Estruct2, .T., .F. )
Code: Select all
/*
Test comparing arrays
*/
#include <hmg.ch>
PROC Main()
DEFINE WINDOW frmMiniFMan ;
ROW 0 ;
COL 0 ;
WIDTH 550 ;
HEIGHT 470 ;
TITLE 'Compare Arrays' ;
ON INIT DoTest();
MAIN
END WINDOW // MAIN
frmMiniFMan.Center()
frmMiniFMan.Activate()
ON KEY ESCAPE ACTION frmMiniFMan.Release
RETU // CompArrs.Main()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._
PROC DoTest()
aArry1 := { 1, 2, 3, 4 }
aArry2 := { 1, 2, 3, 4 }
* MsgDebug( IF( aArry1 = aArry2, "Equal", "Not egual" ) ) // Argument error
MsgDebug( IF( aArry1 == aArry2, "Equal", "Not egual" ) ) // Not Equal
RETU // DoTest()

- Result of using simple equal sign for compare arrays
- agrError.JPG (23.89 KiB) Viewed 4447 times
Re: Comparar tablas dbf de misma Estructura
Posted: Mon Aug 22, 2016 6:59 pm
by Ismach
Antes que nada muchas gracias por las respuestas, lo que necesito comparar son los datos, las estructuras son exactamente igual.
Re: Comparar tablas dbf de misma Estructura
Posted: Mon Aug 22, 2016 7:33 pm
by andyglezl
Básicamente es lo mismo, solo que en vez de comparar el arreglo, comparas el contenido.
Ya tienes los nombres de campos, carga el contenido y compara.
Otra forma es:
Que obtengas el valor numérico (checksum) de todo el contenido del registro y lo compares
contra el valor del otro registro.
Re: Comparar tablas dbf de misma Estructura
Posted: Mon Aug 22, 2016 8:12 pm
by Ismach
Ok... gracias. en cuanto lo finalice lo cuelgo. Saludos y gracias
Re: Comparar tablas dbf de misma Estructura
Posted: Tue Aug 23, 2016 6:18 am
by esgici
Hi Ismach and Andy
As far as I understand right, Ismach ask a way for compare only structures, no records.
Anyway "Checksum" isn't adequate and practical way.
I may propose another method;
If you ask your question by a language I can understand right; sorry this is only English (may be also Turkish

).
Viva HMG

Re: Comparar tablas dbf de misma Estructura
Posted: Wed Aug 24, 2016 1:12 am
by andyglezl
Hola esgici
Yo entendí que Ismach, quería comparar las estructuras, pero el quiere
comparar el contenido de cada campo.
-------------------------------------------------------------------------------------------
Hello esgici
I understood that Ismach, wanted to compare the structures, but he wants
compare the contents of each field.
Re: Comparar tablas dbf de misma Estructura
Posted: Wed Aug 24, 2016 6:05 am
by esgici
andyglezl wrote:...
Hello esgici
I understood that Ismach, wanted to compare the structures, but he wants
compare the contents of each field.
Comparing content of fields, but no records; interesting
Anyway, it's clear that I had understand wrong

; thanks
Viva HMG

Re: Comparar tablas dbf de misma Estructura
Posted: Wed Aug 24, 2016 12:27 pm
by serge_girard
Ismach,
This little sample will do the job:
Condition is both DBF must be the same structure and must have a unique key field.
Open both files with an index on the key.
Read the key fields and compare the key: (3 possibilties):
- if keys are equal: compare non-key fields
- key1 greater : missing in file2
- key2 greater: missing in file1.
On EOF of one of both files: STOP
Loop through EOF1 : missing in 2
Loop through EOF2 : missing in 1
Origin of this program is one of my very first COBOL exercise in 1980..
Code: Select all
// STRUCTURE OF BOTH DBF MUST BE EQUAL !!!
// EXAMPLE DATABASE WITH 2 FIELDS : KEY + SOME ATTRIBUTE (NAME)
USE C:\TEST\DBF_1 NEW
INDEX ON DBF_KEY TO WW1
EOF01 := EOF()
USE C:\TEST\DBF_2 NEW
INDEX ON DBF_KEY TO WW2
EOF02 := EOF()
SET PRINTER TO C:\TEST\COMPARE.TXT
SET PRINTER ON
SET CONSOLE OFF
SELECT DBF_1
GO TOP
DO WHILE .NOT. EOF01 .AND. .NOT. EOF02
IF DBF_1->DBF_KEY == DBF_2->DBF_KEY
? '01 ' + DBF_1->DBF_KEY + ' ' + DBF_1->NAME + ' 10 ' + DBF_2->DBF_KEY + ' ' + DBF_2->NAME
IF UPPER(ALLTRIM(DBF_1->NAME)) == UPPER(ALLTRIM(DBF_2->NAME))
? ' 100% EQUAL '
ELSE
? ' NAME # '
ENDIF
SELECT DBF_1
SKIP
EOF01 := EOF()
SELECT DBF_2
SKIP
EOF02 := EOF()
ELSE
IF DBF_1->DBF_KEY < DBF_2->DBF_KEY
// MISSING RECORD IN DBF2
? '01 ' + DBF_1->DBF_KEY + ' ' + DBF_1->NAME
SELECT DBF_1
SKIP
EOF01 := EOF()
ELSE
// MISSING RECORD IN DBF1
? '02 ' + DBF_2->DBF_KEY + ' ' + DBF_2->NAME
SELECT DBF_2
SKIP
EOF02 := EOF()
ENDIF
ENDIF
ENDDO
DO WHILE .NOT. EOF01
// MISSING RECORDS IN DBF2
? '01 ' + DBF_1->DBF_KEY + ' ' + DBF_1->NAME
SELECT DBF_1
SKIP
EOF01 := EOF()
ENDDO
DO WHILE .NOT. EOF02
// MISSING RECORD IN DBF1
? '02 ' + DBF_2->DBF_KEY + ' ' + DBF_2->NAME
SELECT DBF_2
SKIP
EOF02 := EOF()
ENDDO
CLOSE ALL
SET PRINTER TO
SET PRINTER OFF
SET CONSOLE ON
RETURN
Succes, Serge