how to add two columns in the Report

how to add two columns in the Report

Postby davor0501 » Wed May 15, 2013 8:12 pm

how to add two columns in the Report,
I have a DBF file in which there is a field input and output field, using the report command to print the report should look like this:
input output balance
--------------------------------
100 0 100
20 0 120
0 10 110
0 5 105
-------------------------------
120 15 105
I do not know how to calculate the third column thank you for your help.
davor0501
 
Posts: 23
Joined: Thu Apr 21, 2011 6:02 pm

Re: how to add two columns in the Report

Postby FranciscoA » Wed May 15, 2013 10:10 pm

Hi, here's is an example:
Code: Select all  Expand view
local nBalance:=0

      REPORT oReport ;
     ...
     oReport:bInit := { || MyTable->(dbGoTop()), nBalance:= (nBalance+MyTable->debit - MyTable->Credit )   }  //FWH 1204
         
     COLUMN TITLE "DEBITS    " ;
          DATA  MyTable->Debit ;
          PICTURE "@Z 99,999,999.99" ;
          SIZE 10 ;
          TOTAL

     COLUMN TITLE "CREDITS    " ;
          DATA  MyTable->Credit ;
          PICTURE "@Z 99,999,999.99" ;
          SIZE 10 ;
          TOTAL

     COLUMN TITLE "BALANCE   " ;
          DATA nBalance += ( MyTable->Debit - MyTable->Credit ) ;
          PICTURE "99,999,999.99" ;
          SIZE 10

     END REPORT

     ACTIVATE REPORT oReport
 


Let me know if it helps you.
Regards.
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2158
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: how to add two columns in the Report

Postby davor0501 » Thu May 16, 2013 6:14 pm

Thanks for your help Mr. FranciskoA, this is a small example of what I wanted to do in my program who now works ok.
Best regards Davor.

#include "FiveWin.ch"
#include "report.ch"

REQUEST DBFFPT,DBFCDX

function rept()
local nBalance:=0,nfor,astruct,oReport

IF FILE("MyTable.DBF")=.F.
ASTRUCT := { ;
{ "AAA" , "N", 5, 0 }, ;
{ "DEBIT" , "N", 5, 0 }, ;
{ "CREDIT" , "N", 5, 0 } ;
}

DBCREATE("MyTable", ASTRUCT, "DBFCDX", , )
endif

USE MyTable NEW
index on str(MyTable->aaa) to aaacdx temporary
dbGoTop()
if eof()=.t.
for nfor=1 to 20
append blank
if nfor<=10
replace MyTable->aaa with 10
else
replace MyTable->aaa with 20
endif
replace MyTable->debit with nfor*2
replace MyTable->credit with nfor
next
endif

REPORT oReport ;
TITLE "Test" ;
HEADER dtoc(date());
FOOTER "Page: "+str(oReport:nPage,3) RIGHT;
PREVIEW


oReport:bInit := { || MyTable->(dbGoTop()), nBalance:= 0 } //FWH 1204

COLUMN TITLE "GROUP " ;
DATA MyTable->AAA ;
PICTURE "@Z 99999999" ;
SIZE 10


COLUMN TITLE "DEBITS " ;
DATA MyTable->Debit ;
PICTURE "@Z 99,999,999.99" ;
SIZE 10 ;
TOTAL

COLUMN TITLE "CREDITS " ;
DATA MyTable->Credit ;
PICTURE "@Z 99,999,999.99" ;
SIZE 10 ;
TOTAL

COLUMN TITLE "BALANCE " ;
DATA nBalance += ( MyTable->Debit - MyTable->Credit ) ;
PICTURE "99,999,999.99" ;
SIZE 10

GROUP ON MyTable->aaa

END REPORT

ACTIVATE REPORT oReport ON ENDGROUP nBalance:= 0
close all
return nil
davor0501
 
Posts: 23
Joined: Thu Apr 21, 2011 6:02 pm

Re: how to add two columns in the Report

Postby FranciscoA » Thu May 16, 2013 7:36 pm

davor0501,
Good.
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2158
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 101 guests