<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Execution of class_constructors in subclass in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/execution-of-class-constructors-in-subclass/m-p/4634046#M1091203</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thx for the reply...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it did execute the superclass's c-c, but my question is, why did it not execute the subclass's (i.e. class b ) c-c which was to write "&lt;STRONG&gt;Subclass constructor&lt;/STRONG&gt;" even though class b was addressed by using b=&amp;gt;d ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Oct 2008 15:00:02 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-10-15T15:00:02Z</dc:date>
    <item>
      <title>Execution of class_constructors in subclass</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/execution-of-class-constructors-in-subclass/m-p/4634044#M1091201</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi all, i'm new to abap objects but the testing the code below puzzles me.  can anyone explain why if i execute WRITE b=&amp;gt;d, the sub class_constructor is not executed?  i would expect that after executing the super c-c, the sub c-c is next.  as expected, only the super c-c is executed for WRITE a=&amp;gt;d.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i had read, once a subclass is addressed, the c-c is executed if it hasn't been yet, after all unperformed super c-c's are executed.  but why when addressing b=&amp;gt;d not perform it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS a DEFINITION.&lt;/P&gt;&lt;P&gt;  PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;    CLASS-DATA d TYPE c VALUE 'D'.&lt;/P&gt;&lt;P&gt;    CLASS-METHODS class_constructor.&lt;/P&gt;&lt;P&gt;ENDCLASS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS b DEFINITION INHERITING FROM a.&lt;/P&gt;&lt;P&gt;  PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;    CLASS-METHODS class_constructor..&lt;/P&gt;&lt;P&gt;ENDCLASS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS a IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;  METHOD class_constructor.&lt;/P&gt;&lt;P&gt;    WRITE:/ 'Superclass constructor'.&lt;/P&gt;&lt;P&gt;  ENDMETHOD.&lt;/P&gt;&lt;P&gt;ENDCLASS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS b IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;  METHOD class_constructor.&lt;/P&gt;&lt;P&gt;    WRITE:/ 'Subclass constructor'.&lt;/P&gt;&lt;P&gt;  ENDMETHOD.&lt;/P&gt;&lt;P&gt;ENDCLASS.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2008 13:59:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/execution-of-class-constructors-in-subclass/m-p/4634044#M1091201</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-15T13:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: Execution of class_constructors in subclass</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/execution-of-class-constructors-in-subclass/m-p/4634045#M1091202</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;please take a look at the code below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
report  zzztest.

class a definition.
  public section.
    class-data d type c value 'D'.
    class-methods class_constructor.
endclass.                    "a DEFINITION

class b definition inheriting from a.
  public section.
    class-methods class_constructor..
endclass.                    "b DEFINITION

class a implementation.
  method class_constructor.
    write:/ 'Superclass constructor'.
  endmethod.                    "class_constructor
endclass.                    "a IMPLEMENTATION

class b implementation.
  method class_constructor.
    write:/ 'Subclass constructor'.
  endmethod.                    "class_constructor
endclass.                    "b IMPLEMENTATION

*data l_b type ref to b.

end-of-selection.

  write / 'Start'.
  write / b=&amp;gt;d.
  write / 'End'
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code will produce the following output:&lt;/P&gt;&lt;P&gt;Superclass constructor&lt;/P&gt;&lt;P&gt;Start&lt;/P&gt;&lt;P&gt;D&lt;/P&gt;&lt;P&gt;End&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can see that  the class constructor is executed before the call to write B=&amp;gt;D. I think it is not exactly defined when the class_constructor is executed, but the class constructor is executed before the first object is craeted. In this case this happens before the program starts. It is not related to the write statement. It is related to the definition of the classes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Matthias&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2008 14:42:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/execution-of-class-constructors-in-subclass/m-p/4634045#M1091202</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-15T14:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: Execution of class_constructors in subclass</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/execution-of-class-constructors-in-subclass/m-p/4634046#M1091203</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thx for the reply...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it did execute the superclass's c-c, but my question is, why did it not execute the subclass's (i.e. class b ) c-c which was to write "&lt;STRONG&gt;Subclass constructor&lt;/STRONG&gt;" even though class b was addressed by using b=&amp;gt;d ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2008 15:00:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/execution-of-class-constructors-in-subclass/m-p/4634046#M1091203</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-15T15:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: Execution of class_constructors in subclass</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/execution-of-class-constructors-in-subclass/m-p/4634047#M1091204</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; b=&amp;gt;d  is a static component. There is no need to instantiante a class b (= calling the constructor) and this means that the class to the class_constructor is deferred as well. The only thing which is for shure is that the class_constructor of B is called before the constructor of B. But up to now this is not necessary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you do the following the class_constructor of B is called.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
report  zzztest.

class a definition.
  public section.
    class-data d type c value 'D'.
    class-methods class_constructor.
    methods constructor.
endclass.                    "a DEFINITION

class b definition inheriting from a.
  public section.
    class-methods class_constructor.
    methods constructor.
endclass.                    "b DEFINITION

class a implementation.
  method class_constructor.
    write:/ 'Superclass class constructor'.
  endmethod.                    "class_constructor
  method constructor.
    write:/ 'Superclass constructor'.
  endmethod.                    "class_constructor
endclass.                    "a IMPLEMENTATION

class b implementation.
  method class_constructor.
    write:/ 'Subclass class constructor'.
  endmethod.                    "class_constructor
  method constructor.
    super-&amp;gt;constructor( ).
    write:/ 'Subclass constructor'.
  endmethod.                    "class_constructor

endclass.                    "b IMPLEMENTATION

data l_b type ref to b.

end-of-selection.

  write / 'Start'.
  create object l_b.
  write / b=&amp;gt;d.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The output is:&lt;/P&gt;&lt;P&gt;Superclass class constructor&lt;/P&gt;&lt;P&gt;Start&lt;/P&gt;&lt;P&gt;Subclass class constructor&lt;/P&gt;&lt;P&gt;Superclass constructor&lt;/P&gt;&lt;P&gt;Subclass constructor&lt;/P&gt;&lt;P&gt;D&lt;/P&gt;&lt;P&gt;End&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please be aware the a class_constructor is only called once for each class. The constructor is called for each object.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards Matthias&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2008 15:47:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/execution-of-class-constructors-in-subclass/m-p/4634047#M1091204</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-15T15:47:49Z</dc:date>
    </item>
    <item>
      <title>Re: Execution of class_constructors in subclass</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/execution-of-class-constructors-in-subclass/m-p/4634048#M1091205</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thx...although not the answer i was looking for, nevertheless, it lead me to this....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if i add a static data in subclass b ( say CLASS-DATA e, and address that, i.e. b=&amp;gt;e, both the super c-c and sub c-c are called.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thx matthias, points awarded.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2008 17:02:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/execution-of-class-constructors-in-subclass/m-p/4634048#M1091205</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-15T17:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: Execution of class_constructors in subclass</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/execution-of-class-constructors-in-subclass/m-p/4634049#M1091206</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;. I think it is not exactly defined when the class_constructor is executed,&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not correct.  That would be a serious design fault.   It is &lt;STRONG&gt;exactly&lt;/STRONG&gt; defined.   If A is the superclass of B, then the class constructor of A is guaranteed to run before B.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As appears to have been worked out, accessing an inherited &lt;STRONG&gt;component&lt;/STRONG&gt; of A, that is not overridden in B, using B=&amp;gt;&lt;STRONG&gt;component&lt;/STRONG&gt;, does not, in fact, touch B, hence the class-constructor of B isn't called.  Which is quite interesting.  From a design point of view, I can't see it causes a problem.  Because as soon as you touch B directly, the class-constructor of B will run.  And there's no way that the A-class-constructor could be (or should be) dependent on the B-class-constructor running.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2008 18:45:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/execution-of-class-constructors-in-subclass/m-p/4634049#M1091206</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2008-10-15T18:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: Execution of class_constructors in subclass</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/execution-of-class-constructors-in-subclass/m-p/4634050#M1091207</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Matt, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks for the clarification. But this was exactly what I wanted to say. The statement you refering to should say, that the point in time in not exactly defined. Of course it is clear that the order of calls must be defined and is defined. I stated this as well in my reply. Please read my message Posted: Oct 15, 2008 5:47 PM  as well. What we observe here is that the call to the class constructor is deferred until it it really necessary. This is what I mean, when I am saying that "when" (= point in time) the class constructor is called. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this makes it clear. Sorry for the confusion.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards Matthias&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2008 20:54:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/execution-of-class-constructors-in-subclass/m-p/4634050#M1091207</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-15T20:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: Execution of class_constructors in subclass</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/execution-of-class-constructors-in-subclass/m-p/4634051#M1091208</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Fair enough - still, an interesting question I'd not considered before.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Oct 2008 08:46:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/execution-of-class-constructors-in-subclass/m-p/4634051#M1091208</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2008-10-16T08:46:40Z</dc:date>
    </item>
  </channel>
</rss>

