Before CSPro logic is compiled, it passes through a preprocessor that allows you to conditionally compile your code based on certain conditions. This is an advanced feature and is primarily useful when using
external logic files where certain functionality may only successfully compile based on characteristics of the application.
The preprocessor uses the language's familiar
if/
elseif/
else/
endif keywords but with four differences:
- The keyword must be preceded by a # character.
- The # must be the first non-whitespace character on the line.
- The whole condition must be specified on a single line.
- A condition should not end with a then keyword.
An
#if and
#endif pair must exist, and optionally
#elseif and
#else can be included as part of a preprocessor block.
The preprocessor is activated before the rest of logic is compiled and thus has limited functionality. Simple math expressions and conditional checks are possible, and there are two functions that can be called as part of conditional checks:
This function returns true if your application is of the type specified by app_type. Supported types are Entry, Batch, and Tabulation.
This function returns true if a symbol exists at compile-time. The function checks for symbols that exist as part of an application (dictionary names, form names, etc.), and not symbols that are created during compilation (user-defined functions, objects, etc.).
Another function can be used to set properties for the application, or for objects:
#setProperty(ʃobject_name,ʅ property_name, property_value);
function string GetEAName(numeric province, numeric district, numeric ea)
string ea_name = maketext("EA %04d-%02d-%03d", province, district, ea);
// if we have access to the geocodes dictionary, add the EA description to the name
#if exists(GEOCODES_DICT)
GEOCODES_PROVINCE = province;
GEOCODES_DISTRICT = district;
GEOCODES_EA = ea;
if loadcase(GEOCODES_DICT, GEOCODES_PROVINCE, GEOCODES_DISTRICT, GEOCODES_EA) then
ea_name = ea_name + " / " + strip(EA_DESCRIPTION));
endif;
#endif
exit ea_name;
end;
function ValidateLiteracy()
if HH_EDUCATION in 3:6 and HH_LITERACY <> 1 then
#if AppType(Entry)
errmsg("Person with education level %d should be literate. Please correct.", HH_EDUCATION);
reenter;
#elseif AppType(Batch)
errmsg("Person with education level %d should be literate. Literacy imputed to 1 (literate).", HH_EDUCATION);
impute(HH_LITERACY, 1);
#endif
endif;
end;