Re: Multiple "instances" of a report, all going at once?
Posted in 1994
> > OK, is there a way to do this? (I am pretty sure the answer is "no"). > > I want my program to write out a number of different output files, > all at once, all in the identical format. So I'd like to start > several "instances" of a single report, output rows to each of them, > then finish each report, then stop. > > For instance, I might be processing a large number of records, and > foreach record I do some calculation that tells me which state it > gets credited to. My users want to get a separate report for each > state. So I really want to start 50 different instances of my > report, send each record to one of them depending on results of > said calculation. > > Now I am pretty sure there is no such thing as an "instance" of > a report, but I feel that the should be. I report is just a function, > after all. Yeah, a report is just a function, but I think that there may be some re-entrance problems by calling the same report twice. I'm eager for you to try it and share your results. > One sort-of-solution is to generate a single output file, ordered > first by state, with a "skip to top of page" after group of state. > Then I'd have to cut the output file up into pieces, which doesn't seem > entirely easy since there is no knowing how long each piece will be. But, if you think about this a little more, what is the difference between one long report on the printer and 50 short reports on the printer? You still have to seperate the reports whether its from one report process or fifty (unless you're running the report to 50 different printers). If you do the one LONG report, you can put the SKIP TO TOP OF PAGE code in your AFTER GROUP. You can also reset the PAGE variable so that each page starts with Page: 1, and in your HEADER section, you can do something to make it OBVIOUS that the report has changed (a big banner or even a blank page...). [ Yes-this-will-work-but-seems-kind-of-silly-to-me-method deleted :-) ] > I am pretty sure that there is no better way of doing this, but if anyone > can think of one then I'd love to hear it. If you aren't routeing to 50 physically different printers, then I don't really see the difference. If you ARE then another crafty thing is to dump the report to a pipe, and on the other end of the pipe is a shell script that looks through the data for the spooling printer name (which you put into the header or trailer of the report), then it breaks the report up into it's assorted pieces and spools them for you. You just have to put something very DISTINCT in your after group section (like a line that looks like -=-=-=-=- or 0123456789). The script looks for those report delimeters and splits the file. A lot of systems have the 'csplit(1)' command which breaks a file up based on a regular expression. Or you can use 'awk(1)' or 'perl(1)'. One report, one shell script, Voila'! (Of course, you can just save the various pieces if you don't plan on printing it at all) Then there is the third option of putting the START REPORT inside of your FOREACH, and having it finish and start each report and the new state comes up. LET old_state = NULL FOREACH state_curs IF data_rec.state = old_state THEN ELSE IF old_state IS NOT NULL THEN FINISH REPORT state_report END IF LET rpt_file_name = data_rec.state,".dat" START REPORT state_report TO rpt_file_name LET old_state = data_rec.state END IF OUTPUT TO REPORT state_report (data_rec.*) END FOREACH IF old_state IS NOT NULL THEN FINISH REPORT state_report END IF So, it looks like you're pretty well stuck Paul, I can't think of anything that would help. Fun in the sun, Rock and Roll. Luck, Will (villy@collinscomp.com)