# Using Variables

Inaportprovides functions that allow the use of variables in your expressions. Variables allow you to store information or the results of calculations for use later on:

- store the variable to disk, and allow it to be used in another import operation altogether (global variables)
- later in the same import session (session variables)

- later in the processing of the same record (record variables)

A particularly powerful feature is the use of global variables in SQL SELECT statements (see Using Global Variables in SQL for further information).

Variables can also be passed in the command line when invoking Inaport. this allows you to pass values when running an import as an external process. See notes below on how to set variables from the command line.

### Variable Lifetime

The major difference between variables is how long they are available for:

- A record variable is only available during the import of ONE record. When that record is processed, all record variables are discarded, and new variables created for the next record
- A session variable is available for the entire import operation: a session variable created with the first record is read can be used with the last record
- A global variable is written to disk at the end of the session, and is then available in another, separate import operation. Global variables can be inspected in the Tools - Options - Global Variables dialog box, and can be created or edited using this interface.

### Variable Types

The type of the variable can be:

- string - any sequence of characters e.g. "abcd", "Mr John Smith", "pc1234-45/12"
- number - an integer or floating point number e.g. 123, 123.456, 123,456.654
- date - will record the full date and time supplied e.g. "12/13/01 12:33:45"
- boolean - a true or false that can be used in tests

### Creating a variable

You can use the variable functions to create a variable and store a value into it:

- record variables: recstr("rStringVar", "this is a record string"); recnum("rNumVar", 123.45);
  recbool("rBoolVar", 1 = 2); recdate("rDate", date());
- session variables: sesstr("sStringVar", "this is a session string"); sesnum("sNumVar", 456);
  sesbool("sBoolVar", 1 = 1); sesdate("sDate", date());
- global variables: glostr("gStringVar", "this is a global string"); glonum("gNumVar", 123.45);
  globool("gBoolVar", 1 <> 2); glodate("gDate", date())

### Using a Variable

Once a variable has been created, you can use it in any expression you wish. Calling the function with just the name of the variable will return the value stored:

- sesnum("sNumVar") + 123
  will give 579 (which is 123 + 456)
- glostr("gStringVar") + " with more"
  will give "this is a global string with more"
- iif(recbool("rBoolVar"), "var was true", "var was false")
  will give "var was false"

###

### Setting variables from the command line

Setting variables from the command line is a particularly powerful feature, as it allows you to pass values to Inaport - which can then be used in SQL SELECT statements to query the data source.

The syntax for using command line variables is:

-svarName:varValue creates or sets the value of a global string variable
-nvarName:1234 creates or sets the value of a global number variable
-bvarName:true creates or sets the value of a global boolean variable

Below are some example command lines, to run the import setup "test.ipi" with different variables:

inaport -sMyName:David test.ipi - sets the string variable "MyName" with the value "David"

inaport -nlastInvNo:1234 test.ipi - sets the number variable "lastInvNo" with the value 1234

inaport -bmyTest:true test.ipi - sets the boolean variable "myTest" to the value "true"