>
>I still dont really understand how creating a seperate DATA SESSION would be beneficial. Can you briefly explain how and why you use this?
>
>Many thanks,
>
Well, I will give you example.
Let say you have report that has to present in the same (detail) line client's account balance, Invoices totals for past 3 years, and let say client payments in the past 6 months. (What a mess ha?!).
Now can you imagine how manu tables (databases) you would have to open/relate/calculate/././ , maybe the same table two or three times in order not to disrupt 'flow' etc etc...
Is there such table in the system that has all that? Well, there could be one but if there is not, let's create one! e.g. Result Cursor in it's own datasession.
In this pseudo code is presented how datasession can be utilized as 'Balance Server', and as report code place holder, making things very simple. (...Good old procedure files)
*****************************************
* Begin of pseudo code
* (I will never learn how to make code area white)
*****************************************
Define class AcountBalanceServer as Session
procedure init
this.OpenTables
procedure OpenTables
Open Database ...\Accounts.dbc
use accounts in 0 shared
.
.
procedure account_balance
lParameters cAccountCode,dWithDate
.
.
return nAccountBalance
Endefine
Define Class InvoicesBalanceServer as Session
procedure init
this.OpenTables
procedure OpenTables
Open Database Sales.dbc
use Invoices in 0 shared
use Invlines in 0 shared
.
.
procedure InvoiceBalance
lParameters nYear,cClientCode
.
.
return nYearInvoiceForClient
enddefine
Define Class BankDataServer as Session
.
.
procedure ClientPayments
.
return nPaymentInLastSixMonths
enddefine
*************************And now Materialization of all this
Local oReport
oReport=createobject('MyComplexReport')
oReport.ShutReport()
release oReport
Define Class MyComplexReport as session
my_dummy_frx ='\reports\dummyfrx.frx'
oAccountBalanceServer=createobject('AcountBalanceServer')
oInvoiceBalanceServer=createobject('InvoicesBalanceServer')
oBankDataServer=createobject('BankDataServer')
procedure ShutReport
this.OpenTables
this.CreateCursors
this.ProduceResults
report form (this.my_dummy_frx) to printer preview
procedure open tables
Open Database Clients.dbc
use Clients in 0 shared
procedure CreateCursors
Create Cursor ResultCursor(;
CL_CODE C(10), ;
CL_NAME C(40), ;
CL_ACCODE C(15), ;
AccBal N(12,2) , ;
InvSum N(12,2) , ;
PayTot N(12,2))
index on CL_CODE tag ClientCode
set order to ClientCode
procedure ProduceResults
select Clients
scan for ... &cCondition
scatter memvar memo
m.AccBal=this.oAccountBalanceServer.account_balance(m.CL_ACCODE)
m.InvSum=this.oInvoiceBalanceServer.InvoiceBalance(m.CL_CODE)
m.PayTot=this.oBankDataServer.ClientPayments(m.CL_ACCODE)
insert into ClientSumm from memvar
endscan
select ResultCursor
go top
enddefine
******************************
end of pseudo code
******************************
Every 'Server' open&relates&calculate data at his own terms (datasession) without messing up each other, and simply returns requested value back.
What makes this concept realy good, is fact that differents session objects can bring together data (results) from heterogenous data sources, like one could be 'poking' Oracle database for results, the other VFP database, third could be 'fishing' on the internet etc.
Nice&Easy.
I guess you know how how to 'cheat'
report to accept cursor instead of table ...