Variable and table sizes from compiler

<< Click to Display Table of Contents >>

Navigation:  Reference > Pre-processor >

Variable and table sizes from compiler

The Pre-processor has a mechanism for referring to the lengths of compiled objects.

VERY IMPORTANT: These functions will not work with PPONLY.

The syntax is:

[*SET index = %ITEMS($svar)]

[*SET index = %ITEMS($mvar)]

[*SET index = %ROWS(#table)]

[*SET index = %COLS(#table)]

These commands set the index to the total number of items in the svar or mvar, or rows or columns in the table not including the total rows or columns.

VERY IMPORTANT: When referring to variables these must exist in the current stage. For example, only variables defined in the manip stage can be referred to in the manip stage.

VERY IMPORTANT: The compiler is always some way behind the pre-processor so great care is needed with these commands. The are two possible problems:

If the *SET command immediately follows the first definition of the variable or table, then the compiler will not have completed the definition before the *SET command is used. This will cause a PP error.

If the *SET command immediately follows a START command then the compiler may be between stages when the *SET is used and the list of variables or tables may not exist.

To avoid these problems you may wish to precede each reference which may cause a problem with the following two lines:

ignore, ignore, ignore, ignore, ignore, ignore, ignore ignore, ignore, ignore, ignore, ignore, ignore, ignore

These commands will have no affect on the run but they should ensure that the compiler has caught up with the pre-processor. For repeated use these two lines should be put in an insert file called Ignore.txt. Each compiler function reference can then be preceded with the insert, for example:

[*insert ignore.txt][*set Length=%rows(#15)]

In practice, simply adding these ignore lines at the beginning of a stage should be sufficient.