Search code examples
cobol

Cobol pass function / lang features


Does COBOL support sending a function by reference to a function as a parameter?

I've only looked at a few tutorials at this stage. And Just trying to get an idea of what can be achieve easily. I.E. what knowledge that can be transferred over from other languages.


Solution

  • Does COBOL support sending a function by reference to a function as a parameter?

    "Yes".

    77 FUNC-PTR  USAGE FUNCTION-POINTER.
    SET FUNC-PTR TO ADDRESS OF FUNCTION SOME-FUNC
    

    The reason for setting that into quotes:

    • USAGE FUNCTION-POINTER was introduced in COBOL 2014, so it may not be available with a specific implementation of the language
    • What many other programming languages define as "function" is commonly seen as a PROGRAM in COBOL. You could consider this, too. COBOL 2002 added something that is relative commonly available (it existed as an extension before)
    77 PROG-PTR  USAGE PROGRAM-POINTER.
    SET PROG-PTR TO ADDRESS OF PROGRAM "MYPROG"
    SET PROG-PTR TO ADDRESS OF ENTRY   "MYENTRY"