EGL Reference Guide for iSeries
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:

- Function functionPartName
... end
- Identifies the part as a function and specifies the part name. For
the rules of naming, see Naming conventions.
- parameterName
- Specifies the name of a parameter, which may be a record or data
item; or an array of records or data items. For rules, see
Naming conventions.
If a given parameter receives data from a variable (not from a constant or
literal), changes to the parameter change the variable in the invoking
function.
A parameter that ends with brackets ([ ]) is a dynamic array, and the other
specifications declare aspects of each element of that array.
- recordPartName (after
parameterName)
- A record part that is visible to the function and that is acting as a
typedef (a model of format) for a parameter. For details on what parts
are visible, see References to parts.
The following statements apply to input or output (I/O) against the
specified record:
- dataItemPartName (after parameterName)
- A dataItem part that is visible to the function and that is acting as a
typedef (a model of format) for a parameter.
- primitiveType (after parameterName)
- The parameter's primitive type.
- length (after parameterName)
- The parameter's length, which is an integer that represents the
number of characters or digits in the memory area referenced by
parameterName.
- decimals (after parameterName)
- For a numeric type (BIN, DECIMAL, NUM, NUMC, or PACF), 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.
- looseType
- A loose type is a special kind of primitive type that is used only for
function parameters. You use this type if you wish the parameter to
accept a range of argument lengths. The benefit is that you can invoke
the function repeatedly and can pass an argument of a different length each
time.
Valid values are as follows:
- CHAR
- DBCHAR
- HEX
- MBCHAR
- NUMBER
- UNICODE
If you wish the parameter to accept a number of any primitive type and
length, specify NUMBER as the loose type. In this case, the number
passed to the parameter must not have any decimal places.
If you wish the parameter to accept a string of a particular primitive type
but any length, specify CHAR, DBCHAR, MBCHAR, HEX, or UNICODE as the loose
type and make sure that the argument is of the corresponding primitive
type.
Loose types are not available in functions that are declared in
libraries.
For details on primitive types, see Primitive
types.
- field
- Indicates that the parameter has form-field attributes such as
blanks or numeric. Those attributes can be tested
in a logical expression.
- nullable
- Indicates the following characteristics of the parameter:
- The parameter can be set to null
- The parameter has access to the state information necessary to test for
truncation or null in a logical expression
The nullable attribute is meaningful only if the argument passed
to the parameter is a structure item in an SQL record. The following
rules apply:
- The parameter can be set to null and tested for null only if the item
property isNullable is set to yes.
- In a Java program, the ability to test for truncation is available
regardless of the value of isNullable. In a COBOL program,
however, the ability to test for truncation is available only if
isNullable is set to yes.
- returns
- Describes the data that the function returns to the invoker. The
characteristics of the return value must match the characteristics of the
variable that receives the value.
- dataItemPartName (after returns)
- 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 (after returns)
- The primitive type of the data returned to the invoker.
- length (after returns)
- 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 (after returns)
- For a numeric type (BIN, DECIMAL, NUM, NUMC, or PACF), 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.
- statement
- An EGL statement, as described in EGL statements.
- variableName
- Specifies the name of a local variable other than a parameter. For
details on variable usage, see References to variables and
constants. For other rules, see Naming
conventions.
- dataItemPartName (after variableName)
- A dataItem part that is visible to the function and that acts as a typedef
for the variable.
- recordPartName (after variableName)
- A record part that is visible to the function and that acts as a typedef
for the variable.
- primitiveType (after variableName)
- The primitive type, if no typedef is in
use.
- length (after variableName)
- The variable's length, which is an integer that represents the
maximum number of characters or digits in the memory area referenced by
variableName.
- decimals (after variableName)
- For a numeric type (BIN, DECIMAL, NUM, NUMC, or PACF), 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.
- constantName literal
- Identifies a constant and the literal that is held by the constant.
The constant is local to the function.
- arrayName
- Name of a dynamic or static array of records or data items. If you
use this option, the other symbols to the right (dataItemPartName,
primitiveType, and so on) refer to each element of the
array.
- size
- Number of elements in a static array.
Related concepts
EGL projects, packages, and files
Function part
Import
Library part
Parts
References to parts
References to variables and constants
Typedef
Related tasks
Syntax diagram
Related reference
Basic record part in EGL source format
EGL source format
EGL statements
Indexed record part in EGL source format
I/O error values
Logical expressions
MQ record part in EGL source format
Naming conventions
Primitive types
Program part in EGL source format
Relative record part in EGL source format
Serial record part in EGL source format
SQL record part in EGL source format
[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.