SNIPPET - FUNCTION

The FUNCTION command declares a section of code that can be re-used multiple times later on or in separate places within the script. The syntax is as follows:

FUNCTION <name>([<parameter>[,<parameter>][...])
{
  <commands to perform>
  [ RETURN <value> ]
}

The <name> is the name of the function which can be referenced in other areas of the SNIPPET or even external to the SNIPPET. Inside parenthesis is a list of zero or more parameters separated by a comma. These are simply names which are used to reference data that is passed by the caller. RETURN is an optional command which can send data back to the caller.

When the FUNCTION command is used, it simply declares a re-usable block of code. It does not execute that block. In order to execute the block, the function must be called.

Here is an example of a FUNCTION which will obfuscate a string of numbers:

FUNCTION encrypt(p1)

{

  ASSIGN cipher="1,9,2,7,8,3,6,4,5"

  ASSIGN carray="{cipher.split(',')}"

  ASSIGN rtn=""

  FOR i = 1 to carray.size

  {

    ASSIGN idx=carray[i]

    ASSIGN rtn="{rtn}{p1.mid(idx,1)}"

  }

}

Using the function is discussed in the next section. The above example expects an input string of 9 digits or less. It will create a new variable called RTN that will contain the obfuscated string of digits.