Previous Topic: Invoking a FunctionNext Topic: Writing External Functions as CA ADS Mapless Dialogs


Writing an External Function in COBOL, PL/I, or Assembler

You can write the program associated with a function in COBOL, PL/I or Assembler. This requires the function to be defined with PROTOCOL IDMS. When called, the program is passed a fixed parameter list consisting of the parameters specified in the function definition, as well as additional parameters used for communication between CA IDMS and the function.

Whenever a function is invoked, CA IDMS calls the program associated with the function to service the request. The function responds by processing the input parameters. An error condition can optionally be set in SQLSTATE.

CA IDMS performs transaction and session management automatically in response to requests that the originating application issues. Changes to the database made by a function are committed or rolled out together with other changes made within the SQL transaction. No special action is required of the function in order to ensure that this occurs.

The next section discusses writing a function in detail.

For an example of a function written in COBOL, see Sample COBOL Function.

Calling Arguments

The following sets of arguments are passed when a function is called:

Argument

Contents

Result Indicator (fullword)

Not used

SQLSTATE (CHAR (5))

Status code returned by the procedure:

The initial value is always 00000

00000 Indicates success

01Hxx Indicates a warning

02000 Indicates no more rows

38xxx Indicates an error

Function Name (CHAR (18))

Name of the function

Explicit Name

Not used

Message Text (CHAR (80))

Message text returned by the function and displayed by CA IDMS in the event of an error or warning

SQL Command Code (fullword)

Always 16, indicating a Fetch SQL request

SQL Operation Code (fullword)

Always 16, indicating a "next row" request

Instance Identifier (fullword)

Not meaningful for functions

Local Work Area (user-defined)

A user-defined working storage area

Global Work Area (user-defined)

A user-defined storage area that can be shared by other SQL routines within a transaction.

Parameter Arguments

On entry to the program associated with a function, the value of the arguments corresponding to the parameters defined in the CREATE FUNCTION statement are as follows:

On exit, the program associated with the function is expected either to have set the value of the parameter USER_FUNC, holding the functions return value and the corresponding indicator appropriately, or to have set an SQLSTATE value indicating no-more-rows. If the indicator parameter is set to -1, CA IDMS ignores the value of the USER_FUNC parameter.

Local Work Area

Another parameter passed on each call to a function is a local work area.

CA IDMS allocates the local work area just before calling the function and frees it immediately after the function exits. When the local work area is allocated, it is initialized to binary zeros.

Global Work Area

A global work area is a storage area that can be shared across one or more functions or other SQL routines within a transaction. Each global work area has an associated key that is one of the following:

All SQL routines executing within a transaction and having the same global storage key share the same global work area.