Declare Function

Mon 01 January 2018

Syntax

PeopleCode Function Syntax

Declare Function function_name PeopleCode record_name.field_name event_type

External Library Function Syntax

Declare Function function_name Library lib_name
    [Alias module_name]
    [paramlist]
    [Returns ext_return_type [As pc_type]]

In which paramlist is:

([ext_param1 [, ext_param2] . . .)

And in which ext_param1 , ext_param2 , and so on is:

ext_datatype [{Ref|Value}] [As pc_return_type]

Description

PeopleCode can call PeopleCode functions defined in any field on any record definition. You can create special record definitions whose sole purpose is to serve as function libraries. By convention, PeopleCode functions are stored in FieldFormula PeopleCode, in record definitions with names beginning in FUNCLIB_.

PeopleCode can also call external programs that reside in dynamic link libraries. You must declare either of these types of functions at the top of the calling program using the Declare Function statement.

To support processes running on an application server, you can declare and call functions compiled in dynamic link libraries on windows (*.DLL files) and shared libraries on UNIX (lib*.so files.) The PeopleCode declaration and function call syntax is the same regardless of platform, but UNIX libraries must be compiled with an interface function.

See .

Parameters

The following are the parameters for the PeopleCode function syntax:

Field or Control

Definition

function_name

Name of the function.

PeopleCode

Reserved word that identifies the function as a PeopleCode function.

recordname.fieldname

Specifies the record and field where the function is located.

event_type

Component Processor event with which the function is associated.

Note: event_type can be used to specify record field events only. You can’t specify a component record field event, a component record event, and so on.

The following are the parameters for the external library function syntax:

Field or Control

Definition

function_name

Name of the function.

Library

Reserved word that identifies the function as an external library function.

lib_name

A string representing the name of the external library. The external routine must be located in a DLL named lib_name accessible by Windows, or an equivalent shared library in a UNIX system.

Alias   module_name

Optionally specifies the name of the function’s entry point within the shared library. This is needed only if the C function name differs from function_name in the PeopleCode external function declaration. The external module is invoked using the __stdcall calling convention on Windows.

paramlist

List of parameters expected by the function, each in the form:

ext_datatype [{ Ref | Value }] [ As   pc_type ]

ext_datatype

The data type of the parameter expected by the function. To specify the type you can use any of the following:

  • BOOLEAN

  • INTEGER

  • LONG

  • UINTEGER

  • ULONG

  • STRING

  • STRING

  • FLOAT

  • DOUBLE

Ref | Value

Optionally use one of these two reserved words to specify whether the parameter is passed by reference or by value. If Ref is specified, it is passed by pushing a reference (pointer) on the stack. If Value is specified the value is pushed on the stack (for integers, and so on.) If neither is specified, Ref is assumed.

As   pc_type

Specifies PeopleCode data type of the value passed to the function. You can choose between PeopleCode data types String, Number, Integer, Float, Date, Boolean, and Any.

Returns   ext_return_type

Specifies the data type of any value returned by the function. The Returns clause is omitted if the function is void (returns no value.) To specify the return type you can use any of the following:

  • BOOLEAN

  • INTEGER

  • LONG

  • UINTEGER

  • ULONG

  • FLOAT

  • DOUBLE

The types String and LString are not allowed for the result type of a function.

As   pc_return_type

Specifies the PeopleCode data type of the variable or field into which to read the returned value. You can choose between PeopleCode data types String, Number, Integer, Float, Date, Boolean, and Any. If the As clause is omitted, PeopleTools selects an appropriate type based on the type of value returned by the external function (for example, all integer and floating point types are converted to Number).