View previous topic :: View next topic
|
Author |
Message |
Sumitra.N
New User
Joined: 12 Mar 2013 Posts: 3 Location: India
|
|
|
|
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 |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1787 Location: Bloomington, IL
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
Sumitra.N
New User
Joined: 12 Mar 2013 Posts: 3 Location: India
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Look in the dump. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
The TS mentions an abend occuring. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Sumitra.N
New User
Joined: 12 Mar 2013 Posts: 3 Location: India
|
|
|
|
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 |
|
|
seagull
New User
Joined: 28 May 2007 Posts: 24 Location: Dublin
|
|
|
|
Can you change the passed variables to include the calling program? |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
|