Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
can we use initialize for initializing working storage

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: can we use initialize for initializing working storage
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    Post subject:
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: 757
Location: Germany

PostPosted: Wed Mar 24, 2010 2:43 pm    Post subject:
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    Post subject:
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: 1243
Location: Israel

PostPosted: Wed Mar 24, 2010 6:31 pm    Post subject: Reply to: can we use initialize for initializing working sto
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    Post subject:
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: upstate

PostPosted: Fri Mar 26, 2010 6:59 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts sharing PLI storage Pedro PL/I & Assembler 2 Mon Oct 16, 2017 10:11 pm
No new posts LIBDEF not working in called proc packerm CLIST & REXX 0 Fri Sep 15, 2017 7:22 pm
No new posts Working with hex values in Filemanage... Emile Straker IBM Tools 0 Tue Sep 12, 2017 1:42 am
No new posts ISREDIT MACRO NOT WORKING! :cry: kirank889 TSO/ISPF 3 Thu Aug 03, 2017 5:46 pm
No new posts Iterative use of a REXX script causin... bryonyh CLIST & REXX 4 Fri Jul 28, 2017 12:52 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us