Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The include statement allows you to execute code and use UDRs  that are written in other SIL™ files. This can improve readability and make your code more manageable.

Tip

You can use the include statement to import entire libraries of UDRs.

Syntax

include "path/to/file.incl";

Include statements must be the first statements in your program, before the definition of UDRs.

Info

For more information see  Structure of a SIL™ program.

The provided path may be relative or absolute. If relative, it is resolved relative to the defined 'sil.home' environment variable, usually the 'silprograms' directory.

Variable Visibility

There are two categories of variables you can use in the included programs.

Local Variables

These are the variables you define in the body of the included program. These can be used throughout the included program, as well as in your SIL™ program that included the file.

file.incl
Code Block
function increment(int x) {
  return x + 1;
}
number a = increment(0);
program.sil
Code Block
include "file.incl"; //resolved relative to the 'sil.home'

number b = a + increment(2); //we can use the 'a' variable here!

Notice the use of variable a in the SIL™ program even though it was declared in the included file. Also notice the use of the increment() UDR that was defined in the included file as well.

Global Variables

These are the variables that are already defined and can be used right away (issue fields and customfields). You can use these anywhere in your code without having to declare them.

file.incl
Code Block
function getKey() {
  return key;
}

Header Guards

New to Power Script 5.8.x, header guards protect your scripts from scenarios where through nested include files the same file might accidentally (or intentionally) have been included more than once.

In the image above we can see that both include file A and include file B are using include file C. Perhaps include file C was a collection of helpful functions that could be reused in both file A and file B. Without header guards file C would need to be removed from one of the other files, A or B, otherwise there would be an error. Now, with header guards, the first occurrence of the include files will be loaded and subsequent occurrences will be ignored.

See also

Contents

Table of Contents