Anyone notice that simply referencing (not assigning values to) a field name in an empty datasource stack changes FocCount from 0 to 1? For example, if I have a datasource stack, stkABC and my code does the following:
stack clear stkABC;
reposition datasource1.SEGNAME.KEY_FIELD;
for all next KEY_FIELD into stkABC where KEY_FIELD eq "some value";
Let's say this returned 0 records so stkABC is still empty and FocCount should still be zero.
Then I do this:
Compute Var1 = stkABC().KEY_FIELD;
I guess Var1 would be assigned NULL or "" or something. Not sure since if I do a:
Type "Var1 = " Var1; in my code it just prints:
Var =
Anyway, after this I want to check the FocCount of stkABC in an IF statement to either do something or not, for example:
if stkABC.FocCount eq 0 then
form1.Button1.enabled = 0;
else
form1.Button1.enabled = 1;
Problem is this IF statement will evaluate as false because after the Compute statement that referenced stkABC().KEY_FIELD, stkABC.FocCount now equals 1 not 0, even though I know that stkABC is actually empty (or is it actually not?).
I know I can work around this by checking to see if stkABC.FocCount is 0, and if it is, not executing any code that even just references stkABC or stkABC() or stkABC(row number) if I want to intentionally keep stkABC.FocCount at 0 when stkABC is empty.
The dynamic behavior of stacks in the Maintain language is really helpful but it would nice if the manuals made it clear that just referencing an empty stack or field in an empty datasource stack either changes just the FocCount of that stack from 0 to 1 or actually creates a row in that stack and changes FocCount. It would have saved me a few hours of debugging.
I guess I would think that unless an empty stack is referenced on the left side of an assignment statement, the stack should remain empty and the FocCount of that stack should remain at 0. If it's referenced on the right side of an assignment statement, that should not affect the stack in any way.
Just curious on other peoples' thoughts on this.
FOCUS 7.7.03
WebFOCUS 8.0.x/8.1
z/OS, Windows