4

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;
tjati
  • 5,761
  • 4
  • 41
  • 56
DataMacGyver
  • 386
  • 3
  • 10

2 Answers2

2

You cannot have runtime dependencies (e.g. a dataset loaded from a logical file) on template language code, since the template language directives are processed by the compiler, with the intent of generating ECL code.

You can use datasets, but only if they are constant expressions (e.g. an inline dataset).

Think of Template Language as macros in C. If you really need to generate code based on runtime dependencies, what you can do as a workaround is writing a function that generates a STRING with your code and then submit it to the cluster using a SOAPCALL.

Lucas Barbosa
  • 173
  • 2
  • 8
1

This is possible using the LOOP() command, you may specify a break condition there. See the (mediocre) documentation here and a blog post here

DataMacGyver
  • 386
  • 3
  • 10