IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to get the program name of calling module in called prog


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 271

PostPosted: Mon Aug 01, 2016 3:36 am
Reply with quote

Hi All,

I have a subroutine program(called module) program B static called by many programs. Since it is a maintenance project i dont have access to pass the calling module program through calling variables, is there anyway to get the calling program name without modifying the calling program?

Thanks
Murali
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Aug 01, 2016 4:59 am
Reply with quote

There has been a SHARE requirement to access this information in Enterprise COBOL for a number of years, so yours is not the first request to do this. However, since the requirement exists, obviously it cannot currently be retrieved easily.
Back to top
View user's profile Send private message
steve-myers

Active Member


Joined: 30 Nov 2013
Posts: 917
Location: The Universe

PostPosted: Mon Aug 01, 2016 5:30 am
Reply with quote

I can't think of a way to do this. You can try this.
  1. Get a load module map of the module using JCL like this -
    Code:
    //A       EXEC PGM=IMBLIST
    //SYSPRINT DD  SYSOUT=*
    //SYSLIB   DD  DISP=SHR,DSN=--your load module library--
    //SYSIN    DD  *
     LISTLOAD OUTPUT=XREF,MEMBER=--your program's load module--

  2. Part of this listing will look like this -
    Code:
    -------------------------------------------------------------------------------
          LMOD LOC  CSECT LOC    IN CSECT              REFERS TO SYMBOL  AT LMOD LO
              580       580      LOGTIME                   SMFETIME            690
              584       584      LOGTIME                   LOGTMSGS            5C0
    Look for your program in the REFERS TO SYMBOL AT LMOD column. The symbol in the IN CSECT column is usually (though not always) the calling program. Many compilers will put data (like the address of modules it is calling) in a CSECT separate from the program text. For example -
    Code:
    LMOD LOC  CSECT LOC    IN CSECT              REFERS TO SYMBOL  AT LMOD LOC
         24        24      ICH408                    ICH408D            2178
       2675       4FD      ICH408D                   ICH408               00
       271C       5A4      ICH408D                   ICH408               00 
       2728       5B0      ICH408D                   ICH408               00 
       2734       5BC      ICH408D                   ICH408               00 
       2740       5C8      ICH408D                   ICH408               00 
       274C       5D4      ICH408D                   ICH408               00 
       2758       5E0      ICH408D                   ICH408               00 
       2764       5EC      ICH408D                   ICH408               00 
       27A8       630      ICH408D                   ICH408               00 
       27B4       63C      ICH408D                   ICH408               00 
       28F0       778      ICH408D                   MINIFMT            16E8 
       2954       7DC      ICH408D                   ICH408               00 
       2994       81C      ICH408D                   QSORTL             15D0
    Figuring out relations in this kind of structure is doable, though painful.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Mon Aug 01, 2016 6:53 am
Reply with quote

You'll have to chase control blocks for it. I wrote a callable module that did this for my last client, but

  1. I'm not at that client any more and therefore don't have access to that code, and
  2. it was in PL/I

I'll try to remember the sequence of control blocks tomorrow.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Aug 01, 2016 5:22 pm
Reply with quote

It's been discussed before. Here, and the links within.

It is not a good idea to use this to control program logic. What do you want the program name for?
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Mon Aug 01, 2016 8:59 pm
Reply with quote

What you want is this, CEEBINT High-Level Language User Exit Interface but I guess you need modifications?
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Mon Aug 01, 2016 9:39 pm
Reply with quote

This is what I found on internet, Retrieve Call Stack (QWVRCSTK) API.
Code:
PROCESS NOMONOPRC.

* To compile:
* CRTCBLMOD CALLSTACK
* CRTPGM CALLSTACK BNDDIR(QC2LE)

IDENTIFICATION DIVISION.
PROGRAM-ID. CALLSTACK.

DATA DIVISION.
WORKING-STORAGE SECTION.
COPY QUSEC OF QSYSINC-QCBLLESRC.
COPY QWCATTR OF QSYSINC-QCBLLESRC.

01 Receiver.
05 Bytes-Returned PIC S9(9) BINARY.
05 Bytes-Available PIC S9(9) BINARY.
01 Memory-Pointer POINTER.
01 Stack-Pointer POINTER.
01 My-Name PIC X(10).

LINKAGE SECTION.
COPY QWVRCSTK OF QSYSINC-QCBLLESRC.

PROCEDURE DIVISION.
MAIN-LINE.
MOVE 0 TO Bytes-Provided OF QUS-EC.
PERFORM Get-Caller THRU Exit-Get-Caller.
STOP RUN.

Get-Caller.

* Find out how much information is available

* First initialize the Job Information structure
MOVE LOW-VALUES TO QWC-JIDF0100.
MOVE "*" TO JOB-NAME OF QWC-JIDF0100.
MOVE SPACES TO USER-NAME OF QWC-JIDF0100.
MOVE SPACES TO JOB-NUMBER OF QWC-JIDF0100.
MOVE SPACES TO INT-JOB-ID OF QWC-JIDF0100.
MOVE 1 TO THREAD-INDICATOR OF QWC-JIDF0100.

* Then call the API
CALL "QWVRCSTK" USING
BY REFERENCE Receiver,
BY CONTENT LENGTH OF Receiver,
BY CONTENT "CSTK0100",
BY REFERENCE QWC-JIDF0100,
BY CONTENT "JIDF0100",
BY REFERENCE QUS-EC.

* Allocate enough memory for the information
CALL LINKAGE PRC "malloc" USING
BY VALUE Bytes-Available OF Receiver
RETURNING Memory-Pointer.
SET ADDRESS OF QWV-CSTK0100 TO Memory-Pointer.

* Now get the information
CALL "QWVRCSTK" USING
BY REFERENCE QWV-CSTK0100,
BY CONTENT Bytes-Available OF Receiver,
BY CONTENT "CSTK0100",
BY REFERENCE QWC-JIDF0100,
BY CONTENT "JIDF0100",
BY REFERENCE QUS-EC.
* Not available for some reason?
IF ENTRY-AVAILABLE OF QWV-CSTK0100 = 0
DISPLAY "Major problem accessing call stack"

ELSE
* Display the program name
SET Stack-Pointer TO Memory-Pointer
SET Stack-Pointer UP BY ENTRY-OFFSET
OF QWV-CSTK0100
SET ADDRESS OF QWV-RCSTK-ENTRY TO Stack-Pointer
MOVE PROGRAM-NAME OF QWV-RCSTK-ENTRY TO My-Name
PERFORM TEST AFTER UNTIL PROGRAM-NAME OF QWV-RCSTK-ENTRY
NOT EQUAL My-Name
SET Stack-Pointer UP BY ENTRY-LENGTH
OF QWV-RCSTK-ENTRY
SET ADDRESS OF QWV-RCSTK-ENTRY TO Stack-Pointer
END-PERFORM
DISPLAY "My caller is: " PROGRAM-NAME
OF QWV-RCSTK-ENTRY
END-IF.

* Now free the allocated memory
CALL LINKAGE PRC "free" USING BY VALUE Memory-Pointer.
Exit-Get-Caller.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Aug 01, 2016 10:13 pm
Reply with quote

Rohit,

That program is for iSeries again.

The CEEBINT is possible, but it is a bit blunt. There's discussion of it in another topic here, which the search should find. If COBOL can be calling CEEBINT, the exit cannot be written in COBOL (but an be PL/I, C/C++, Assembler).
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Wed Aug 03, 2016 2:06 am
Reply with quote

Thanks Bill. I never require to work on that but good to know.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Using API Gateway from CICS program CICS 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Calling Java method from batch COBOL ... COBOL Programming 5
No new posts Calling an Open C library function in... CICS 1
No new posts DB2 Event passed to the Application P... DB2 1
Search our Forums:

Back to Top