ENT 

Invoking User-Defined Functions

User-defined functions may be invoked in most places that intrinsic functions may be invoked.

If you are invoking a user-defined functions without using the FUNCTION keyword, its name must be specified in the REPOSITORY paragraph.

The following example shows a compilation group containing a user-defined function definition called usedef and a program containing the function invocation:

       Identification division.
       Function-id. usedef.
       Data division.
       Linkage section.
       01 Bal pic 999v999.
       01 Spend pic 999v999.
       01 res pic 999v999.
       Procedure division
              using Bal Spend
              returning res.
              compute res = Bal - Spend
              goback.
       End function usedef.
       Identification division.
       Program-id. 'caller'.
       Environment division.
       Configuration section.
       Data division.
       Working-storage section.
       01 result pic 999v999 usage display.
       01 dis-res pic 999v999.
       Procedure division.
           compute result = function usedef(10 9.99).
           move result to dis-res.
           display "Current balance = " dis-res.
           goback.
       End program 'caller'.

After compilation, and running the 'caller' program, the output is as follows:

Current balance = 000.010