Function prototype with external name
Occasionally, it might be desirable to have the compiler generate code for invocations to function prototypes whose name either cannot be expressed as a COBOL word, or whose name might have restrictions or requirements in the external operating environment. In such cases you can code the AS external-name phrase on the FUNCTION-ID paragraph of the function prototype definition to provide the externalized name.
About this task
For example, you can name your function prototype "GetRecord", but have invocations of
"GetRecord" actually invoke a function whose external name in your operating environment is
"QQGETREC". To do this, you can code as
follows:
Identification division.
Function-id. GetRecord as 'QQGETREC' is prototype.
Data division.
Linkage section.
1 retval pic x(100).
Procedure division returning retval.
End function GetRecord.
**********************************
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.
"GetRecord" might then be defined in another batch compilation as the following user-defined
function:
Identification division.
Function-id. GetRecord as 'QQGETREC'.
Data division.
Linkage section.
1 retval pic x(100).
Procedure division returning retval.
move "data" to retval
goback.
End function GetRecord.
Suppose instead of "QQGETREC", you choose "abc123Get_Customer_Record". To use this external name,
you need to use either the PGMNAME compiler option or the ENTRY-NAME phrase of the
FUNCTION-ID paragraph as in the following
example:
Identification division.
Function-id. GetRecord as 'abc123Get_Customer_Record' is prototype
entry-name is longmixed.
Data division.
Linkage section.
1 retval pic x(100).
Procedure division returning retval.
End function GetRecord.
**********************************
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.