smusba
20th January 2009, 13:20
Dear Gurus,
Below is the script with 2 reports send. I want to merge these two scripts in one so dat i can get the data from both the tables in one report _send(). How to merge the scripts.
functions:
function read.main.table()
{ |db.set.to.default(ttdsfl003)
select tdsfl003.*
from tdsfl003
where tdsfl003.rwar = :rwar
and tdsfl003.dwar = :dwar
and tdsfl003.date between :odat.f and :odat.t
and tdsfl003.trtp = "MREQ"
order by tdsfl003.orno,tdsfl003.pono
selectdo
select tiitm001.*
from tiitm001
where tiitm001.item = :tdsfl003.item
selectdo
endselect
rprt_send()
endselect
select tdrpl100.*
from tdrpl100
where tdrpl100.rwar= :rwar
and tdrpl100.dwar = :dwar
and tdrpl100.odat between :odat.f and :odat.t
order by tdrpl100.orno, tdrpl100.pono
selectdo
select tiitm001.*
from tiitm001
where tiitm001.item = :tdrpl100.item
selectdo
endselect
rprt_send()
endselect
}
mark_h
20th January 2009, 23:20
Well I won't do the merge for you but I can tell you how I have done something similiar. Let use for example one report for GRP Production Orders and one for SFC Production Orders. First what I do is look at the two reports and create generic fields for them. So both reports have orno, item and description, maybe need date, and qty. So on the report I would use rpt.orno, rpt.item, tiitm001.dsca, rpt.date, rpt.qty - using the largest domain for rpt.qty.
Then in the session script what I do is something like this(simplified) - not sure about field names:
select tisfc001.*, tiitm001.dsca
from tisfc001, tiitm001
where tisfc001._index = {some index search}
and tiitm001._index1 = {tisfc001.mitm}
selectdo
if (some checks or stuff) then
rpt.orno = tisfc001.orno
rpt.item = tisfc001.mitm
rpt.date = tisfc001.prdt
rpt.qty = tisfc001.qrdr
rprt_send()
endif
endselect
select tipgc510.*, tiitm001.dsca
from tipgc510, tiitm001
where tipgc510._index = {some index search}
and tiitm001._index1 = {tipgc510.item}
selectdo
if (some checks or stuff) then
rpt.orno = tipgc510.orno
rpt.item = tipgc510.item
rpt.date = tipgc510.psdt
rpt.qty = tipgc510.oqan
rprt_send()
endif
endselect
This gives me one report from multiple tables - now usually I do something so I know which record come from which table. Sometimes a simple text field that says "GRP" or "SFC". This is how I combine multiple reports for multiple tables into one report and session.
smusba
21st January 2009, 09:26
Thanks Mark your logic was extremely helpful.
But i have got problem again.
I have wittten the script according to your format. It is getting the data for me .
Problem:
1. data is not accurate for Ordered (tdsfl003.quan) and Delivered(tdrpl100.dqua)
2. If I comment 2nd function I get data right for 1st function.
3. If I comment 1st function I get data right for 2nd function.
This is my script:
declaration:
table ttdrpl100 | Replenishment Order Lines
table ttdrpl105 | Replenishment Order Headers
table ttiitm001 | Items
table ttdsfl008 | Warehouse
table ttdsfl003
extern domain tccwar rwar,dwar
extern domain tcdsca dsca
extern domain tcdsca dwar.dsca
extern domain tcorno orno.f,orno.t,flag,orno
extern domain tcpono pono,ppos
extern domain tcdate odat.t,odat.f,rddt.t,rddt.f,date,odat,date.t,date.f
extern domain tcqrp3 dqty,dqua
extern domain tcitem item,item.t,item.f
extern domain tcmcs.str15 preq,preq.f,preq.t
|****************************** form section **********************************
form.1:
init.form:
get.screen.defaults()
|****************************** choice section ********************************
choice.cont.process:
on.choice:
execute(print.data)
choice.print.data:
on.choice:
if rprt_open() then
read.main.table()
read.main.table1()
rprt_close()
else
choice.again()
endif
|****************************** field section *********************************
field.rwar:
when.field.changes:
rwar = rwar
field.dwar:
when.field.changes:
dwar = dwar
field.odat.f:
when.field.changes:
odat.t = odat.f
field.item.f:
when.field.changes:
item.t = item.f
|****************************** function section ******************************
functions:
function read.main.table()
{
dqua = 0.0
select tdrpl100.*,tiitm001.dsca
from tdrpl100,tiitm001
where tdrpl100.rwar = :rwar
and tdrpl100.dwar = :dwar
and tdrpl100.odat between :odat.f and :odat.t
and tdrpl100.item refers to tiitm001
order by tdrpl100.orno,tdrpl100.pono
selectdo
if item = tdrpl100.item then
else
dqua = 0.0
endif
orno = tdrpl100.orno
dqua = tdrpl100.dqua
item = tdrpl100.item
pono = tdrpl100.pono
rprt_send()
endselect
}
function read.main.table1()
{
dqty = 0.0
preq = " "
select tdsfl003.*,tiitm001.dsca
from tdsfl003,tiitm001
where tdsfl003.rwar= :rwar
and tdsfl003.dwar = :dwar
and tdsfl003.date between :odat.f and :odat.t
and tdsfl003.item refers to tiitm001
order by tdsfl003.orno,tdsfl003.pono
selectdo
if item = tdsfl003.item then
else
dqty = 0.0
endif
orno = tdsfl003.orno
dqty = tdsfl003.quan
preq = tdsfl003.preq
ppos = tdsfl003.ppos
item = tdsfl003.item
rprt_send()
endselect
}
According to my thinking the problem can be solved
if
1.in the choice section 2nd function must be executed after fetching all the data from 1st function.
2. Can any one program 2nd funciton in such a way.
Other logic is also appareciated.
mark_h
21st January 2009, 16:01
Just the way you do it in the posted script works for me - I have done that plenty of times. I usually find all the records from one table, then go find all the records from the second table. So from what I see in the script that is what you are doing I do not see how the two functions could interfere with each other.
smusba
24th January 2009, 11:46
I have taken report layout as
itemcode desc ordered deivered orno
itemcode -> item
desc ->tiitm0001.desc
ordered ->dqty
delivered->dqua
orno -> orno
and has after.field->item
NvpBaaN
25th January 2009, 23:14
I think the probelm is due to variable initiailization. In the following code, when item = tdrpl100.item, you are assigning dqua = 0.0, but then after exiting from the IF statement you are assigning dqua = tdrpl100.dqua. Same is the case in the other function.
if item = tdrpl100.item then
else
dqua = 0.0
endif
orno = tdrpl100.orno
dqua = tdrpl100.dqua
item = tdrpl100.item
pono = tdrpl100.pono
rprt_send()
Maybe you should write this code as:
if item = tdrpl100.item then
dqua = tdrpl100.dqua
else
dqua = 0.0
endif
orno = tdrpl100.orno
item = tdrpl100.item
pono = tdrpl100.pono
rprt_send()
This should be done in both the functions, and then it should work.