Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
Problem due to 'INITIAL' in Sub Program
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Interview Questions
Author Message
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 143

PostPosted: Fri Jul 03, 2009 8:08 pm    Post subject:
Reply with quote

To be more specific,

I have coded Program 'A1' which calls Program 'A2' and Program 'A2' calls Program 'B' all are dynamic calls, after one invocation by Program 'A1' if i cancel Program 'B' will it initialize WS-END-OF-CB002003.

The syntax must be
CANCEL (IDENTIFIER-1,
lITERAL-11....)

Please suggest the above approach is correct or not.

Thanks,
murali.
Back to top
View user's profile Send private message
References
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 143

PostPosted: Fri Jul 03, 2009 8:32 pm    Post subject: Reply to: Problem due to 'INITIAL' in Sub Program
Reply with quote

Now It's working Fine.

Thanks Dick Brenholtz and Robert Sample.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Senior Member


Joined: 20 Oct 2006
Posts: 3385
Location: germany

PostPosted: Fri Jul 03, 2009 8:33 pm    Post subject:
Reply with quote

glad you were able to solve it. Have a good weekend.
Back to top
View user's profile Send private message
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 143

PostPosted: Sat Jul 04, 2009 6:35 pm    Post subject: Reply to: Problem due to 'INITIAL' in Sub Program
Reply with quote

I have one doubt,what could be the chances of the Program 'B' to hold the value which is being stored on first call? whether it could be the compiler option which made the program to do so?

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

Senior Member


Joined: 20 Oct 2006
Posts: 3385
Location: germany

PostPosted: Sat Jul 04, 2009 6:56 pm    Post subject:
Reply with quote

what you are asking is
'if a compiler option would override the existence or non-existence of the INITIAL phrase in the PROGRAM-ID clause'.

I don't think so.
Back to top
View user's profile Send private message
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 143

PostPosted: Sat Jul 04, 2009 6:59 pm    Post subject: Reply to: Problem due to 'INITIAL' in Sub Program
Reply with quote

I'm confused about the behavior of the program, i guess it may be due to compiler options. I'm not sure.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Senior Member


Joined: 20 Oct 2006
Posts: 3385
Location: germany

PostPosted: Sat Jul 04, 2009 7:17 pm    Post subject:
Reply with quote

Quote:
I'm confused about the behavior of the program


you are not going to get any help here if you do not describe the behavior that is confusing you.
Back to top
View user's profile Send private message
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 143

PostPosted: Sat Jul 04, 2009 10:02 pm    Post subject: Reply to: Problem due to 'INITIAL' in Sub Program
Reply with quote

If a sub program(dynamic call) is called twice, for the first call normally a sub program(goback) returning the control back to main program the local variable will contain the initial values for second call. In my case why that program retains the values (first call) in second call. Please let me know.

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

Global Moderator


Joined: 06 Jun 2008
Posts: 4235
Location: Atlanta, GA

PostPosted: Sat Jul 04, 2009 10:13 pm    Post subject:
Reply with quote

What are the compile options? What does the CALL statement look like? Is program B linked into program A or is it an independent module?

You've stated that the call is dynamic, but you've provided no proof of this. A static call will retain values, and unless you've read and understood the COBOL Programming Guide and Language Reference manuals on dynamic calls, it is easy to think a static call is dynamic.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Senior Member


Joined: 20 Oct 2006
Posts: 3385
Location: germany

PostPosted: Sun Jul 05, 2009 2:46 am    Post subject:
Reply with quote

a dynamic call will also perform the same.

the only time a CALLed module
does not retain working-storage values, generated during the invocation,
on second, third call is
  • the CALLed program is CANCELed
  • the CALLed program has the INITIAL phrase as part of the PROGRAM-ID statement
  • the CALLed program has code in procedure division that modifies working-storage variables before start of processing


Murali,
you want the working-storage variables at an initialized value for each invocation:
you don't want to change the sub-module
you need to CANCEL the module after return to the CALLing module each time.
Back to top
View user's profile Send private message
dick scherrer

Global Moderator


Joined: 23 Nov 2006
Posts: 13572
Location: 221 B Baker St

PostPosted: Sun Jul 05, 2009 3:43 am    Post subject:
Reply with quote

Hello,

Not quite the same (but gives predictable results) is always passing these fields from the caller to the called module. There would be no question of the value and if someone changes the way the module is called one day, the program will still perform consistently.

This was the standard for subroutine processing at several sites i've supported.

fwiw. . .
Back to top
View user's profile Send private message
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 143

PostPosted: Mon Jul 06, 2009 11:58 am    Post subject: Reply to: Problem due to 'INITIAL' in Sub Program
Reply with quote

Proof for Dynamic call,

Code:

2200-GET-POSSIBLE-MATCHES.                                 
                                                           
    MOVE '2200-GET-POSSIBLE-MATCHES' TO WS-PARAGRAPH-NM.   
                                                           
    MOVE ZERO TO IP-B002-ADDR-COUNT.                       
    MOVE ZERO TO IP-B002-CSPCLT-COUNT.                     
    CALL WS-R243B002 USING  LK-ECA-HEADER,                 
                            LK-R243B002-DATA-IN,           
                            LK-R243B002-DATA-OUT.           
                                                           
    IF LK-ECA-RETURN-CD = '0000'                           


working storage declaration

Code:

      01  WS-CALLED-PROGRAMS.                                         
          05  WS-R243B002                 PIC X(08) VALUE 'R243B002'. 
          05  WS-R243B003                 PIC X(08) VALUE 'R243B003'. 
          05  WS-R243B004                 PIC X(08) VALUE 'R243B004'. 
          05  WS-R243B005                 PIC X(08) VALUE 'R243B005'. 
                                                                       


Program WS-R243B002 is reffered as PROGRAM 'B' and compiled with dynam option.

Thanks,
Murali.
Back to top
View user's profile Send private message
Marso

Active Member


Joined: 13 Mar 2006
Posts: 614
Location: Israel

PostPosted: Mon Jul 06, 2009 12:27 pm    Post subject:
Reply with quote

Did anybody notice that the question was about LOCAL-STORAGE area ?

pkmurali wrote:
the Local-storage values remains the same when program 'A' calls Program 'B' second time.
Back to top
View user's profile Send private message
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 143

PostPosted: Mon Jul 13, 2009 11:30 am    Post subject:
Reply with quote

Hope i have given the proof for Dynamic call ( apart from calling statement the compiler is not specified as DYNAM so in default it would be NODYNAM), But still i am not clear about how the sub program behaving like an static call.

I believe, the below statement is correct,

A statically called subroutine will not be in its initial state the next time it is called unless you explicitly use INITIAL or you do a CANCEL. A dynamically called routine will always be in its initial state.

In static linking, the called subroutine is link-edited into the calling program , while in dynamic linking, the subroutine & the main program will exist as separate load modules. You choose static/dynamic linking by choosing either the DYNAM or NODYNAM link edit option. (Even if you choose NODYNAM, a CALL identifier (as opposed to a CALL literal), will translate to a DYNAMIC call).

What could be the reason for this sort of behaviour any changes in program Genes icon_confused.gif
Back to top
View user's profile Send private message
dick scherrer

Global Moderator


Joined: 23 Nov 2006
Posts: 13572
Location: 221 B Baker St

PostPosted: Mon Jul 13, 2009 8:22 pm    Post subject:
Reply with quote

Hello,

Quote:
What could be the reason for this sort of behaviour
Unless i've missed something, what you are saying is that everything is working as documented icon_confused.gif
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Interview Questions All times are GMT + 6 HoursGoto page Previous  1, 2, 3  Next
Page 2 of 3