2007 Aug 23 10:58 AM
Hi,
As it's documented in SAP help :
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5c54f411d194a60000e8353423/frameset.htm
"
Special Methods
As well as normal methods, which you call using CALL METHOD, there are two special methods called CONSTRUCTOR and CLASS_CONSTRUCTOR, which are automatically called when you create an object (CONSTRUCTOR) or when you first access the components of a class (CLASS_CONSTRUCTOR).
"
CLASS_CONSTRUCTOR should be called before you can access to any static component.
I sayed Should.... because on a inherited class this is not true.
If you create a class A with statics attribute VER (string)
You create a class B inhireting from A
You build class_constructor for both class A & B seting ver to : "Class A" and "Class B" to know with class_constructor is called
You'll realize that class_constructor of class B is NOT called.
Using test tool of SE24 let you realize that CLASS_CONSTUCTOR is not called on the first static access but on instance creation ! ?? !
If any one has an solution for this I'll be happy to know it.
Hi,
As it's documented in SAP help :
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5c54f411d194a60000e8353423/frameset.htm
"
Special Methods
As well as normal methods, which you call using CALL METHOD, there are two special methods called CONSTRUCTOR and CLASS_CONSTRUCTOR, which are automatically called when you create an object (CONSTRUCTOR) or when you first access the components of a class (CLASS_CONSTRUCTOR).
"
CLASS_CONSTRUCTOR should be called before you can access to any static component.
I sayed Should.... because on a inherited class this is not true.
If you create a class A with statics attribute VER (string)
You create a class B inhireting from A
You build class_constructor for both class A & B seting ver to : "Class A" and "Class B" to know with class_constructor is called
You'll realize that class_constructor of class B is NOT called.
Using test tool of SE24 let you realize that CLASS_CONSTUCTOR is not called on the first static access but on instance creation ! ?? !
If any one has an solution for this I'll be happy to know it.
2007 Aug 23 11:00 AM
Please find SAPLINK nugget providing class A & B :
<?xml version="1.0" encoding="utf-16"?>
<nugget name="CLASS_CONSTRUCTOR_TEST">
<CLAS CLSNAME="YA" VERSION="1" LANGU="F" DESCRIPT="dfdfd" UUID="46CA7A6674E61D75E1000000AC1E9ACA" CATEGORY="00" EXPOSURE="2" STATE="1" RELEASE="0" AUTHOR="TBENSIALI" CREATEDON="20070821" CHANGEDBY="TBENSIALI" CHANGEDON="20070821" CHGDANYON="00000000" CLSCCINCL="X" FIXPT="X" UNICODE="X" R3RELEASE="700" CLSBCCAT="00" DURATION_TYPE="0 " RISK_LEVEL="0 ">
<publicSection>class YA definition
public
create public .
" public components of class YA
" do not include other source files here!!!
public section.
class-data VER type STRING read-only .
methods CONSTRUCTOR .
class-methods CLASS_CONSTRUCTOR .</publicSection>
<protectedSection>" protected components of class YA
" do not include other source files here!!!
protected section.</protectedSection>
<privateSection>" private components of class YA
" do not include other source files here!!!
private section.</privateSection>
<localImplementation>" local class implementation for public class
" use this source file for the implementation part of
" local helper classes</localImplementation>
<localTypes>" use this source file for any type declarations (class
" definitions, interfaces or data types) you need for method
" implementation or private method's signature</localTypes>
<localMacros>" use this source file for any macro definitions you need
" in the implementation part of the class</localMacros>
<attribute CLSNAME="YA" CMPNAME="VER" VERSION="1" LANGU="F" EXPOSURE="2" STATE="1" EDITORDER="1 " AUTHOR="TBENSIALI" CREATEDON="20070821" CHANGEDON="00000000" ATTDECLTYP="1" ATTRDONLY="X" ATTEXPVIRT="0" TYPTYPE="1" TYPE="STRING" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " R3RELEASE="700" TYPESRC_LENG="0 "/>
<method CLSNAME="YA" CMPNAME="CLASS_CONSTRUCTOR" VERSION="1" LANGU="F" DESCRIPT="CLASS_CONSTRUCTOR" EXPOSURE="2" STATE="1" EDITORDER="2 " DISPID="0 " AUTHOR="TBENSIALI" CREATEDON="20070821" CHANGEDBY="TBENSIALI" CHANGEDON="20070823" MTDTYPE="2" MTDDECLTYP="1" R3RELEASE="700" BCMTDCAT="00" BCMTDSYN="0">
<source>method CLASS_CONSTRUCTOR.
VER = 'YA=>CLASS_CONSTRUCTOR'.
endmethod.</source>
</method>
<method CLSNAME="YA" CMPNAME="CONSTRUCTOR" VERSION="1" LANGU="F" DESCRIPT="CONSTRUCTOR" EXPOSURE="2" STATE="1" EDITORDER="1 " DISPID="0 " AUTHOR="TBENSIALI" CREATEDON="20070823" CHANGEDON="00000000" MTDTYPE="2" MTDDECLTYP="0" R3RELEASE="700" BCMTDCAT="00" BCMTDSYN="0">
<source>method CONSTRUCTOR.
VER = 'YA=>CONSTRUCTOR'.
endmethod.</source>
</method>
</CLAS>
<CLAS CLSNAME="YB" VERSION="1" LANGU="F" DESCRIPT="hghfghfhfh" UUID="46CA950B721620B5E1000000AC1E9ACA" CATEGORY="00" EXPOSURE="2" STATE="1" RELEASE="0" AUTHOR="TBENSIALI" CREATEDON="20070821" CHANGEDBY="TBENSIALI" CHANGEDON="00000000" CHGDANYON="00000000" CLSCCINCL="X" FIXPT="X" UNICODE="X" R3RELEASE="700" CLSBCCAT="00" DURATION_TYPE="0 " RISK_LEVEL="0 " REFCLSNAME="YA">
<publicSection>class YB definition
public
inheriting from YA
create public .
" public components of class YB
" do not include other source files here!!!
public section.
methods CONSTRUCTOR .
class-methods CLASS_CONSTRUCTOR .</publicSection>
<protectedSection>" protected components of class YB
" do not include other source files here!!!
protected section.</protectedSection>
<privateSection>" private components of class YB
" do not include other source files here!!!
private section.</privateSection>
<localImplementation>" local class implementation for public class
" use this source file for the implementation part of
" local helper classes</localImplementation>
<localTypes>" use this source file for any type declarations (class
" definitions, interfaces or data types) you need for method
" implementation or private method's signature</localTypes>
<localMacros>" use this source file for any macro definitions you need
" in the implementation part of the class</localMacros>
<inheritance CLSNAME="YB" REFCLSNAME="YA" VERSION="1" STATE="1" AUTHOR="TBENSIALI" CREATEDON="20070821" CHANGEDON="00000000"/>
<method CLSNAME="YB" CMPNAME="CLASS_CONSTRUCTOR" VERSION="1" LANGU="F" DESCRIPT="CLASS_CONSTRUCTOR" EXPOSURE="2" STATE="1" EDITORDER="2 " DISPID="0 " AUTHOR="TBENSIALI" CREATEDON="20070821" CHANGEDBY="TBENSIALI" CHANGEDON="20070823" MTDTYPE="2" MTDDECLTYP="1" R3RELEASE="700" BCMTDCAT="00" BCMTDSYN="0">
<source>method CLASS_CONSTRUCTOR.
VER = 'YB=>CLASS_CONSTRUCTOR'.
endmethod.</source>
</method>
<method CLSNAME="YB" CMPNAME="CONSTRUCTOR" VERSION="1" LANGU="F" DESCRIPT="CONSTRUCTOR" EXPOSURE="2" STATE="1" EDITORDER="1 " DISPID="0 " AUTHOR="TBENSIALI" CREATEDON="20070823" CHANGEDON="00000000" MTDTYPE="2" MTDDECLTYP="0" R3RELEASE="700" BCMTDCAT="00" BCMTDSYN="0">
<source>METHOD constructor.
CALL METHOD super->constructor.
VER = 'YB=>CONSTRUCTOR'.
ENDMETHOD.</source>
</method>
</CLAS>
</nugget>
2007 Aug 23 11:06 AM
Answer found in SAP Help :
<a href="http://help.sap.com/saphelp_47x200/helpdata/en/dd/4049c40f4611d3b9380000e8353423/frameset.htm">http://help.sap.com/saphelp_47x200/helpdata/en/dd/4049c40f4611d3b9380000e8353423/frameset.htm</a>
Inheritance and Static Attributes
Like all components, static attributes only exist once in each inheritance tree. A subclass can access the public and protected static attributes of all of its superclasses. Conversely, a superclass shares its public and protected static attributes with all of its subclasses. In terms of inheritance, static attributes are not assigned to a single class, but to a part of the inheritance tree. You can change them from outside the class using the class component selector with any class name, or within any class in which they are shared. They are visible in all classes in the inheritance tree.
When you address a static attribute that belongs to part of an inheritance tree, you always address the class in which the attribute is declared, irrespective of the class you specify in the class selector. This is particularly important when you call the static constructors of classes in inheritance. Static constructors are executed the first time you address a class. <u><b>If you address a static attribute declared in a superclass using the class name of a subclass, only the static constructor of the superclass is executed.</b></u>
2007 Aug 23 11:18 AM
It's strange, because when you add on class B a static component and access to it like :
write 😕 YB=>VER.
write 😕 YB=>TEST.
write 😕 YB=>VER.
you've got :
YB=>CLASS_CONSTRUCTOR
TEST
YB=>CLASS_CONSTRUCTOR
But if you simply do :
write 😕 YB=>VER.
You've got :
<u><b>YA</b></u>=>CLASS_CONSTRUCTOR
This means that previous execution of code 'write 😕 YB=>VER.' is impacted by later code 'write 😕 YB=>TEST.' !!!
Thanks SAP to be so complicated we won't get bored for the next ten years...
:-s
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |