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

how to access global variable in class interface

former_member5472
Active Contributor
0 Likes
4,727

Hi,

i have declared a global variable i_variable in top include.

i have declared a method, where i want to use the global variable.

my class interface is throwing error that the varaible is not declared.

can anyone help me, how to include the declaration in my class interface.

thanks

pratyush

7 REPLIES 7
Read only

matt
Active Contributor
0 Likes
2,386

I assume the class is local to your ABAP? Global variables are not visible within classes. If you want to have a variable visible in all methods, it must be defined as an attribute of the class (private, protected or public), or superclass (protected or public).

matt

Read only

Former Member
0 Likes
2,386

Hello,

You need to create a public attribute in the class/method and pass the global variable into it.

Regards,

Read only

0 Likes
2,386

Hi,

thanks for your response.

the value of the variable is set inside the method, and the global variable is declared in top include. the same global variable is used in some other FM .

so i have to assign the attribute value to global variable to make it visible across the Function Group.

actually the scenario is like this,

i have redifined SAP standard class . the methods in the class are triggred based on actions done by end users. so i'm not sure which method will be trigerred first and thats why i'm confused where to set the attribute value ? i.e if i have written code to set the attribute value inside one method and if users dosen't trigers the method than , my global variable won't be set.

Read only

matt
Active Contributor
0 Likes
2,386

Set the attribute, which should be static, in the CLASS-CONSTRUCTOR. Then it will be set the first time there is a reference to the class.

This is precisely the scenario that constructors were designed to deal with.

matt

Read only

0 Likes
2,386

Hi,

thanks for the replies

Read only

matt
Active Contributor
0 Likes
2,386

Now mark the question answered!

Read only

former_member5472
Active Contributor
0 Likes
2,386

thanks