support: Customer Portal
Focused on delivering choice, investment protection and flexibility to organizations with valuable COBOL assets
 

Veryant Knowledge Base
Home > All Categories > isCOBOL General > Deployment > How can I use the Call/Cancel custom HOOK program to get the start and end time of every CALLed program?
Question 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 This question has been viewed 32 times so far.
Click Here to View all the questions in Deployment category.
File Attachments File Attachments
How helpful was this article to you?
User Comments User Comments Add Comment
There are no user comments for this question. Be the first to post a comment. Click Here
Related Questions Related Questions
  1. Did you know you can create temporary files in memory?
  2. What are the minimum files I need for a runtime-only installation? How do I create a launcher?
  3. How can I encode a URL String?
  4. Working with sequential files on Pipes
  5. Did you know isCOBOL IDE allows you to easily understand how to invoke a method in a Java Class?
  6. What can I use to perform an email validation during entry-field accept?
  7. How do I generate an executable for deployment?
  8. How do I create an installation package for my COBOL application?
  9. Is there a way to to emulate the W$GETC routine?
  10. Did you know isCOBOL IDE allows you to easily understand how to invoke a method in a Java Class?
  11. Did you know you could choose from different languages for isCOBOL message?
  12. Did you know you could set a background image from isCOBOL IDE's painter?
  13. How can I read data correctly from a line-sequential file that has a different encoding from the one used by isCOBOL?
  14. Did you know these two ways of finding out the working directory in use?
  15. Can I mix versions of Java, isCOBOL compiler and isCOBOL runtime?
  16. How can I read a data written with a different encoding?
  17. How can I tell if my application is running in the WebClient environment or another environment?
Article Information Additional Information
Article Number: 317
Created: 2021-01-11 4:23 AM
Rating: No Rating
 
Article Options Article Options
Print Question Print this Question
Email Question Email Question to Friend
Export to Adobe PDF Export to PDF File
Export to MS Word Export to MS Word
Bookmark Article
Subscribe to Article Subscribe to Article
 
Search Knowledge Base Search Knowledge Base



 
 

© Veryant - All Rights Reserved
Veryant and isCOBOL are trademarks or registered marks of Veryant in the United States and other countries. All other marks are the property of their respective owners.