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

how can i get the name of a mainprogram from a subprogram


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

New User


Joined: 05 Dec 2007
Posts: 13
Location: Germany

PostPosted: Tue Mar 16, 2010 9:17 pm
Reply with quote

I want the name of a main program from a subprogram( all in cobol)

The subprogram is linked to with the main program.

Can i use a function in cobol ???

thanks
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Mar 16, 2010 9:29 pm
Reply with quote

Hello,

No.

Suggeest you search in the forum (SEARCH in the blue bar above) as this has been discussed fairly recently. . .
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Tue Mar 16, 2010 11:03 pm
Reply with quote

If you pass the calling program name as a part of linkage section/commarea this can be achieved. From what I understand, your requirement is-
If calling prog = proga
do something
else
do something else.
Please elaborate if you wanted something else so that we can come up with better suggestions.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Mar 16, 2010 11:06 pm
Reply with quote

Hello,

Quote:
If you pass the calling program name as a part of linkage section/commarea this can be achieved.
But that would require changing every calling program. . . icon_wink.gif
Back to top
View user's profile Send private message
ajaehnert

New User


Joined: 05 Dec 2007
Posts: 13
Location: Germany

PostPosted: Tue Mar 16, 2010 11:06 pm
Reply with quote

i cant pass the program name as part of the linkage section, because this is a migration an the old linkage section is to small and i do not want to change the calling programs.

it was a ASM program, which ask the name of the maim program via a macro.

Andreas
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Mar 16, 2010 11:37 pm
Reply with quote

Hello,

How did the assembler code accomplish this (what did the macro do)?

If you understand how the assembler works, you could possibly do something like this in the called replacement code.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


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

PostPosted: Tue Mar 16, 2010 11:37 pm
Reply with quote

I am not a COBOL programmer; I believe that recent versions of COBOL can handle pointers/addresses, but I don't know if they can be manipulated. It may be necessary to write the external sub-routine/function in PL/I, C/370, HLASM, or smilar language.

Get the TCB (always at address 540 decimal, IIRC). The address of the last LLE is at offset 36 decimal from the TCB; the address of the CDE is at offset 4 from the LLE. The program name is the 8-byte string beginning at offset 8 from the CDE.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Mar 16, 2010 11:50 pm
Reply with quote

Hello,

Quote:
I believe that recent versions of COBOL can handle pointers/addresses
Yup, one can "chase control blocks" with cobol now (actually for quite some time). . .
Back to top
View user's profile Send private message
ajaehnert

New User


Joined: 05 Dec 2007
Posts: 13
Location: Germany

PostPosted: Wed Mar 17, 2010 12:28 am
Reply with quote

hi,

an this program name ist the name of the maim program?


Andreas
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 17, 2010 12:35 am
Reply with quote

Yes; note, however, if the "main" program is really a dynamically-linked (or attached, fetched, etc.) subroutine of a genuine main program as IJKEFTxx, DFSRRC00, etc., that the latter will be returned.
Back to top
View user's profile Send private message
ajaehnert

New User


Joined: 05 Dec 2007
Posts: 13
Location: Germany

PostPosted: Wed Mar 24, 2010 1:23 pm
Reply with quote

hi

i want to know the name of the main program when i executing the sub programm( not dynamily linked)

Thanke
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: Wed Mar 24, 2010 4:49 pm
Reply with quote

You have three choices:

1. Pass the calling program name as a parameter to the subprogram.
2. Chase z/OS control blocks to get this data -- search the forum for exactly what you have to in this case.
3. Accept that what you want is not otherwise possible. There is no COBOL way to get this data, for example -- you have to directly read memory areas for the control blocks.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


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

PostPosted: Wed Mar 24, 2010 6:48 pm
Reply with quote

Quote:
when i executing the sub programm
And, as the sub-programs can not be directly executed - I'm little skeptical about the origin of this question itself!
Back to top
View user's profile Send private message
MBabu

Active User


Joined: 03 Aug 2008
Posts: 400
Location: Mumbai

PostPosted: Wed Mar 24, 2010 11:56 pm
Reply with quote

Chasing control blocks isn't necessarily good though. If load module A has routines M1 and M2 and they call S1, then finding the CDE will show A but you still don't know if M1 or M2 made the call. If you Really want to do this accurately, you might be able to find the CDE, run AMBLIST to get the offsets for the various CSECTs in the load module and do the math. But that sort of thing is still probably imperfect and would be a *real* pain in the *** and implies that you know the address of the subroutine and have access to the save areas and that the compiler is using standard linkage or some other chaining mechanism you can trace. In assembler programs this isn't as bad because most programs use a standard base register, and often have an eyecatcher at at the module, so all you need to do is find the previous save area, grab its 1st base register and use that to find the eye catcher. COBOL though? I wouldn't go there.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Mar 25, 2010 12:01 am
Reply with quote

Quote:
pain in the ***
or maybe:

***a pain***

Hmmmm. . .

Either way - A pain in the asterisks. . .

icon_cool.gif
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 How to go into a subprogram in IBM De... IBM Tools 5
No new posts Parallel Sysplex - subprogram execution CICS 7
No new posts Is possible to call subprogram from c... COBOL Programming 3
No new posts Difference of COMMIT in main program ... DB2 11
No new posts Could not extract Natural Subprogram(s) Java & MQSeries 0
Search our Forums:

Back to Top