Calling Scripts with FPL

Documentation home 

 

Introduction. 1

Callscript parameters 1

Script in parameters 2

Passed Tables 2

 

See also:   local variables, local tables      

Introduction

The callscript FPL command can be used to call from one script to another, optionally passing parameters. Scripts written in any programming language can be called, but parameters can only be passed to scripts written in FPL.

 

In order to receive incoming parameters, the called FPL script must have a script statement as its first statement as shown below:

 

Calling script SCRIPT1:

 

..

..

callscript SCRIPT2(var1, var2, table1);

 

 

Called script SCRIPT2:

 

script(char v1, int v2, table t1)

..

..  

 

It is important to understand that all parameters are passed by reference; this means that changes made to any of these parameters in a called script are reflected back to the calling script. For example, if variable v1 in the example above is changed in SCRIPT2, then variable var1 in SCRIPT1 will also change. In practice, both of these variables reference the same underlying object. This is true for all passed parameters including tables.

Callscript parameters

The following can be included as parameters on a callscript statement:

 

Examples:

callscript ABC_1(char_field1, int_field2, date_field3);

callscript ABC_1('A string literal', 25, $SYSTEM_DATE);

callscript ABC_1(null, null, $SYSTEM_DATE);

callscript ABC_2(CUSTOMERS_TABLE);

Script in parameters

On a script statement, the in parameters are defined as pairs of parameter type and parameter name with each pair delimited by a comma. Parameter types can be any local variable type or TABLE.

 

Examples:

script(char c1, int i1, date d1)

script(table tab1)

script()

 

The following are the rules for matching callscript parameters with script in parameters:

 

All script in parameters are treated as local variables or local tables in the called script.

Passed Tables

When a table is received, the column names from the calling script are automatically passed and can be used in the called script. The table prefix however changes to the table name defined on the table in parameter. This is illustrated in the following example where SCRIPT1 defines a table table1 which is then passed to SCRIPT2 where it is referred to as tab2;

 

Calling script SCRIPT1:

 

table table1 char col1;

// insert 2 rows

insertrow table1;

table1-col1 = 'Row 1';

insertrow table1;

table1-col1 = 'Row 1';

// call SCRIPT2 passing the table

callscript SCRIPT2(table1);

 

Called script SCRIPT2:

 

script(table tab2)

loop at tab2

  log tab2-col1;

endloop  

 

When a table in parameter is missing or is passed as null, then any reference to the table or any one of its columns will fail at runtime.