doornbos
4th October 2002, 12:58
Hi,

How can I ignore records in a report script? Based on some conditions I would like to skip the current record and get the next one from the session script.

For example:

after.receive.data:
if ( tppdm600.cprj = "ABCDEF" ) then
| this record should not taken into account in this report
...receive next data...
endif

Is this possible is some or another way?

Thanks, Douwe.

Eddie Monster
4th October 2002, 14:27
One method is to process the record, but let it pass through without printing it on the report. For example:


|********************* DETAIL.10.LAYOUT
detail.10:
before.layout:
if ( tppdm600.cprj = "ABCDEF" ) then
lattr.print = false
else
| process record as usual...
endif

A second method is by not even sending that record to the report script. Put this into the selectdo clause of your select statement.

if ( tppdm600.cprj = "ABCDEF" ) then
| do nothing
else
| process record as usual...
rprt_send()
endif

doornbos
4th October 2002, 17:00
Hi Eddie,

Thank you for your response. Unfortunately I've no access to the programscript, so the second method is not an option.

The first one (excluding the record from processing) is a lot of work in my case, because there are many places in the reportscript where I should do this. That's why I am looking for a way to just ignore the current record and read the next one.

With kindly regards, Douwe.

Eddie Monster
4th October 2002, 17:08
I would refer you to a solution provided by mark_h:

http://www.baanboard.com/baanboard/showthread.php?s=&threadid=1908

This worked for me for some of my other projects where I did not have access to the source code.

mark_h
4th October 2002, 17:19
I was just getting ready to post the code again because I could not find the thread. Also your link worked for me.

Mark

doornbos
7th October 2002, 12:39
Hi,

Thank you for helping me. I've been studying the code of Marks solution. It really is a nice workaround! But in my case isn't the code below a solution? Or am I overlooking something?


after.receive.data:
while ( tppdm600.cprj = "ABCDEF" )
| this record should not taken into account in this report
r.read.seq.file()
endwhile


With kindly regards, Douwe.

mark_h
7th October 2002, 15:24
Have you tried it? It looks like it will work. My code was designed to add a new sort field to the report - we do not own source and had to modify the report to get the new sort field.

Mark

doornbos
8th October 2002, 11:41
Hi,

I tried, but the last record is causing some problems. If the last record should be skipped then the program enters a endless loop. So I changed the code a bit:

after.receive.data:
while ( ( tppdm600.cprj = "ABCDEF" ) and ( e = 0 ) )
| this record should not taken into account in this report
r.read.seq.file()
endwhile

But with the code above the last record is always printed, even if it shouldn't. What can I do to notify the report that there are no more records to process?

...
endwhile
if ( e <> 0 ) then
| no more records to process
| don't even process the last record read
... finish off the report without printing the last record
endif

Thanks for your help.
With kindly regards, Douwe.

doornbos
10th October 2002, 11:20
Ok, I implemented the workaround provided by Mark.


after.receive.data
if (first = 0) then
r.o = seq.open(r.datafile$ & ".tmp", "w")
r.reccount = 0
while (e = 0)
if ( tppdm600.cprj <> "ABCDEF" ) then
l = seq.puts(r.recbuf$, r.o)
r.reccount = r.reccount + 1
endif
r.read.seq.file()
endwhile
l = seq.flush(r.o)
l = seq.close(r.o)
l = seq.close(r.lfn)
r.lfn = seq.open(r.datafile$ & ".tmp", "a+")
first = 1
endif


This seems to work. One final question: How important is r.reccount? I write r.recbuf$ containing the 'old' r.reccount in stead of seq.puts with a concat of all (in my case appr. 50) fields. Should I expect some side affects because of this, which I did not notice until now?

With kindly regards,

Douwe.

mark_h
10th October 2002, 15:47
I can not remember what the r.reccount was used for - I will go test this in a report I am working on.

Mark

mark_h
10th October 2002, 16:10
I do not think you have any problems with r.reccount. It looks like it is only used in the r.write.seq.file.

Also I notices that when e became -1 it went to the r.afters() section. So maybe this would have worked using your code:

after.receive.data:
while ( tppdm600.cprj = "ABCDEF" )
if e=0 then
r.read.seq.file()
else
r.afters()
endif
endwhile


Of course this is just a guess, but I am curious.

Mark

doornbos
11th October 2002, 12:32
Hi Mark,

The r.afters() call is resulting in some fatal errors. So I stick to the 'replace datafile' solution which is working ok.

Fatal error: r.sorttab index 0 buiten dimensie [1] 4

Another question was bubbling up: If I'm right the number of fields in a datafile record is checked. When adding a new sort field, how did you keep the number of fields in the datafile the same?

Eddie and Mark, thank you for your help.

With kindly reagrds,

Douwe.

mark_h
11th October 2002, 15:33
What we did was add tipgc001.cplb to the input fields. The report then expected the correct number of fields and this field was always empty.
Actually we added it as a sort field, but it doesn't do anything until we populate it and sort it in the script.

Mark

doornbos
25th October 2002, 10:25
Hello, it's me again,

I need a function to abort the printing process. When there are no records left after the filtering, the report still prints the last record read from the old datafile. So I would like to add someting like

if ( r.reccount = 0 ) then
| abort printing
....
endif

I tried the end() function but that doesn't work. The headers of the report are still printed then. Setting lattr.enddata to true doesn't work either (it's a readonly var after all).

Anybody any idea how to abort the printing process from a report script.

With kindly regard,

Douwe.

mark_h
25th October 2002, 15:42
What you can try is to set a variable to false, then in each section check the variable and set lattr.print to false.


before.program:
stopprint = false

After.receive.data:
if r.reccount = 0 then
stopprint = true
...exit this routine....
endif

heading.1:
before.layout:
if stopprint then
lattr.print = false
endif

detail.1:
before.layout:
if stopprint then
lattr.print = false
endif


Or you could stopprint in the output expression of the layouts. Just some thoughts.

Mark