RETURN within REPORT (was: Do you need a "on every row")
Posted in 1993
The recent discussion about forcing at least one page from a report that receives no data caused me to make another attempt at finding a general solution to the problem. I've used various approaches in the past, usually some form of the method where you set one of the data elements being sent to the report to a special "flag" value to indicate "no data found." However, I've never been completely happy with this scheme for several reasons. I have recently been thinking about using a method, demonstrated in the test program below, that depends on using a RETURN statement within a REPORT module, as in Line 70 of the program. One reason I like this method is because it would be easier than some others to retrofit into existing programs. I couldn't find any specific mention of *not* using RETURN inside REPORTs in the manuals, so I just tried it and it worked, at least in I4GL 4.11.UC1 under SunOS 4.1.3. I thought it might since we use c4gl, which implements REPORTs as C functions. Before I get more involved with this approach, such as deciding how to handle GROUP clauses, I'd like to know if anyone can see any problems with it. Does this also work in RDS? Is RETURN within REPORT just a currently untrapped keyword that happens to work in C, or is the connection between REPORTs and functions fundamental enough to 4GL that this is likely to continue to work? Any thoughts would be appreciated. Thanks, Walt. ------------------------------------------------------------------------------ 1 { rpt.4gl } 2 3 { 4 Usage: rpt 1 4 # to simulate data found 5 rpt 4 1 # to simulate data not found 6 7 8 This program tests a method of reporting that no data was found 9 that satisfied selection criteria for a 4GL report. 10 } 11 12 13 main 14 15 define ifrom smallint, 16 ito smallint, 17 18 i smallint, 19 data_flag smallint 20 21 let ifrom = arg_val(1) # get command line arguments 22 let ito = arg_val(2) 23 24 let data_flag = FALSE # initialize "data found" flag 25 26 start report rpt 27 28 for i = ifrom to ito # generate simulated report data 29 30 let data_flag = TRUE # indicate data found 31 32 output to report rpt ( i, data_flag ) 33 34 end for 35 36 if ( not data_flag ) # send special record to report if no data 37 then 38 output to report rpt ( i, data_flag ) 39 end if 40 41 finish report rpt 42 43 end main 44 45 report rpt ( r_i, r_data_flag ) 46 47 define 48 49 r_i smallint, 50 r_data_flag smallint 51 52 output 53 54 page length 10 55 top margin 1 56 bottom margin 1 57 58 format 59 60 page header 61 62 print "Page Header" 63 skip 1 line 64 65 on every row 66 67 if ( not r_data_flag ) # if this is special "no data found" 68 then # record, print message and return 69 print "No data found" 70 return 71 end if 72 73 print r_i 74 75 page trailer 76 77 skip 1 line 78 print "Page Trailer" 79 80 end report ------------------------------------------------------------------------------ -- Walt Hultgren Internet: walt@rmy.emory.edu (IP 128.140.8.1) Emory University UUCP: {...,gatech,rutgers,uunet}!emory!rmy!walt 954 Gatewood Road, NE BITNET: walt@EMORY Atlanta, GA 30329 USA Voice: +1 404 727 0648