Page 1 of 1

Merging datas and structures

Posted: Sat Mar 26, 2016 2:02 pm
by cnavarro
In the Harbour group users

https://groups.google.com/forum/?fromgr ... Tisk_kIsXk

Code: Select all


DBSTRUMERGE("mpdbtmp",{ "plos2016", "poc2016", "ras2016", "rass2016", "razm2016", "vra2016", "vras2016"},.t.)

***********************************************************************
FUNCTION DBSTRUMERGE(cNewbase,aBases,mergeData)
LOCAL i, j, k, aDbf:={}, aDbftmp:={}, aErrFields:={},dSelect:=SELECT()

FOR i=1 TO LEN(aBases)
       DBUSEAREA(.T.,,aBases[i],,.t.)
       IF i=1 ; aDbf:=DBSTRUCT() ; LOOP ; ENDIF
       aDbftmp:=DBSTRUCT()
       FOR j=1 TO LEN(aDbftmp)
              IF (k:=ASCAN(aDbf,{| x | x[ 1 ] == aDbftmp[j,1] } )) <> 0
                  IF aDbf[k,2]<>aDbftmp[j,2] .OR. aDbf[k,3]<>aDbftmp[j,3] .OR. aDbf[k,4]<>aDbftmp[j,4] 
                      AADD(aErrFields,{ aBases[i],  aDbf[k,1] })
                 ENDIF
             ELSE   
                 AADD(aDbf, aDbftmp[j])
             ENDIF   
      NEXT
      DBCLOSEAREA()
NEXT    

DBCREATE(cNewbase, ASORT(aDbf,,, {| x, y | x[ 1 ] < y[ 1 ] } ) )    

IF PCOUNT()=3
    DBUSEAREA(.T.,,cNewbase,,.t.)
    FOR i=1 TO LEN(aBases)
           APPEND FROM (aBases[i]) 
    NEXT
    DBCLOSEAREA()
ENDIF

RETURN aErrFields


//By Zoran Sibinovic

 
No lo he probado aun, pero me ha parecido interesante

I have not tried yet, but I found interesting

Regards