Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Duplicates from multiple DBF with file source

Status
Not open for further replies.

TheLazyPig

Programmer
Sep 26, 2019
103
PH
Hi!

Example that I have multiple dbf files and some of the tables have duplicates. I want to get all duplicates as well as the file name where the duplicate locates.

filesrc_v8nbo4.jpg


The problem is I'm not getting the correct file_src

dbfff_hmrnsb.jpg


It seems that it only gets the first file name but the correct is the other (green box).

**To get Duplicate
Code:
PROCEDURE withDuplicate() 
local lnArea, lcTalk, llWithDup 
lnArea = SELECT() 
lcTalk = SET("Talk") 
SET TALK ON 

SELECT * ; 
FROM curAll ; 
WHERE REGCODE+DIVCODE+STACODE+EMPNO+POLICYNO+EFFYY+EFFMM+TERYY+TERMM IN ( ; 
SELECT REGCODE+DIVCODE+STACODE+EMPNO+POLICYNO+EFFYY+EFFMM+TERYY+TERMM ; 
FROM curAll ; 
GROUP BY 1 ; 
HAVING COUNT(*)>1 ; 
) INTO CURSOR curDup READWRITE 

llWithDup = reccount("curDup") > 0 

IF llWithDup 
[indent]
SELECT * FROM curDup INTO CURSOR curFil READWRITE 
ALTER TABLE curFil ADD COLUMN file_src c(100) 
REPLACE file_src WITH curData.filename FOR EMPTY(file_src) IN curFil 
BROWSE
[/indent] 

ENDIF 

SELECT (lnArea) 
RETURN llWithDup 
ENDPROC

**To get DBF Files
Code:
LOCAL pcSearchType,pcCurName,pcMainPath,pcSrcPath,pcRptPath,lfilename,lnTotAmt

*----------------------------------
pcSearchDBF  = "*.dbf"
pcSearchXLS  = "*.xls"
pcCurName    = "curData"
pcCurrDir    = CURDIR()
pcScrPath    = pcCurrDir+"\basket\"
sysDate	     = DTOS(DATE())
pcFileName   = "consoldt_"+sysDate
pnCtr        = 0
*----------------------------------

DO pcCurrDir+"popfiles" WITH pcScrPath, pcSearchXLS , pcCurName

IF ATC(".xls",curdata.filename) > 0
	MESSAGEBOX(".xls file exists in basket!",48)
ELSE
	DO pcCurrDir+"popfiles" WITH pcScrPath, pcSearchDBF, pcCurName

	SELECT filename as name FROM &pcCurName INTO CURSOR curTemp
	SELECT curTemp
	
	SCAN 

		IF pnCtr = 0 THEN
				
			USE (curTemp.name) NOUPDATE SHARED IN SELECT("crDbfRaw") AGAIN ALIAS crDbfRaw
			SELECT * FROM crDbfRaw INTO CURSOR curAll READWRITE
			
		ELSE
		
			USE (curTemp.name) NOUPDATE SHARED IN SELECT("crDbfRaw") AGAIN ALIAS crDbfRaw
			INSERT INTO curAll SELECT * FROM crDbfRaw
		
		ENDIF
			
		pnCtr = pnCtr + 1
		
	ENDSCAN

The popfiles.prg procedure returns cursor with records matching wildcard skeleton inside the given base directory (subdirectories included)

Thank you in advance!! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top