‎2008 May 14 1:27 PM
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
‎2008 May 14 1:43 PM
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
‎2008 May 14 1:50 PM
Hello,
You need to create a public attribute in the class/method and pass the global variable into it.
Regards,
‎2008 May 14 2:01 PM
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.
‎2008 May 14 3:16 PM
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
‎2008 May 15 7:13 AM
‎2008 May 15 9:15 AM
‎2008 May 15 9:41 AM