Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

gv n lv

Former Member
0 Kudos
1,291

what is the difference between global variable and local variable?

3 REPLIES 3

Former Member
0 Kudos
327

Within a program ---

A global variable is available all through the program, every part of the program.

A local variable is availabe with in the subroutine where you have declared the variable.

It basically depends on the scope of the variable.

Regards,

Ravi

Note - Please mark all the helpful answers

Former Member
0 Kudos
327

Hi,

Variables are named data objects that you can declare statically using declarative statements, or dynamically while a program is running. They allow you to store changeable data under a particular name within the memory area of a program.

You can declare variables statically using the following statements:

DATA: To declare variables whose lifetime is linked to the context of the declaration

STATICS: To declare variables with static validity in procedures

CLASS-DATA: To declare static variables within classes

PARAMETERS: To declare elementary data objects that are also linked to an input field on a selection screen

SELECT-OPTIONS: To declare an internal table that is also linked to input fields on a selection screen

RANGES: To declare an internal table with the same structure as in SELECT-OPTIONS, but without linking it to a selection screen.

Click the link below to know more about Variables.

http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3034358411d1829f0000e829fbfe/content.htm

Global Variables.

Everything mentioned above remains the same for Global variables, except that they are available across the program. If you refer to Global Objects, then they are available across the applications. Remember If the Local and Global variables have same name then the local variable has the more significance in the block/Program/Subroutine/function module than the global variable.

Regards,

Vara

Former Member
0 Kudos
327

Hi

let talk about modulepool.

when youdeclare anything in the top include ,its a global variable and it holds the value until you clear it externally using clear statment.

say if yousing module -


in a particular statment and declaring a variable in side that module then its local to that module,

once you come out of that module it would loose its value automatically.

Hope i am clear

thanks

venki