select projects &&Table which holds projects codes etc local aStru(1) afields(aStru) create cursor rProjects from array aStru alter table alias() add column income N(12,2) **Add other fields you need alter table alias() add column expences N(12,2) alter table alias() add column result N(12,2) index on projcode tag tag1 set order to projectcode tag1You can populate it with dummy values just to build FRX layout (tip: you can copy it on hard disc and use
define class ProjectIncomeAndExpencesServer as session procedure init this.OPenTables() procedure OpenTables * copy paste opening and relation of tables that existing function (or new methods inhere) uses, open table projexpences in 0 shared open table IncomeDetails in 0 shared open table budgets ... set relation to ... endproc **Now claculation methods/functions which return single value as result **Here you reuse whatever you can from old code **First Income; function CalculateIncome && new or existing code which calculate income figure per project lParameters cProjectCode local nIncome . select IncomeDetails =Seek(cProjectCode) scan while IncomeDetails.ProjectCode=cProjectCode . *Calculations . endscan return nIncome **Then expences side **Calculate sum of all expences for specific project code Function CalculateExpences && new or existing code which calculate expences figure lParameters cProjectCode . A+B+C-D=nExpences . return nExpences enddefine <pre/> So now you run all this in folowing way <pre> **Insert here tmp cursor creation code from above local oBalances oBalances=createobject('ProjectIncomeAndExpencesServer') select projects Scan for &cSomeCriteria &&You can rise ranges form before this to establish some report criteria scatter memvar memo m.income = oBalances.CalculateIncome(projects.ProjCode) &&Pass project code / get result figure m.Expences= oBalances.CalculateExpences(projects.ProjCode) &&Pass project code / get result figure m.result=m.Income-m.Expences insert into rProjects from memvar endscan oBalances = null &&Releases supporting session object (private sessions automatically closes all open tables) So you are left with cursor which have all results you need select rProject *browse normal &&At design time to verify results you are getting go top report form myReport to printer preview select rProjects use &&relese temporary cursor as wellMake sure that report runs in default datasession and that DE object does not open any tables.