Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
APPEND FROM [SQL Cursor]
Message
From
23/12/2008 15:50:16
 
 
To
23/12/2008 13:33:14
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01369081
Message ID:
01369484
Views:
38
Hi Tore,

>Please do me the favour to check again. As I wrote, add a simple Browse to check that records really are selected.
I did this check. Records are selected.

>And once more I ask you to please show us the WHOLE non working code, WITHOUT any modifications.
Ok, the entire method up to the problem point appears below.

>To make the code more readable, please use...
Ok, thanks. I didn't know how to do this.

Best regards, Chaim
* LocalCreateReportDataVoluntaryDeductions
* export all voluntary deductions

* input:
*   ThisForm.iRun
*   table ADeduct

IF glsuspend
SET STEP ON 
ENDIF

* step 0A--create cursor CuDedEmp--all deduction data by employee
  CREATE CURSOR CuDedEmp;
    (iEmp I,;
     cNameLast C(25),;
     cNameFrst C(25),;
     cNameMI   C(1),;
     cNameSort C(51),;
     yDeduct   Y,;
     cAggType  C(1))

* step 0B--create cursor CuDedGLA--all deduction data by General Ledger Account
  CREATE CURSOR CuDedGLA;
    (cAcctCode C(5),;
     cAcctDesc C(25),;
     yDeduct   Y,;
     cAggType  C(1))

* step 0C--create cursor CuDedExp--all deduction data for export
  CREATE CURSOR CuDedExp;
    (iEmp I,;
     cNameLast C(25),;
     cNameFrst C(25),;
     cNameMI   C(1),;
     cAcctCode C(5),;
     yDeduct   Y,;
     cAggType  C(1),;
     cText     C(55))

* startup
  LOCAL lnTallyCuDed1GLA,lnTallyCuDed1Emp,lnTallyCuDed2,;
    lnTallyCuDed3EmpGLA,lnTallyCuDed3Emp,lnTallyCuDed3Gla
  STORE 0 TO lnTallyCuDed1GLA,lnTallyCuDed1Emp,lnTallyCuDed2,;
    lnTallyCuDed3EmpGLA,lnTallyCuDed3Emp,lnTallyCuDed3Gla

* step 1--Agg Type 1: aggregate deductions by employee by GL account
  SELECT;
      ADeduct.iEmp,;
      LUGLActD.cAccount       AS cAcctCode,;
      MAX(LUGLActD.cText)     AS cAcctDesc,;
      SUM(ADeduct.yDeduct)    AS yDeduct,;
      MAX(Employee.cNameLast) AS cNameLast,;
      MAX(Employee.cNameFrst) AS cNameFrst,;
      MAX(Employee.cNameMI)   AS cNameMI;
    FROM ADeduct JOIN Employee ON Employee.iPK = ADeduct.iEmp;
                 JOIN LUDeduct ON LUDeduct.iPK = ADeduct.iDeduct;
                 JOIN DedCmpny ON LUDeduct.iPK = DedCmpny.iDeduct;
                 JOIN LUGLActD ON LUGLActD.iPK = DedCmpny.iGLAcct;
    GROUP BY 1,2;
    WHERE ADeduct.iRun = ThisForm.iRun AND;
          LUDeduct.cAggType = "1"      AND;
          LUDeduct.lGL                 AND;
          DedCmpny.iCompany = ThisForm.iCompany;
    INTO CURSOR CuDed1EmpGLA NOFILTER READWRITE
  lnTallyCuDed1GLA = _TALLY    

* step 2--Agg Type 1: aggregate cursor CuDed1EmpGLA by employee
  IF lnTallyCuDed1GLA > 0

    SELECT;
        iEmp,;
        MAX(UPPER(cNameLast + cNameFrst + cNameMI));
                       AS cNameSort,;
        MAX(cNameLast) AS cNameLast,;
        MAX(cNameFrst) AS cNameFrst,;
        MAX(cNameMI)   AS cNameMI,;
        SUM(yDeduct)   AS yDeduct,;
        MAX("1")       AS cAggType;
      FROM CuDed1EmpGLA;
      GROUP BY 1;
      INTO CURSOR CuDed1Emp READWRITE NOFILTER
    lnTallyCuDed1Emp = _TALLY    

  ENDIF && lnTallyCuDed1GLA > 0

* step 3--aggregate cursor CuDed1EmpGLA by GL account
  IF lnTallyCuDed1GLA > 0
    SELECT;
        cAcctCode,;
        MAX(cAcctDesc) AS cAcctDesc,;
        SUM(yDeduct)   AS yDeduct,;
        "1"            AS cAggType;
      FROM CuDed1EmpGLA;
      GROUP BY 1;
      INTO CURSOR CuDed1GLA NOFILTER READWRITE
    lnTallyCuDed1GLA = _TALLY
  ENDIF && lnTallyCuDed1GLA > 0

* step 4--Agg Type 2: get garnishments
* TODO later

* step 5--Agg Type 3: get agg type 3 (currently Exchange)
IF glsuspend
SET STEP ON 
endif
  SELECT;
      ADeduct.iEmp,;
      LUGLActD.cAccount       AS cAcctCode,;
      MAX(LUGLActD.cText)     AS cAcctDesc,;
      SUM(ADeduct.yDeduct)    AS yDeduct,;
      MAX(Employee.cNameLast) AS cNameLast,;
      MAX(Employee.cNameFrst) AS cNameFrst,;
      MAX(Employee.cNameMI)   AS cNameMI,;
      "3"                     AS cAggType;
    FROM ADeduct JOIN Employee ON Employee.iPK = ADeduct.iEmp;
                 JOIN LUDeduct ON LUDeduct.iPK = ADeduct.iDeduct;
                 JOIN DedCmpny ON LUDeduct.iPK = DedCmpny.iDeduct;
                 JOIN LUGLActD ON LUGLActD.iPK = DedCmpny.iGLAcct;
    GROUP BY 1,2;
    WHERE ADeduct.iRun = ThisForm.iRun AND;
          LUDeduct.cAggType = "3"      AND;
          LUDeduct.lGL                 AND;
          DedCmpny.iCompany = ThisForm.iCompany;
    INTO CURSOR CuDed3EmpGLA NOFILTER READWRITE
  lnTallyCuDed3EmpGLA = _TALLY

* step 6--Agg Type 3: aggregate cursor CuDed3EmpGLA by employee
  IF lnTallyCuDed3EmpGLA > 0
    SELECT;
        iEmp,;
        MAX(UPPER(cNameLast + cNameFrst + cNameMI));
                       AS cNameSort,;
        MAX(cNameLast) AS cNameLast,;
        MAX(cNameFrst) AS cNameFrst,;
        MAX(cNameMI)   AS cNameMI,;
        SUM(yDeduct)   AS yDeduct,;
        "3"            AS cAggType;
      FROM CuDed3EmpGLA;
      GROUP BY 1;
      INTO CURSOR CuDed3Emp NOFILTER READWRITE
    lnTallyCuDed3Emp = _TALLY
  ENDIF && lnTallyCuDed3EmpGLA > 0

* step 7--Agg  Type 3: aggregate cursor CuDed3EmpGLA by GL account
  IF lnTallyCuDed3EmpGLA > 0
    SELECT;
        cAcctCode,;
        MAX(cAcctDesc) AS cAcctDesc,;
        SUM(yDeduct)   AS yDeduct,;
        "3"            AS cAggType;
      FROM CuDed3EmpGLA;
      GROUP BY 1;
      INTO CURSOR CuDed3GLA NOFILTER READWRITE
    lnTallyCuDed3Gla = _TALLY
  ENDIF && lnTallyCuDed3EmpGLA > 0

* step 8--Agg  Type 1: copy CuDed1Emp to CuDedEmp
IF glsuspend
SET STEP ON 
endif
  IF lnTallyCuDed1Emp > 0



* test--failure expected--start
*!*	    SELECT CuDedEmp
*!*	    APPEND FROM (DBF("CuDed1Emp"))
* test--failure expected--end


* this is the workaround
    SELECT CuDed1Emp
    SCAN
      INSERT INTO CuDedEmp;
        (iEmp,;
         cNameLast,cNameFrst,cNameMI,;
         cNameSort,;
         yDeduct,cAggType);
        VALUES;
        (CuDed1Emp.iEmp,;
         CuDed1Emp.cNameLast,CuDed1Emp.cNameFrst,CuDed1Emp.cNameMI,;
         UPPER(CuDed1Emp.cNameLast + CuDed1Emp.cNameFrst + CuDed1Emp.cNameMI),;
         CuDed1Emp.yDeduct,CuDed1Emp.cAggType)
    ENDSCAN
  ENDIF && lnTallyCuDed1Emp > 0
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform