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

Problem due to 'INITIAL' in Sub Program


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
dick scherrer

Moderator Emeritus


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

PostPosted: Sun Jul 05, 2009 3:43 am
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: 271

PostPosted: Mon Jul 06, 2009 11:58 am
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

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Jul 06, 2009 12:27 pm
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: 271

PostPosted: Mon Jul 13, 2009 11:30 am
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

Moderator Emeritus


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

PostPosted: Mon Jul 13, 2009 8:22 pm
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
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Mon Jul 13, 2009 8:39 pm
Reply with quote

pkmurali, your bold statements in your last post are not correct. From the COBOL Programming Guide, emphasis added by me
Quote:
1.1.3.2 Comparison of WORKING-STORAGE and LOCAL-STORAGE

How data items are allocated and initialized varies depending on whether the items are in the WORKING-STORAGE SECTION or LOCAL-STORAGE SECTION.

WORKING-STORAGE for programs is allocated at the start of the run unit.

Any data items that have VALUE clauses are initialized to the appropriate value at that time. For the duration of the run unit, WORKING-STORAGE items persist in their last-used state. Exceptions are:

* A program with INITIAL specified in the PROGRAM-ID paragraph

In this case, WORKING-STORAGE data items are reinitialized each time that the program is entered.

* A subprogram that is dynamically called and then canceled


In this case, WORKING-STORAGE data items are reinitialized on the first reentry into the program following the CANCEL.

WORKING-STORAGE is deallocated at the termination of the run unit.
For batch programs the run unit starts with the main program initialization and continues until the main program ends. Unless your subprogram explicitly has INITIAL in the PROGRAM-ID paragraph, OR it is dynamically called and then canceled, the subprogram variables will retain their values across subprogram calls. Whether the program is dynamically linked does not matter unless the calling program does a CANCEL on the subprogram. If you don't have a CANCEL in your calling program, and you do not have INITIAL on your subprogram PROGRAM-ID paragraph, then your variables in the subprogram will retain the same values from call to call.

Also, be aware that LOCAL-STORAGE and WORKING-STORAGE are very different items now. You need to distinguish between them as WORKING-STORAGE is allocated by run unit while LOCAL-STORAGE is allocated by invocation.
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 -> Mainframe Interview Questions Goto page Previous  1, 2

 


Similar Topics
Topic Forum Replies
No new posts Using API Gateway from CICS program CICS 0
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts DB2 Event passed to the Application P... DB2 1
No new posts How to pass the PARM value to my targ... COBOL Programming 8
No new posts REXX code to expand copybook in a cob... CLIST & REXX 2
Search our Forums:

Back to Top