You can declare functions in an EGL source file, as described
in EGL source format.
The following example shows a program part with two embedded functions,
along with a standalone function and a standalone 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
// standalone 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.
- parameter
- A parameter, which is an area of memory that is available throughout the
function and that may receive 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. The return type must be a primitive type.
In
a service, the return type cannot be of type ANY, BLOB, or CLOB.
- { functionProperties }
- The properties and their types are as follows, and each is optional:
- @WSDL
- Is valid only if the function is in a Service part; and is meaningful
only a variable that is based on that Service part is bound to a Web service.
Allows
EGL to extract data from the Web Service Description Language (WSDL) definition
for use in interacting with the Java™ JAX-RPC runtime code. The property
fields and types are as follows:
- elementName STRING
- If this property field is present, the value becomes the name in the WSDL
operation element for the function. If the property field is not present,
the function name is used. The data is case sensitive: for example, the name myFunction is
different from MYFUNCTION.
- nameSpace STRING
- This property field is ignored in the context of a function.
- isLastParamReturnValue BooleanKind
- This property field is ignored in the context of a function.
- alias STRING
- Is valid only if the function is in a library of type nativeLibrary. In
that context, the value is the name of the DLL-based function and defaults
to the EGL function name. Set the aliasproperty
explicitly if a validation error occurs when you name the EGL function with
the name of the DLL-based 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 present with the data at run time.
- 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. The default is no.
This
indicator is for use in code that was migrated from VisualAge® Generator. For details,
see containerContextDependent.