GeraintJones
12th May 2005, 01:57
i have the following code to add out of stocks to our packingslips

after.order.1:
before.layout:
|* Get order line shortage info.

select tcibd001.dsca, tdsls401.item,
tdsls401.qoor, tdsls401.cups
from tdsls401, tcibd001

where tdsls401.orno = {:order}
and tdsls401.clyn = 1
and tcibd001.item = tdsls401.item
selectdo

shortages.qty = 0
shortages.item = tdsls401.item
shortages.unit = tdsls401.cups
shortages.shortage = tdsls401.qoor
shortages.description = tcibd001.dsca
selectempty
endselect

after.layout:
layout.again()


there are two problems, if i remove layout.again() i only get 1 line even if there are 3 or 4, and if i leave it there i get an infinate ammount of lines

any help appreceated.

I am new to Report scripting ;-)

beginer
12th May 2005, 07:34
Hi ,

The immediate solution that I can think of is setting a flag in selectempty of the query & checking this before calling the layout.again().
Ofcourse one time the layout will be repeated but not more than that.

There has to be a better solution than this..but this is what i could think of at this moment.

Regards,

Youp2001
12th May 2005, 13:02
Problem is that the system needs to know when all shortages have been printed. Setting a flag in the selectempty won't help you as the query in the before.layout is executed every time again when the layout.again is called. This results in your infinite loop.

You could try to change the query to a dynamic SQL query. Then you can check if you have an SQL id. If the id is filled, you don't need to parse and execute the query anymore.

You get something like this:

before.program:
sql.id = 0

after.order.1:
before.layout:
|* Get order line shortage info.
if sql.id = 0 then
query.str = "<your query>"
sql.id = sql.parse(query.str)
sql.where.bind(...) | To set the necessary variable
sql.exec(sql.id)
result = sql.fetch(sql.id) | To fetch the first record
if result <> 0 then
| An error occurred, probably no records...
sql.close(sql.id)
sql.id = 0
lattr.print = false
endif
endif
after.layout:
result = sql.fetch(sql.id)
if result = 0 then
layout.again()
else
sql.close(sql.id)
sql.id. = 0
endif

I haven't tested the above, but I think you could solve your problem in this way. Alternatively you could load you data in an array and print the array in using layout.again.

Success.

Youp

mark_h
12th May 2005, 15:51
Lots of posts in this form about layout.again - here is just one (http://www.baanboard.com/baanboard/showthread.php?t=1075&highlight=layout.again). Looks like you just need to stop the layout.again from occuring after the last record. You can check the print purchase order report. On our system it counts how many projects have been printed. Something like this with your code - did this kind of quick so this is the concept from our version of rtdpur440101000:


detail.1:
after.layout:
record.cnt = 1

after.order.1:
before.layout:
|* Get order line shortage info.
select count(tdsls401.item):total.cnt
from tdsls401, tcibd001
where tdsls401.orno = {:order}
and tdsls401.clyn = 1
and tcibd001.item = tdsls401.item
selectdo
endselect

current.cnt = 0
select tcibd001.dsca, tdsls401.item,
tdsls401.qoor, tdsls401.cups
from tdsls401, tcibd001
where tdsls401.orno = {:order}
and tdsls401.clyn = 1
and tcibd001.item = tdsls401.item
selectdo
shortages.qty = 0
shortages.item = tdsls401.item
shortages.unit = tdsls401.cups
shortages.shortage = tdsls401.qoor
shortages.description = tcibd001.dsca
current.cnt = current.cnt + 1
if record.cnt = current.cnt then
break
endif
endselect

after.layout:
if record.cnt<total.cnt then
record.cnt = record.cnt + 1
layout.again()
else
record.cnt = 0
endif

GeraintJones
13th May 2005, 01:09
Thankyou very much, that worked perfectly ;-)