Hi All,
This is just something I noticed in passing (caused me a real headache!), so just throught I'd share it.
I only needed the first 10 or less rows of a table, so
At the end, I checked x to find out how many records were found. If exactly 10 records would be found in the table anyway without the "x = 1 to 10", x would be equal to 10.
It was then that I noticed that if more than 10 records were found (20, 30 etc.), x would be 11. Is it just me, or should x still be 10 regardless if there are more records available?
Example to test:
This is just something I noticed in passing (caused me a real headache!), so just throught I'd share it.
I only needed the first 10 or less rows of a table, so
Code:
for each table
/* where clause */
x = 1 to 10
:
/* do processing */
end.
At the end, I checked x to find out how many records were found. If exactly 10 records would be found in the table anyway without the "x = 1 to 10", x would be equal to 10.
It was then that I noticed that if more than 10 records were found (20, 30 etc.), x would be 11. Is it just me, or should x still be 10 regardless if there are more records available?
Example to test:
Code:
/* setup environment */
def var x as inte.
def temp-table t1
field t1_inte as inte
index t1_io t1_inte
.
/* build temp-table */
do x = 1 to 10
:
create t1. t1_inte = x.
end.
/* example 1 - I expect x to be 10 when foreach is done */
run i-foreach.
display x with frame f_1.
/* add one more entry to temp table */
create t1. t1_inte = 11.
/* example 2 - i stil expect x to be 10, but it isn't... */
run i-foreach.
display x with frame f_2.
/* procedure containing "for each" */
procedure i-foreach
:
for each t1
x = 1 to 10
:
end.
end procedure.