Application Development and Automation 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: 
Read only

Local Variables Versus Global Variables

Former Member
0 Likes
719

DATA A TYPE I VALUE 100.

PERFORM PRINT_DATA.

FORM PRINT_DATA.

DATA A(10) TYPE C 'HELLO'.

WRITE / A. "Wanted to Print 100 (Global)

WRITE / A. "Wanted to Print 'HELLO'(Local)

ENDFORM.

Note : Both the times, the Local Variable 'A' is Printed .

?Is there any way to Differentiate the Local and Global Variables When the Names Are Same.*

*It Might be Possible in Object Oriented But I am Looking for the Same in FORMs.

DATA A TYPE I VALUE 100.

PERFORM PRINT_DATA.

FORM PRINT_DATA.

DATA A(10) TYPE C 'HELLO'.

WRITE / A. "Wanted to Print 100 (Global)

WRITE / A. "Wanted to Print 'HELLO'(Local)

ENDFORM.

Note : Both the times, the Local Variable 'A' is Printed .

?Is there any way to Differentiate the Local and Global Variables When the Names Are Same.*

*It Might be Possible in Object Oriented But I am Looking for the Same in FORMs.

3 REPLIES 3
Read only

ThomasZloch
Active Contributor
0 Likes
642

Local declarations are masking global declarations. Using identical names is extremely bad programming style.

Solution: do not use global variables, and if you must, prefix them with "g_", for example.

Thomas

Read only

former_member229034
Participant
0 Likes
642

Hello Gagan,

You want to print the Global as well as the local values of the variable named "A". Here are a couple of approaches:

1.The 'Subroutines' are part of the modularization techniques. There are certain keywords like "using" & "Changing" so that you can work by passing Values.

2. There is a keyword named "LOCAL". Declare data object with the keyword "LOCAL" and then try the 'write" statement. I suppose this should work for you.

Let me know if any one of the above works or if you need more help.

Best Regards,

Chaitanya

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
642

Check the f1 help of statements STATICS and LOCAL.