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

To identify which main pgm is calling sub program


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 2455
Location: Hampshire, UK

PostPosted: Tue Mar 12, 2013 6:55 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Tue Mar 12, 2013 7:14 pm
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

Superior Member


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

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

This seem to be good discussion on a similar thing : 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: 1788
Location: Bloomington, IL

PostPosted: Wed Mar 13, 2013 3:08 am
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Mar 13, 2013 6:52 am
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
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

Moderator Emeritus


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

PostPosted: Wed Mar 13, 2013 2:51 pm
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: 2481
Location: Netherlands, Amstelveen

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

Look in the dump.
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: Wed Mar 13, 2013 3:44 pm
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: 2481
Location: Netherlands, Amstelveen

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

The TS mentions an abend occuring.
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: Wed Mar 13, 2013 4:27 pm
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
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Mar 13, 2013 5:39 pm
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 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