View previous topic :: View next topic
|
Author |
Message |
pankajtripathi
New User
Joined: 16 Mar 2010 Posts: 6 Location: India
|
|
|
|
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 |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
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 |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
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 |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
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 |
|
|
pgte3
New User
Joined: 06 Feb 2009 Posts: 11 Location: USA
|
|
|
|
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 |
|
|
|