Please enable JavaScript to view this site.

One common use for conditional compilation statement is to prevent a common include file—which may be referenced by multiple modules—from being processed more than once. You can also use ++INCLUDE'ONCE (see One-Time ++INCLUDES) but that depends on consistent use through all the code which may reference an include file. Adding conditionals within the include file itself can prevent the problem of duplicate includes without requiring any cooperation on the part of any external modules.

A common approach to protecting against duplicate include processing is to define a special symbol that indicates that the module has already been included, and then add a conditional which prevents processing of the module if the symbol has already been defined. For example:

! MYMODULE.BSI

 

++IFNDEF INC_MYMODULE_BSI_

DEFINE INC_MYMODULE_BSI_ 1

 

    <contents of the module>

 

++ENDIF

 

In the above example, the first time the compiler sees the code, the symbol INC_MYMODULE_BSI_ will not have been defined, so it proceeds to process the module (including defining the symbol). On subsequent passes through this module, the symbol will have been defined, so the conditional will cause the module contents to be skipped.

For modules that define symbols or structures, you may avoid the need to define an artificial symbol just to track whether the module has been compiled, by referencing one of the DEFINE or DEFSTRUCT symbols in the file, i.e

++IFNDEF ST_CUSTOMER

    ...

    DEFSTRUCT ST_CUSTOMER

        MAP2 ...

    ...

    ENDSTRUCT

    ...

++ENDIF

 

Similarly, if the module maps variables or defines any labels or functions/procedures, you can use ++IFNMAP <variable> or ++INFNLBL <label>, for example:

++IFNMAP MYMODULE'VARS

    ...

    MAP1 MYMODULE'VARS

        MAP2 ...

    ...

++ENDIF

 

Note that in the above case, the variable referenced in the ++IFNMAP must have global (not private or local) scope. See ++IFMAP, ++IFNMAP, ++ELIFMAP .

Or, to use the same idea but with a label or procedure name instead of a variable:

++IFNLBL MyProc()

    ...

Procedure MyProc()

    ...

   EndProcedure

    ...

++ENDIF

 

See Also

History

2014 March, A-Shell 6.1.1382 (Compiler edit 655):  Add ++IFLBL, ++ELIFLBL, ++IFNLBL

Created with Help+Manual 9 and styled with Premium Pack Version 5 © by EC Software