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

can we use initialize for initializing working storage


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

New User


Joined: 16 Mar 2010
Posts: 6
Location: India

PostPosted: Wed Mar 24, 2010 2:02 pm
Reply with quote

Hi
I have declared all the variables in working storage section.

Is there any need to initialize working storage in procedure division..
e.g.
P.D.

INITIALIZE WS-WORKING-STORAGE.
further programe will be here...

if yes then why and if no then why???
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Wed Mar 24, 2010 2:40 pm
Reply with quote

Hi Pankaj,

Quote:
Is there any need to initialize working storage in procedure division..
No... Not necessary...

Quote:
if yes then why and if no then why???
Because initializing variables is purely the way you code or rather functional. If you are expecting any field to have any default values before using them in the code, then you should certainly have a INITIALIZE or VALUE clause... Its always a good programming practice though to initialize the working variables...

Hope this is what you were looking for ...
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Wed Mar 24, 2010 2:43 pm
Reply with quote

Morning Sir !

Not really.

Perhaps you overwrite some variables during programm-flow and you want to rest them to te default. For example the input/output-areas of datasets.

I would suggest to contemplate about the functionality of the initialize command. Then have a look at your programm-flow. Then specify where you have to reset your ws-variables to the primordially content.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Wed Mar 24, 2010 5:32 pm
Reply with quote

You should however be aware that if you are writing modules to be used in online application in e.g. CICS and IMS you cannot safely rely on your working storage to have all initial values if variables have been modified in a previous call.

That it also the fact if you make multiple calls to a module during a batch execution. The working storage will have the same contents as when you returned to the calling program last time, unless reentrant techniques are used (basically each called instance allocates it own working storage).

The initialize statement can consume a lot of CPU, if not used wisely. So it is prudent to ensure that variables are actually set/modified before you reference the contents, unless you actively want to use information that could have been set by an earlier invocation.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

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

I would not recommend initializing the working-storage globally.
Code:
03  MAX-VAL PIC S9(4) COMP VALUE 12.
If you have constants like this, they will be emptied!
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Thu Mar 25, 2010 5:17 am
Reply with quote

If you tell us how many and how often the variables will need "reinitializing" and how they are defined (record definitions, individual working storage variables, etc.), maybe someone can provide options for accomplishing what you want.
Back to top
View user's profile Send private message
pgte3

New User


Joined: 06 Feb 2009
Posts: 11
Location: USA

PostPosted: Fri Mar 26, 2010 6:59 pm
Reply with quote

I would shy away from doing something like INITIALIZE WS-WORKING-STORAGE without understanding completely what the program is doing and the environment it is running in.

Issuing such a command will cause problems with constants defined (as mention above) and will also introduce overhead by possibly initializing variables that do not need to be initialized.
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 CLIST - Virtual storage allocation error CLIST & REXX 5
No new posts PD not working for unsigned packed JO... DFSORT/ICETOOL 5
No new posts Def PD not working for unsigned packe... JCL & VSAM 3
No new posts CICS vs LE: STORAGE option CICS 0
No new posts Insufficient Storage ABENDS & Debugging 7
Search our Forums:

Back to Top