Function part in EGL source format

You can declare functions in an EGL file, as described in EGL source format.

The following example shows a program part with two embedded functions, along with a stand-alone function and a stand-alone record part:

  Program myProgram(employeeNum INT) 
    {includeReferencedFunctions = yes}

    // program-global variable
      employees record_ws;
      employeeName char(20);

    // a required embedded function
    Function main() 

      // initialize employee names
      recd_init();

      // get the correct employee name
      // based on the employeeNum passed
      employeeName = getEmployeeName(employeeNum);
    end

    // another embedded function
    Function recd_init()
      employees.name[1] = "Employee 1";
      employees.name[2] = "Employee 2";
    end
  end

  // stand-alone function
  Function getEmployeeName(employeeNum INT) returns (CHAR(20))

    // local variable
    index BIN(4);
    index = syslib.size(employees.name);
    if (employeeNum > index)
      return("Error");
    else
      return(employees.name[employeeNum]);
    end

  end

  // record part that acts as a typeDef for employees
  Record record_ws type basicRecord
    10 name CHAR(20)[2];
  end

The syntax diagram for a function part is as follows:


Syntax diagram for a function part

Function functionPartName ... end

Identifies the part as a function and specifies the part name. For the rules of naming, see Naming conventions.

parameter

A parameter, which is an area of memory that is available throughout the function and that receives a value from the invoking function. For details on the syntax used to declare a parameter, see Function parameters.

returns (returnType)

Describes the data that the function returns to the invoker. The characteristics of the return type must match the characteristics of the variable that receives the value in the invoking function.

dataItemPartName

A dataItem part that is visible to the function and that is acting as a typedef (a model of format) for the return value.

primitiveType

The primitive type of the data returned to the invoker.

length

The length of the data returned to the invoker. The length is an integer that represents the number of characters or digits in the returned value.

decimals

For some numeric types, you may specify decimals, which is an integer that represents the number of places after the decimal point. The maximum number of decimal positions is the smaller of two numbers: 18 or the number of digits declared as length. The decimal point is not stored with the data.

"dateTimeMask"

For TIMESTAMP and INTERVAL types, you may specify "dateTimeMask", which assigns a meaning (such as "year digit") to a given position in the datetime value. The mask is not stored with the data.

statement

An EGL statement, as described in EGL statements. Most end with a semicolon.

variableDeclaration

A variable declaration, as described in Function variables.

containerContextDependent

An indication of whether to extend the namespace used to resolve the functions that are invoked by the function being declared.

This indicator is for use in code that was migrated from VisualAge Generator. For details, see containerContextDependent.

Related concepts
EGL projects, packages, and files
Function part
Import
Library part
Parts
References to parts
References to variables and constants
Syntax diagram
Typedef

Related reference
Arrays
containerContextDependent
EGL statements
Function variables
Function parameters
INTERVAL
I/O error values
Naming conventions
Primitive types
TIMESTAMP