Hi to all,
RHEL 5.6
GDC 2.32.08
$ fglrun -V
fglrun 2.30.06 build-1815.7
Built Dec 1 2010 15:16:07
IDS 11.50.FC7IE
Can I use an array in an AFTER GROUP OF clause in a 4GL style report? My program is substantially more complex then my example below, but I think the example shows the problem. Previously, I had a static number of tran_type(s). I originally used Method 1. Always worked. Now I have an unknown number of tran_type(s). In the real program, I load the array, pa_taxrelieftype, from a table. In the example, I hard code the array. Method 2 uses pa_taxrelieftype[1].tran_type, pa_taxrelieftype[2].tran_type, etc. Not really any better then Method 1. Method 3 is my goal. I want to be able to add a new tran_type record to my table and not need a program change. I want to use a FOR loop. The program compiles without error. I get run time error:
Program stopped at 'test10.4gl', line number 106.
FORMS statement error number -1326.
An array variable has been referenced outside of its specified dimensions.
NOTE: Line 106 is the "format" line in test10_rpt()
When I run it through a debugger, on the first call to "output to report test10_rpt(p_rpt.*)", it does the PAGE HEADER, and then crashes with the above error. It never gets to the ON EVERY ROW or AFTER GROUP OF.
Is this a bug? Should this work? Can I use arrays this way?
Thanks for any help,
David
define
pa_taxrelieftype dynamic array of record
tran_type char(2)
end record,
taxrelieftype_cnt integer
main
defer interrupt
defer quit
call testit()
end main
function testit()
define
p_rpt record
tran_type char(2),
amt integer
end record
close window screen
start report test10_rpt to screen
let pa_taxrelieftype[1].tran_type = "AA"
let pa_taxrelieftype[2].tran_type = "BB"
let pa_taxrelieftype[3].tran_type = "CC"
let p_rpt.tran_type = "AA"
let p_rpt.amt = 10
output to report test10_rpt(p_rpt.*)
let p_rpt.tran_type = "AA"
let p_rpt.amt = 11
output to report test10_rpt(p_rpt.*)
let p_rpt.tran_type = "AA"
let p_rpt.amt = 12
output to report test10_rpt(p_rpt.*)
let p_rpt.tran_type = "BB"
let p_rpt.amt = 20
output to report test10_rpt(p_rpt.*)
let p_rpt.tran_type = "BB"
let p_rpt.amt = 21
output to report test10_rpt(p_rpt.*)
let p_rpt.tran_type = "BB"
let p_rpt.amt = 22
output to report test10_rpt(p_rpt.*)
let p_rpt.tran_type = "CC"
let p_rpt.amt = 30
output to report test10_rpt(p_rpt.*)
let p_rpt.tran_type = "CC"
let p_rpt.amt = 31
output to report test10_rpt(p_rpt.*)
let p_rpt.tran_type = "CCB"
let p_rpt.amt = 32
output to report test10_rpt(p_rpt.*)
finish report test10_rpt
end function
report test10_rpt(p_rpt)
define
p_rpt record
tran_type char(2),
amt integer
end record,
i integer
output
left margin 0
top margin 0
bottom margin 0
page length 60
order external by p_rpt.tran_type
format
page header
print column 1, "Type Amount"
on every row
print column 2, p_rpt.tran_type clipped,
column 10, p_rpt.amt using "###"
after group of p_rpt.tran_type
# Method 1
# Hard code the tran_type
{
if (group count(*) where p_rpt.tran_type = "AA") > 0 then
print column 1, "Total",
column 10, group sum(p_rpt.amt) where p_rpt.tran_type = "AA" using "###"
end if
if (group count(*) where p_rpt.tran_type = "BB") > 0 then
print column 1, "Total",
column 10, group sum(p_rpt.amt) where p_rpt.tran_type = "BB" using "###"
end if
if (group count(*) where p_rpt.tran_type = "CC") > 0 then
print column 1, "Total",
column 10, group sum(p_rpt.amt) where p_rpt.tran_type = "CC" using "###"
end if
}
# Method 2
# Hard code index of pa_taxrelieftype[?].tran_type
{
if (group count(*) where p_rpt.tran_type = pa_taxrelieftype[1].tran_type) > 0 then
print column 1, "Total",
column 10, group sum(p_rpt.amt) where p_rpt.tran_type = pa_taxrelieftype[1].tran_type using "###"
end if
if (group count(*) where p_rpt.tran_type = pa_taxrelieftype[2].tran_type) > 0 then
print column 1, "Total",
column 10, group sum(p_rpt.amt) where p_rpt.tran_type = pa_taxrelieftype[2].tran_type using "###"
end if
if (group count(*) where p_rpt.tran_type = pa_taxrelieftype[3].tran_type) > 0 then
print column 1, "Total",
column 10, group sum(p_rpt.amt) where p_rpt.tran_type = pa_taxrelieftype[3].tran_type using "###"
end if
}
# Method 3
# Use for loop for index of pa_taxrelieftype[?].tran_type
{
$ fglrun test10
Program stopped at 'test10.4gl', line number 106.
FORMS statement error number -1326.
An array variable has been referenced outside of its specified dimensions.
NOTE: Line 106 is the "format" line in test10_rpt()
}
for i = 1 to pa_taxrelieftype.getlength()
if (group count(*) where p_rpt.tran_type = pa_taxrelieftype.tran_type) > 0 then
print column 1, "Total",
column 10, group sum(p_rpt.amt) where p_rpt.tran_type = pa_taxrelieftype.tran_type using "###"
end if
end for
skip 1 line
end report