Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

To identify which main pgm is calling sub program

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Sumitra.N

New User


Joined: 12 Mar 2013
Posts: 3
Location: India

PostPosted: Tue Mar 12, 2013 5:40 pm    Post subject: To identify which main pgm is calling sub program
Reply with quote

Hi,
I have a sub program Sub1 being called from 2 main programs in a jcl, main1 and main2.
The program name is not a part of the variables being passed while calling the sub1.
Is there any other way to know whether main1 or main2 is calling the sub1, inside sub1.

Please let me know if you need any more details.

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

Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1712
Location: UK

PostPosted: Tue Mar 12, 2013 6:55 pm    Post subject:
Reply with quote

Yes - your JCL only executes one program at a time so the current execution of sub1 is from the current execution of the main program.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Tue Mar 12, 2013 7:14 pm    Post subject: Reply to: To identify which main pgm is calling sub program
Reply with quote

a partial excuse could be that the subroutine should behave differently depending on the caller

anyway that' s a very poor excuse ...
more proper to use an additional parameter to specify the actions/flow
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Tue Mar 12, 2013 7:50 pm    Post subject:
Reply with quote

This seem to be good discussion on a similar thing : http://ibmmainframes.com/about57228.html , I've not verifed too much though.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


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

PostPosted: Wed Mar 13, 2013 3:08 am    Post subject: Re: Reply to: To identify which main pgm is calling sub prog
Reply with quote

enrico-sorichetti wrote:
more proper to use an additional parameter to specify the actions/flow

But software engineers "cloning" programs cannot be trusted to update that parameter properly.

Sumitra-chan, you can get the call chain by chasing control blocks; I wrote a PL/I subroutine a few years back that does just that, and for the reason mentioned above. I'll see tomorrow if I still have my notes.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Mar 13, 2013 6:52 am    Post subject: Reply to: To identify which main pgm is calling sub program
Reply with quote

The following three LOAD instructions, can get you to the MVS-TCB in Assembler -

Code:

         L     R1,16                   CVT-ADDRESS
         L     R1,0(,R1)               ADDRESS OF TCB-POINTERS
         L     R1,4(,R1)               LOAD TCB-ADDRESS

You can then navigate through the TCB-data and locate the Calling Program's name.

The Mapping Macro is ===> IKJTCB

Another method (one less instruction) -

Code:

         L     R1,540                  POINT TO TCB-ADDRESS
         L     R1,0(,R1)               LOAD TCB-ADDRESS

R1 is used only as an example.

HTH....
Back to top
View user's profile Send private message
Sumitra.N

New User


Joined: 12 Mar 2013
Posts: 3
Location: India

PostPosted: Wed Mar 13, 2013 9:01 am    Post subject:
Reply with quote

Thr purpose : The sub1 fails under a specific condition when called from main1 and main2. The program is not made to abend but writes into an error log. So when we see the eror log we should know thru which program the abend in sub program occurred.

Hope this would make the requirement more clear.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Wed Mar 13, 2013 2:51 pm    Post subject: Reply to: To identify which main pgm is calling sub program
Reply with quote

OK, you want to identify the CALLing program (better than calling it main).

Unfortunately, even if you want to know the name of the current program, Cobol gives no help.

I'd suggest calling a small Assembler sub-routine to do the work. It would work its way back down the "calling chain" to the "last but one" call which, since yours will be the "last" CALL to the Assembler, will be the program that CALLed your program.

Do you know Assembler? Anyone at your site?

If not, you may need to spend some money. Needn't be much (it is a very simple thing). Can be done "remotely", if you get the hint :-)
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Wed Mar 13, 2013 2:54 pm    Post subject:
Reply with quote

Look in the dump.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Wed Mar 13, 2013 3:44 pm    Post subject: Reply to: To identify which main pgm is calling sub program
Reply with quote

If there is an abend, yes, but for logging non-fatal problems, the source of the CALL has to be something else.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Wed Mar 13, 2013 4:06 pm    Post subject:
Reply with quote

The TS mentions an abend occuring.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Wed Mar 13, 2013 4:27 pm    Post subject:
Reply with quote

I missed the full meaning Peter :-)


Sumitra.N wrote:
Thr purpose : The sub1 fails under a specific condition when called from main1 and main2. The program is not made to abend but writes into an error log. So when we see the eror log we should know thru which program the abend in sub program occurred.

Hope this would make the requirement more clear.


The "main" program writes an error log (and the "main" program should, subject to typos or slack modelling on other programs, be able to have its name available - it would be nice if Cobol provided a "special register" with the program name in, but it doesn't).

The "main" program should also know the name of the CALLed program, subject to the same caveats.

From the dump, as Peter has said, it is just a question of looking. Perhaps whatever is formatting the dump will just plain tell you. Even if not, the last log entry (which may not be on disk, but can be located) will tell you.
Back to top
View user's profile Send private message
Sumitra.N

New User


Joined: 12 Mar 2013
Posts: 3
Location: India

PostPosted: Wed Mar 13, 2013 4:54 pm    Post subject:
Reply with quote

One small correction in the above post- The main pgm does not write the error log the sub program writes the error log, which is why i want the name of the main pgm in the sub program.
1) Assembler, well out of question since we are not proficient enough
2) From the dump, where and how do we locate it, any clues.
3) When it write into error log, there is no abend.
Back to top
View user's profile Send private message
seagull

New User


Joined: 28 May 2007
Posts: 24
Location: Dublin

PostPosted: Wed Mar 13, 2013 5:18 pm    Post subject:
Reply with quote

Can you change the passed variables to include the calling program?
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Mar 13, 2013 5:39 pm    Post subject: Reply to: To identify which main pgm is calling sub program
Reply with quote

Or, define EXTERNAL WS in both programs and populate the calling program-name, which is then addressable by both.

The EXTERNAL WS needs to be defined exactly the same way in both programs.

Using EXTERNAL WS negates the need to alter the parm-list.

Define the following in both programs and populate WS-CALLING-PGM in the Calling Program before calling the sub-program. VALUE clauses are not allowed in EXTERNAL WS -

Code:

01  WS-EXTERNAL-STG EXTERNAL.
    03  WS-CALLING-PGM PIC X(08).

MOVE 'MAINPGM' TO WS-CALLING-PGM.

HTH....
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts IMS BMP program causes 878 system abend Artemk IMS DB/DC 7 Tue Nov 22, 2016 8:26 pm
No new posts A sample of exit program for exit XMN... lind sh CICS 2 Mon Oct 03, 2016 5:07 pm
No new posts Need points to tune IMS Checkpoint Pr... satish.ms10 IMS DB/DC 2 Fri Sep 30, 2016 4:12 pm
No new posts ISPF program to set SCRNAME prino TSO/ISPF 5 Fri Sep 30, 2016 2:18 pm
No new posts Need Rexx Program to Load in to DB2 T... Hareesh Verma CLIST & REXX 22 Tue Sep 20, 2016 2:59 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us