We are trying to write a loop macro with a break function. Basically we would like to repeat a certain action until X (derived from a Dataset) is true. The compiler doesn't seem to like this approach however (returns 'Constant expression expected') so we were wondering if there is a known workaround?
An entirely artificial example is provided below, called by:
LoopFunction(5);
from a BWR window.
EXPORT LoopFunction(NMax = 5) := MACRO
Rec := RECORD
INTEGER i;
END;
#DECLARE(i);
OUTPUT(DATASET([1], REC), ,'~TEMP::MB::LOOPTEST' + %i%, COMPRESSED, OVERWRITE);
#SET(i, 2);
shouldIbreak := DATASET('~TEMP::MB::LOOPTEST' + (%i% - 1), Rec, THOR);
#LOOP
OUTPUT(shouldIbreak +DATASET([%i%], REC), ,'~TEMP::MB::LOOPTEST' + %i%, COMPRESSED, OVERWRITE);
#SET (i, %i%+1);
#IF (COUNT(shouldIbreak) > Nmax);
#BREAK
#END
#END
ENDMACRO;
This is possible using the LOOP() command, you may specify a break condition there. See the (mediocre) documentation here and a blog post here