Coding user-defined function definitions

User-defined functions must contain the FUNCTION-ID paragraph within the IDENTIFICATION DIVISION. The END FUNCTION keyword indicates the end of a user-defined function definition. User-defined functions must contain the RETURNING phrase of the PROCEDURE DIVISION header to indicate the returning item of the function.

About this task

Zero or more parameters for user-defined functions may appear in the USING phrase of the PROCEDURE DIVISION header. Parameters may be passed BY REFERENCE or BY VALUE.

The following example shows a user-defined function definition called "docalc":
   Identification division.
     Function-id. docalc.
   Data division.
    Linkage section.
     1 kind pic x(3).
     1 argA pic 999.
     1 argB pic v999.
     1 res pic 999v999.
   Procedure division
       using by reference kind argA argB
       returning res.
       if kind equal "add" then
         compute res = argA + argB
       end-if
       goback.
   End function docalc.

Related references  
FUNCTION-ID paragraph (Enterprise COBOL for z/OS® Language Reference)