Title: How can I use the Call/Cancel custom HOOK program to get the start and end time of every CALLed program?

The iscobol.call_cancel.hook runtime property can be used to provide the name of a custom class that will intercept the before and after moments of every CALL and CANCEL statement during a runtime session.
That class would be written as an implementation of the isCOBOL jCallHandler runtime class.

In this KB article we show how to write a class with isCOBOL OOP in order to get the start time and end time of every call, along with a couple of other pieces of information about the execution: the calling program and the called program.
The MYCALLHANDLER class provided with this article is based on the MYCALLHANDLER.cbl provided with the isCOBOL JDK samples and adapted to our goals.

These variables are defined at the OBJECT level to hold the information to be logged.

   WORKING-STORAGE SECTION.
   01  ws-calling-program pic x any length.
   01  ws-start-time      pic 9(8).
   01  ws-end-time        pic 9(8).
Then, the start time will be obtained in the beforeCall method as follows:
   IDENTIFICATION DIVISION.
   METHOD-ID. IS-BEFORECALL AS "beforeCall".
   WORKING-STORAGE SECTION.
   77  obj object reference.
   LINKAGE SECTION.
   77  iscobol-call OBJECT REFERENCE jIscobolCall.
   77  j-lang-object OBJECT REFERENCE JLangObect.
   PROCEDURE DIVISION USING iscobol-call j-lang-object 
                    RAISING jCallOverflowException.
   MAIN.
       set obj to iscobol-call
       if obj:>getClass:>getName:>startsWith("com.iscobol.lib")
       else
          accept ws-start-time from time
          display " " upon sysout
          display "HOOK" upon sysout
          display "before call of " obj:>getClass:>getName 
                                        upon sysout
          display "Start time : " ws-start-time upon sysout
       end-if
       .
   END METHOD.
Later, in the afterCall method we'll get the rest of the information we want as follows:
   IDENTIFICATION DIVISION.
   METHOD-ID. IS-AFTERCALL AS "afterCall".
   WORKING-STORAGE SECTION.
   77  obj object reference.
   LINKAGE SECTION.
   77  iscobol-call OBJECT REFERENCE jIscobolCall.
   77  j-lang-object OBJECT REFERENCE JLangObect.
   PROCEDURE DIVISION USING iscobol-call j-lang-object 
                    RAISING jCallOverflowException.
   MAIN.
       set obj to iscobol-call
       if obj:>getClass:>getName:>startsWith("com.iscobol.lib")
       else
          accept ws-end-time from time
          initialize ws-calling-program 
          call "c$calledby" using ws-calling-program
          display " " upon sysout
          display "HOOK" upon sysout
          display "After call of " obj:>getClass:>getName 
                                        upon sysout
          display "End time : " ws-end-time upon sysout
          display "Called by : " ws-calling-program upon sysout
       end-if
       .
   END METHOD.
Attached is a zip file with the MYCALLHANDLER.cbl, some test programs, the properties file, and 2 batch files.
Use the compile.bat to compile the samples and the run.bat to run them on a command prompt window.

Authored by: Veryant Support on Mon, Jan 11th, 2021 at 7:00 PM
This question has been viewed 1705 times so far.
Online URL: http://support.veryant.com/support/phpkb/question.php?ID=317

Powered by PHPKB Knowledge Base Software