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
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 271

PostPosted: Thu Jul 02, 2009 7:39 pm
Reply with quote

Hi,

Program A is calling sub program B twice. Since Program 'B' is in Inital the Local-storage values remains the same when program 'A' calls Program 'B' second time.

What are all the possibilities to convert Program 'B' non-initial
apart from recompiling Program 'B'. (i.e. without changing Program 'B').

Please let me know.

Thanks,
Murali.
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: Thu Jul 02, 2009 7:52 pm
Reply with quote

Remove "PROGRAM IS INITIAL" from the PROGRAM-ID clause? icon_rolleyes.gif
Back to top
View user's profile Send private message
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 271

PostPosted: Thu Jul 02, 2009 7:54 pm
Reply with quote

I agree it will help, but my scenario is not to touch the Program 'B'. I feel 'CANCEL' will help...
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Jul 02, 2009 7:56 pm
Reply with quote

pkmurali,

you have everything ass-backwards.

INITIAL and CANCEL have the same effect.
Back to top
View user's profile Send private message
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 271

PostPosted: Fri Jul 03, 2009 11:31 am
Reply with quote

Dick Brenholtz

I am using a existing COBOL Program in my project(similar to Program 'B' mentioned in the previous post) which retains it's local storage variables, i can't able to find the keyword 'INITIAL' or 'CANCEL' used in the program.Since we use Endevor the compiling details are not available. Please let me know what should be done to make that program non-initial.

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

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Fri Jul 03, 2009 1:49 pm
Reply with quote

pkmurali wrote:
Hi,

Program A is calling sub program B twice. Since Program 'B' is in Inital the Local-storage values remains the same when program 'A' calls Program 'B' second time.

What are all the possibilities to convert Program 'B' non-initial
apart from recompiling Program 'B'. (i.e. without changing Program 'B').

Please let me know.

Thanks,
Murali.


AFAIK INITIAL clause causes the variables to be 'refreshed'. i.e. the variables WILL NOT retain the values from the previous call.

According to my understanding, Using INITIAL in the called program and using CANCEL before calling the subprogram in the calling program yields the same effect. Is there really a need to change anything??
Back to top
View user's profile Send private message
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 271

PostPosted: Fri Jul 03, 2009 4:49 pm
Reply with quote

My objective is to make the program 'B' to be non-initial without touching the program 'B'. Is it possible?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jul 03, 2009 4:56 pm
Reply with quote

does program b have PROGRAM IS INITIAL in the PROGRAM-ID clause?????

if not, then your objective has been obtained - without action.

If Program b has the INITIAL phrase in the PROGRAM-ID clause,
then you have to change Program b.

you said that there are no CANCEL Program b instructions in Program a,
so that is not an issue.
Back to top
View user's profile Send private message
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 271

PostPosted: Fri Jul 03, 2009 5:00 pm
Reply with quote

does program b have PROGRAM IS INITIAL in the PROGRAM-ID clause?????

NO

if not,
then if there are no CANCEL Program b instructions in Program a,
then program b's working-storage,
will
on subsequent CALLs,
have the same values as when exited on the previous invocation.

No Cancel statement coded
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jul 03, 2009 5:02 pm
Reply with quote

then you do not have a problem. and you don't need to take any action.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jul 03, 2009 5:05 pm
Reply with quote

I have overlooked the possibility that Program b executes INITIALIZE instructions.

Does Program b initialize all of its working-storage via INITIALIZE instructions?
Back to top
View user's profile Send private message
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 271

PostPosted: Fri Jul 03, 2009 7:29 pm
Reply with quote

I have xpedited the subprogram, where WS-END-OF-CB002003 is the working storage variable.

This is the first call...

Code:

COMMAND ===>                                                        SCROLL ===>    CSR 
                            BEFORE BREAKPOINT ENCOUNTERED                           
                                                  -                                 
000067    K    05 WS-END-OF-CB002003                 >     N                                 
                                                  ----+----1----+----2----+----3    
MORE->         01 LK-ECA-HEADER                      >     ..............................    
                                                  ----+----1----+----2----+----3    
------         -----------------------------------------    Before R243B002/AMODE 31    <>
000826         ********************                                              0114
=====>    B     PROCEDURE DIVISION USING LK-ECA-HEADER                           0116
000828                                   LK-R243B002-DATA-IN                     0117
000829                                   LK-R243B002-DATA-OUT.                   0117
000830         ********************                                              0118
000831         *                                                                 0119
000832          DSNSQL SECTION.                                                     


This the status at the end of the sub program...

Code:

    COMMAND ===>                                                        SCROLL ===>    CSR 
                                BEFORE BREAKPOINT ENCOUNTERED                           
                                                      -                                 
    000067    K    05 WS-END-OF-CB002003                 >     Y                                 
             ** END **                                                             
                                                                                   
                                                                                   
    ------         -------------------------------------    Before R243B002:958/AMODE 31    <>
    000957          0000-MAINLINE-EXIT.                                              0149
    =====>    B         GOBACK.                                                      0150
    000959         /                                                                 0151
    000960          1000-INITIALIZATION.                                             0152
    000961              MOVE '1000-INITIALIZATION'         TO WS-PARAGRAPH-NM.       0153
    000962                                                                           0154
    000963         * TEMPORARY TABLE DECLARATION                                     0154


this the second call.. where the value of WS-END-OF-CB002003 remains the same 'Y' (retaining the value after the first call).

Code:

    COMMAND ===>                                                        SCROLL ===>    CSR 
    PROGRAM:    R243B002      MODULE: R243B002 COMP DATE:  09/17/2002 COMP TIME:14:56:25
                                                      -                                 
    000067    K    05 WS-END-OF-CB002003                 >     Y                                 
                                                      ----+----1----+----2----+----3    
    MORE->         01 LK-ECA-HEADER                      >     ..............................    
                                                      ----+----1----+----2----+----3    
    ------         -----------------------------------------    Before R243B002/AMODE 31    <>
    000826         ********************                                              0114
    =====>    B     PROCEDURE DIVISION USING LK-ECA-HEADER                           0116
    000828                                   LK-R243B002-DATA-IN                     0117
    000829                                   LK-R243B002-DATA-OUT.                   0117
    000830         ********************                                              0118
    000831         *                                                                 0119
    000832          DSNSQL SECTION.                                                     
    000833          SQL-SKIP.                                                           
    000834              GO TO SQL-INIT-END.                                             


The Sub program doesn't contain 'INITIAL' or the calling program doesn't have 'CANCEL' statement. Please let me know what should be done to refresh the value for WS-END-OF-CB002003. I am not supposed to change the Sub-Program.

Thanks,
Murali.
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: Fri Jul 03, 2009 7:41 pm
Reply with quote

Is the sub program statically called or dynamically called? If it is statically called, change your calling program to make it a dynamic call.

Use CANCEL after returning from the subprogram -- but note that this verb only works on dynamically called routines.
Back to top
View user's profile Send private message
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 271

PostPosted: Fri Jul 03, 2009 7:42 pm
Reply with quote

To Addwith,

The Sub program is treated as Stored Procedure in earlier application, but i am using it as BatchLoad. Sub-Program can be called as Stored Procedure as well as Batch Program.

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

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jul 03, 2009 7:56 pm
Reply with quote

now I understand the problem.
some jerk coded a stored procedure,
knowing that it would not be re-invoked during the task,
and laid crap code so that it is not re-entrant.

you are screwed Murali,

as Robert said, you can only CANCEL dynamically CALLed modules,
so your process must eat the overhead created by CANCELing and reLOADing the module for each invocation.
Back to top
View user's profile Send private message
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 271

PostPosted: Fri Jul 03, 2009 8:08 pm
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
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 271

PostPosted: Fri Jul 03, 2009 8:32 pm
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

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jul 03, 2009 8:33 pm
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: 271

PostPosted: Sat Jul 04, 2009 6:35 pm
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

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sat Jul 04, 2009 6:56 pm
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: 271

PostPosted: Sat Jul 04, 2009 6:59 pm
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

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sat Jul 04, 2009 7:17 pm
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: 271

PostPosted: Sat Jul 04, 2009 10:02 pm
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Sat Jul 04, 2009 10:13 pm
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

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sun Jul 05, 2009 2:46 am
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
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 1, 2  Next

 


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