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

Use of Static variable for storage purpose


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Prabha
Warnings : 2

New User


Joined: 05 Dec 2005
Posts: 79

PostPosted: Fri Feb 22, 2008 3:07 pm
Reply with quote

Hi,

Can anyone explain me the usage of static varible. Is static varible is only for storage purpose or to keep value. Please explain me with examples. I searched in other forums. But it was not clear.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Fri Feb 22, 2008 6:02 pm
Reply with quote

Can you provide a link to where you found a reference to the term static variable?
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Fri Feb 22, 2008 7:05 pm
Reply with quote

In your terms, what is the difference between "storage purposes" and "keep a value"?

STATIC vars are a PL/I concept. From a web-link:

Quote:
Storage. PL/I provides a number of storage attributes. The default is AUTOMATIC, which is allocated on entry to a block, possibly with initialization, and freed at exit. STATIC storage exists throughout the life of the program,
Back to top
View user's profile Send private message
ruodeer

New User


Joined: 06 Jul 2007
Posts: 58
Location: home

PostPosted: Fri Feb 22, 2008 8:19 pm
Reply with quote

as saying:static for batch program..automatic for online program.
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: Fri Feb 22, 2008 8:37 pm
Reply with quote

Do you mean an Assembler constant (DC)?

Code:

EYECTCHR DC    CL38'HELLO, I AM A CONSTANT, LEAVE ME ALONE'


HTH....

Regards,

Bill
Back to top
View user's profile Send private message
u770624

New User


Joined: 12 Jul 2006
Posts: 2
Location: Blighty

PostPosted: Tue Mar 04, 2008 3:40 am
Reply with quote

Illustration on use of static variables ...
Module_A calls Module_B ( and it can do so many times )
Module_B needs to know when it is called for the first time (probably as an efficiency measure)

Therefore Module_B declares a STATIC variable and initialises it to a known value.

Module_B checks the static variable every time it is called and if it is the known, initiallised value then it is the first time it is called. Module_B then performs the first time logic AND sets the static variable to a different value.
On subsequent calls, the value is no longer the initiallised value.

If it was not a static variable then it would be a dynamic variable and would be set to the initiallised value every time Module_B was called.
Back to top
View user's profile Send private message
Mistermind

New User


Joined: 08 Feb 2008
Posts: 46
Location: Dublin

PostPosted: Sun Mar 16, 2008 1:59 am
Reply with quote

Static storage is mapped just once inside the PL/I loadmodule, similar to WORKING-STORAGE variable in cobol. Automatic variables are allocated new storage space each time you invoke the subroutine B, so if your subroutine B declares AUTO variables, your partition will very quickly run out of space. This problem will not arise if STATIC variable is declared. If subroutine needs to ensure a certain value in a static variable, e.g. zero, it can be set each time subroutine gains control.

PL/I STATIC variables are also easier to find in storage, always addressed by register 3.
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 -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts CLIST - Virtual storage allocation error CLIST & REXX 5
No new posts CICS vs LE: STORAGE option CICS 0
No new posts Variable Output file name DFSORT/ICETOOL 8
No new posts Insufficient Storage ABENDS & Debugging 7
Search our Forums:

Back to Top