SET TALK OFF
SET SAFETY OFF
CLOSE TABLES 
axx=0
SELECT hatemp.month as months,pdtcode,spec,type1,type2,boxes,standn,SUM(qty) as sqty,SUM(pdtvalu) as spdtvalu FROM hatemp GROUP BY hatemp.month,hatemp.pdtcode,hatemp.spec,hatemp.type1,hatemp.type2,hatemp.boxes,hatemp.standn INTO CURSOR tag1
FOR tg=1 TO RECCOUNT()
   SELECT hatemp.month as months,pdtcode,spec,type1,type2,boxes,standn,SUM(qty) as sqty,SUM(pdtvalu) as spdtvalu FROM hatemp GROUP BY hatemp.month,hatemp.pdtcode,hatemp.spec,hatemp.type1,hatemp.type2,hatemp.boxes,hatemp.standn INTO CURSOR tag1
   GO tg
   tg1=months
   tg2=pdtcode
   tg3=spec 
   tg4=standn
   tg5=type1
   tg6=type2
   tg7=boxes
   tg8=sqty
   tg9=spdtvalu
   ? RECNO()
   USE hamx
   APPEND BLANK 
   REPLACE hamx.month WITH tg1,hamx.pdtcode WITH tg2,hamx.spec WITH tg3,hamx.type1 WITH tg5,hamx.type2 WITH tg6,hamx.boxes WITH tg7,hamx.qty WITH tg8,hamx.pdtvalu WITH tg9,hamx.standn WITH tg4
   IF USED('odrep') THEN 
      SELECT odrep
   ELSE
      SELECT 0
      USE odrep
   ENDIF 
   LOCATE FOR odrep.month-odrep.pdtcode-odrep.spec-odrep.standn==tg1-tg2-tg3-tg4
   ? FOUND()
   *BROWSE
   IF FOUND()
      REPLACE hamx.team WITH odrep.team,hamx.rep WITH odrep.rep,hamx.regbj WITH odrep.regbj,hamx.supbj WITH odrep.supbj,hamx.repbj WITH odrep.repbj,hamx.city WITH odrep.city,hamx.prov WITH odrep.prov 
      *USE IN odrep
   ELSE
      axx=axx+1 
      REPLACE hamx.team WITH '非目标',hamx.rep WITH '非目标',hamx.regbj WITH 'XX',hamx.supbj WITH 'X',hamx.repbj WITH 'XXX'
      *USE IN odrep
   ENDIF
   USE IN odrep 
   USE IN hamx
   
ENDFOR 
?axx
CLOSE TABLES 
RELEASE ALL 
各位有空了帮忙看看,标红的字体是出问题的地方,使用browse之后,标红的语句可以执行,否则repl结果为空值。
我放了个axx在else之后测试了一下,axx是可以计数的。只是repl不正确。