以下是引用mywisdom88在2022-7-13 12:38:48的发言:
吹斑竹,搞个函数出来玩玩。。。
简单示例
程序代码:
cDefPath = ADDBS(JUSTPATH(SYS(16)))
SET DEFAULT TO (cDefPath)
CREATE TABLE dbf1 (f1 c(11), f2 I, f3 n(9,2))
INSERT INTO dbf1 VALUES ("aa", 1, 1.12)
INSERT INTO dbf1 VALUES ("bb", 2, 2.23)
USE
CREATE TABLE dbf2 (f1 c(11), f2 I, f3 n(9,2))
INSERT INTO dbf2 VALUES ("cc", 3, 3.34)
INSERT INTO dbf2 VALUES ("dd", 4, 4.45)
INSERT INTO dbf2 VALUES ("ee", 5, 5.56)
USE
dbf1 = FILETOSTR("dbf1.dbf")
dbf2 = FILETOSTR("dbf2.dbf")
nDataOffset = CTOBIN(SUBSTR(dbf1,9,2),"2rs") + 1 && 数据块偏移量
nRecords = CTOBIN(SUBSTR(dbf1,5,4),"4rs") && dbf 记录数
nRecords = nRecords + CTOBIN(SUBSTR(dbf2,5,4),"4rs") && 合并表记录数
dbf = STUFF(dbf1,5,4,BINTOC(nRecords,"4rs")) && 取最前的表,修改记录数
dbf = LEFT(dbf,LEN(dbf)-1) && 前面的表去除文件结束标志
dbf = dbf + SUBSTR(dbf2,nDataOffset) && 追加最后的表(保留文件结束标志)
STRTOFILE(dbf,"dbf.dbf") && 保存合并的表
SELECT * FROM dbf
CLOSE TABLES ALL
DELETE FILE dbf.dbf
DELETE FILE dbf1.dbf
DELETE FILE dbf2.dbf