Start of change

Function prototype best practices

It is recommended that function prototypes be defined in copybooks and included into the compilation groups that reference them using the COPY statement. This practice ensures that prototype definitions across the application are the same. Furthermore, it is also recommended that the function prototype definition be included via COPY in the same compilation group as the user-defined function definition to allow the compiler to check for consistency.

For example, this function prototype is placed in a copybook called GETREC.
       Identification division.
         Function-id. GetRecord is prototype.
       Data division.
        Linkage section.
         1 retval pic x(100).
       Procedure division returning retval.
       End function GetRecord.
This copybook is included along with the user-defined function definition in another compilation group.
       Copy GETREC.
       Identification division.
         Function-id. GetRecord.
       Data division.
        Linkage section.
         1 retval pic x(100).
       Procedure division returning retval.
           move "data" to retval
           goback.
       End function GetRecord.
The copybook is also included in any compilation group where "GetRecord" is invoked.
       Copy GETREC.
       Identification division.
         Program-id. myprog.
       Data division.
        Working-storage section.
         1 a pic x(100).
       Procedure division.
           move function GetRecord to a
           goback.
       End program myprog.
End of change