Skip to content

TypeCobolFunctions

Olivier Smedile edited this page Jun 28, 2016 · 21 revisions

Functions

Format : function

FUNCTION function-name (parameters)

This syntax is the same as the syntax for COBOL intrinsic functions and can be used in the same contexts (in particular as part of any statement where an intrinsic function would be acceptable).

Definition

A function is defined by:

  • its function name
  • its library
  • its list of input parameters, each parameter being defined by:
    • its type or format
  • One returning parameter, being defined by:
    • its type or format

Parameters

A function can have any number of parameters. Each parameter can be of any type (either from COBOL or a custom defined type). A parameter is always an input parameter: it is written by the caller but read-only for the callee

Return code

Each function should have the return code as an output parameter. Note that TypeCobol doesn't enforce that.

« Intrinsic » functions

TypeCobol will provide native functions included directly in our Library. These are called "TypeCobol intrinsic fucnctions".

Libraries

Functions are grouped in libraries.

Usage

You can pass any data to a function, provided each data is of the type expected by the function definition. You can pass identifiers or directly literals with no particular concern. If a function needs more than one parameter, you need to separate parameters with commas (,).

Implied parameters

If the method implementation allows it, you can imply some parameters you don't want to bother with. To do this, you just have to put nothing between the parameters separators.

Examples

To imply the third parameter of a call to fun, a four-parameters function:

FUNCTION fun(param1, param2, , param4)

To imply the second and third parameters of a call to fun2, a three-parameters function, you could write any of the following:

FUNCTION fun2(param1)
FUNCTION fun2(param1, , )
FUNCTION fun2(param1, )

« Intrinsic » functions

Once defined, a custom function which has only one output parameter (in addition to its return code) can be used the same way a COBOL intrinsic function would be. For example, the following would be perfectly valid:

MOVE FUNCTION SOFUN(myVar1, 'literal', , myVar4) TO myResultVar.

Other custom functions

TODO

Code generation

TODO

Clone this wiki locally