<?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: Classes definition with CREATE PROTECTED addition in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/classes-definition-with-create-protected-addition/m-p/1813630#M348627</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When using the extension  CREATE PROTECTED, the class can only  be instaniated from the methods of the class itself or by the subclasses.  So in your case, the zl_lcl_counter_prot_Sub class needs to inherit from zl_lcl_counter_prot.  You can change the create_obj method to a static method.  See below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

*----------------------------------------------------------------------*
*       CLASS zl_lcl_counter_prot DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zl_lcl_counter_prot DEFINITION  CREATE PROTECTED.

  PUBLIC SECTION.

    DATA: gv_count_prot TYPE i.

    METHODS constructor.
    METHODS counter IMPORTING set_value TYPE i
    EXPORTING get_value TYPE i.


ENDCLASS.                    "zl_lcl_counter_prot DEFINITION

*----------------------------------------------------------------------*
*       CLASS zl_lcl_counter_prot IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zl_lcl_counter_prot IMPLEMENTATION.

  METHOD counter.

    gv_count_prot = set_value + 1.
    get_value = gv_count_prot.

  ENDMETHOD. "counter

  METHOD constructor.

    WRITE / 'Constructor is called'.

  ENDMETHOD. "constructor

ENDCLASS. "zl_lcl_counter_prot

*----------------------------------------------------------------------*
*       CLASS zl_lcl_counter_prot_sub DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zl_lcl_counter_prot_sub DEFINITION INHERITING FROM zl_lcl_counter_prot.

  PUBLIC SECTION.
    class-METHODS create_obj
    EXPORTING pointer TYPE REF TO zl_lcl_counter_prot.



ENDCLASS.                    "zl_lcl_counter_prot_sub DEFINITION

*----------------------------------------------------------------------*
*       CLASS zl_lcl_counter_prot_sub IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zl_lcl_counter_prot_sub IMPLEMENTATION.

  METHOD create_obj.

    CREATE OBJECT pointer TYPE zl_lcl_counter_prot.

  ENDMETHOD. "create_obj

ENDCLASS.                    "zl_lcl_counter_prot_sub IMPLEMENTATION

DATA: z_cnt_prot TYPE REF TO zl_lcl_counter_prot,
z_cnt_prot_sub TYPE REF TO zl_lcl_counter_prot_sub.

data: gv_counter type i.

START-OF-SELECTION.

*  CREATE OBJECT z_cnt_prot_sub.

* Calling the method of subclass to instantiate the superclass
  zl_lcl_counter_prot_sub=&amp;gt;create_obj( IMPORTING pointer = z_cnt_prot ).

  z_cnt_prot-&amp;gt;counter( EXPORTING set_value = 1
  IMPORTING get_value = gv_counter ).

  WRITE: / gv_counter.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 21 Jan 2007 15:03:10 GMT</pubDate>
    <dc:creator>RichHeilman</dc:creator>
    <dc:date>2007-01-21T15:03:10Z</dc:date>
    <item>
      <title>Classes definition with CREATE PROTECTED addition</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/classes-definition-with-create-protected-addition/m-p/1813629#M348626</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello All, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am defining a class with CREATE PROTECTED addition. My understanding is this class can be instantiated in its subclass. I am using the following code. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS zl_lcl_counter_prot DEFINITION CREATE PROTECTED.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    DATA: gv_count_prot TYPE i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    METHODS constructor.&lt;/P&gt;&lt;P&gt;    METHODS counter IMPORTING set_value TYPE i&lt;/P&gt;&lt;P&gt;                    EXPORTING get_value TYPE i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCLASS. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS zl_lcl_counter_prot IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  METHOD counter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    gv_count_prot = set_value + 1.&lt;/P&gt;&lt;P&gt;    get_value     = gv_count_prot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "counter&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  METHOD constructor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    WRITE / 'Constructor is called'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "constructor&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCLASS.               "zl_lcl_counter_prot&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS zl_lcl_counter_prot_sub DEFINITION INHERITING FROM zl_lcl_counter_pub.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;    METHODS create_obj&lt;/P&gt;&lt;P&gt;            EXPORTING pointer TYPE REF TO zl_lcl_counter_prot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCLASS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS zl_lcl_counter_prot_sub IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  METHOD create_obj.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    CREATE OBJECT pointer TYPE zl_lcl_counter_prot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "create_obj&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCLASS. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: z_cnt_prot        TYPE REF TO zl_lcl_counter_prot,&lt;/P&gt;&lt;P&gt;          z_cnt_prot_sub TYPE REF TO zl_lcl_counter_prot_sub.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  CREATE OBJECT z_cnt_prot_sub.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Calling the method of subclass to instantiate the superclass&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  z_cnt_prot_sub-&amp;gt;create_obj( IMPORTING pointer = z_cnt_prot ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  z_cnt_prot-&amp;gt;counter( EXPORTING set_value = 1&lt;/P&gt;&lt;P&gt;                       IMPORTING get_value = gv_counter ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  WRITE: / gv_counter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am getting an error that I cant create an instance of the protected superclass in the subclass. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could anyone please suggest why this error is coming thought I am using CREATE PROTECTED ADDITION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Indrajit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Jan 2007 13:43:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/classes-definition-with-create-protected-addition/m-p/1813629#M348626</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-01-21T13:43:23Z</dc:date>
    </item>
    <item>
      <title>Re: Classes definition with CREATE PROTECTED addition</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/classes-definition-with-create-protected-addition/m-p/1813630#M348627</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When using the extension  CREATE PROTECTED, the class can only  be instaniated from the methods of the class itself or by the subclasses.  So in your case, the zl_lcl_counter_prot_Sub class needs to inherit from zl_lcl_counter_prot.  You can change the create_obj method to a static method.  See below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

*----------------------------------------------------------------------*
*       CLASS zl_lcl_counter_prot DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zl_lcl_counter_prot DEFINITION  CREATE PROTECTED.

  PUBLIC SECTION.

    DATA: gv_count_prot TYPE i.

    METHODS constructor.
    METHODS counter IMPORTING set_value TYPE i
    EXPORTING get_value TYPE i.


ENDCLASS.                    "zl_lcl_counter_prot DEFINITION

*----------------------------------------------------------------------*
*       CLASS zl_lcl_counter_prot IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zl_lcl_counter_prot IMPLEMENTATION.

  METHOD counter.

    gv_count_prot = set_value + 1.
    get_value = gv_count_prot.

  ENDMETHOD. "counter

  METHOD constructor.

    WRITE / 'Constructor is called'.

  ENDMETHOD. "constructor

ENDCLASS. "zl_lcl_counter_prot

*----------------------------------------------------------------------*
*       CLASS zl_lcl_counter_prot_sub DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zl_lcl_counter_prot_sub DEFINITION INHERITING FROM zl_lcl_counter_prot.

  PUBLIC SECTION.
    class-METHODS create_obj
    EXPORTING pointer TYPE REF TO zl_lcl_counter_prot.



ENDCLASS.                    "zl_lcl_counter_prot_sub DEFINITION

*----------------------------------------------------------------------*
*       CLASS zl_lcl_counter_prot_sub IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zl_lcl_counter_prot_sub IMPLEMENTATION.

  METHOD create_obj.

    CREATE OBJECT pointer TYPE zl_lcl_counter_prot.

  ENDMETHOD. "create_obj

ENDCLASS.                    "zl_lcl_counter_prot_sub IMPLEMENTATION

DATA: z_cnt_prot TYPE REF TO zl_lcl_counter_prot,
z_cnt_prot_sub TYPE REF TO zl_lcl_counter_prot_sub.

data: gv_counter type i.

START-OF-SELECTION.

*  CREATE OBJECT z_cnt_prot_sub.

* Calling the method of subclass to instantiate the superclass
  zl_lcl_counter_prot_sub=&amp;gt;create_obj( IMPORTING pointer = z_cnt_prot ).

  z_cnt_prot-&amp;gt;counter( EXPORTING set_value = 1
  IMPORTING get_value = gv_counter ).

  WRITE: / gv_counter.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Jan 2007 15:03:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/classes-definition-with-create-protected-addition/m-p/1813630#M348627</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2007-01-21T15:03:10Z</dc:date>
    </item>
  </channel>
</rss>

