Skip to main content

Problem:

Attempting to get the full path/file name of a program that is CALLING the current program by calling the CBL_GET_PROGRAM_INFO routine using call-function 2. However, it might only be returning the  program name and not the full path or the file extension.

Using this routine to get the COBOL program name can be used for initialising the Consolidated Trace Facility  (CBL_CTF_TRACER_GET).

Resolution:

Below is an example of how to return the full path/filename of the calling program.

The first thing to do is to establish the handle for the current program.

working-storage section. * 01 call-function pic x(4) comp-5. 01 cblt-prog-info. 05 cblte-gpi-size pic x(4) comp-5. 05 cblte-gpi-flags pic x(4) comp-5. 05 cblte-gpi-handle usage pointer. 05 cblte-gpi-prog-id usage pointer. 05 cblte-gpi-attrs pic x(4) comp-5. 01 name-buf pic x(100). 01 name-len pic x(4) comp-5. 01 status-code pic x(2) comp-5. * procedure division. *Firstly, to establish handle of the current program into *into cblte-gpi-handle move spaces to name-buf move 20 to cblte-gpi-size move 0 to call-function move 1 to cblte-gpi-flags call "CBL_GET_PROGRAM_INFO" using by value call-function by reference cblt-prog-info by reference name-buf by reference name-len returning status-code *Secondly, to return status information for the program that *called the program currently associated with cblte-gpi-handle. *This function requires that cblte-gpi-handle has been set up *using functions 0 or 1(as above). The program associated with *cblte-gpi-handle is updated to the calling program. move 2 to call-function move 1 to cblte-gpi-flags call "CBL_GET_PROGRAM_INFO" using by value call-function by reference cblt-prog-info by reference name-buf by reference name-len returning status-code *Lastly, to display the full path / filename of the program *returned into cblte-gpi-handle as a a result of the call using *call-function 2 move 7 to call-function move 3 to cblte-gpi-flags move 200 to name-len call "CBL_GET_PROGRAM_INFO" using by value call-function by reference cblt-prog-info by reference name-buf by reference name-len returning status-code display name-buf

This should now display the full path/progname of the program that called the current program.

It is important to close a previously created cblte-gpi-handle by making a call with function 3.

*Close a previously created cblte-gpi-handle. This function *requires a valid cblte-gpi-handle to have been created using *function 0 or 1. A call with this function must be made when *cblte-gpi-handle is finished with. move 3 to call-function call "CBL_GET_PROGRAM_INFO" using by value call-function by reference cblt-prog-info by reference name-buf by reference name-len returning status-code
 
A complete working demo can be found in another article here