<?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: accessing protected class in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/accessing-protected-class/m-p/3788309#M911362</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is it that you want to access? The static methods and attributes can be access without any problems like this:&lt;/P&gt;&lt;P&gt;  DATA: gc_formfield TYPE string.&lt;/P&gt;&lt;P&gt;  gc_formfield = cl_http_server=&amp;gt;co_form_field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But this is only possible if the attribute is public, otherwise you will have to create an instance of the class as well to access it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If, however, you want to access the instance attributes you will have to create the instance first like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT zzz_test3.



*----------------------------------------------------------------------*
*       CLASS lcl_user DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_user DEFINITION INHERITING FROM cl_user_defaults CREATE PUBLIC.

  PUBLIC SECTION.

    DATA: gr_user TYPE syuname.


ENDCLASS.                    "lcl_user DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_user IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_user IMPLEMENTATION.



ENDCLASS.                    "lcl_user IMPLEMENTATION

START-OF-SELECTION.

  DATA: gr_defaults TYPE REF TO lcl_user,
        gt_defaults TYPE usrdflt_itab,
        wa_defaults LIKE LINE OF gt_defaults.

  CREATE OBJECT gr_defaults
       EXPORTING
          iv_calling_program = sy-repid.

  gt_defaults = gr_defaults-&amp;gt;get( ).

  LOOP AT gt_defaults INTO wa_defaults.

  ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nothing really happens here, but I just want to show you how you instantiate this class and have access to the instance methods and attributes.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 08 May 2008 12:20:26 GMT</pubDate>
    <dc:creator>Sm1tje</dc:creator>
    <dc:date>2008-05-08T12:20:26Z</dc:date>
    <item>
      <title>accessing protected class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/accessing-protected-class/m-p/3788307#M911360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;how to access the protected class in OOABAP..can any one help me with sample code&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 May 2008 11:07:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/accessing-protected-class/m-p/3788307#M911360</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-08T11:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: accessing protected class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/accessing-protected-class/m-p/3788308#M911361</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;Data declared in the protected section can be accessed by the class itself,  and also by its subclasses but not by external users outside the class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS parentclass DEFINITION .&lt;/P&gt;&lt;P&gt; PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;  DATA : commondata(30) type c value 'Accessible to all'.&lt;/P&gt;&lt;P&gt;  METHODS : SHOWVAL.&lt;/P&gt;&lt;P&gt; PROTECTED SECTION.&lt;/P&gt;&lt;P&gt;  DATA : protectdata(40) type c value 'Protected data'.&lt;/P&gt;&lt;P&gt; private section.&lt;/P&gt;&lt;P&gt; data : privatedata(30) type c value 'Private data'.&lt;/P&gt;&lt;P&gt; ENDCLASS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; CLASS parentclass IMPLEMENTATION.&lt;/P&gt;&lt;P&gt; METHOD : SHOWVAL.&lt;/P&gt;&lt;P&gt;  write:/5 'All data from parentclass shown:-'.&lt;/P&gt;&lt;P&gt;  write:/ sy-uline.&lt;/P&gt;&lt;P&gt;  WRITE:/5 COMMONDATA,&lt;/P&gt;&lt;P&gt;        /5 PROTECTDATA,&lt;/P&gt;&lt;P&gt;        /5 PRIVATEDATA.&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 childclass DEFINITION INHERITING FROM parentclass.&lt;/P&gt;&lt;P&gt; PUBLIC SECTION .&lt;/P&gt;&lt;P&gt; METHODS : subval.&lt;/P&gt;&lt;P&gt; ENDCLASS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; CLASS childclass IMPLEMENTATION.&lt;/P&gt;&lt;P&gt; method : subval.&lt;/P&gt;&lt;P&gt;  skip 1.&lt;/P&gt;&lt;P&gt;  write:/5 'Data of parent shown from child-'.&lt;/P&gt;&lt;P&gt;  write:/5 sy-uline.&lt;/P&gt;&lt;P&gt;  WRITE:/5 COMMONDATA,&lt;/P&gt;&lt;P&gt;        /5 PROTECTDATA.&lt;/P&gt;&lt;P&gt;  Commondata = 'Public data changed in subclass'.&lt;/P&gt;&lt;P&gt;  Protectdata = 'Protected data changed in subclass'.&lt;/P&gt;&lt;P&gt;  write:/5 sy-uline.&lt;/P&gt;&lt;P&gt;  WRITE:/5 COMMONDATA,&lt;/P&gt;&lt;P&gt;        /5 PROTECTDATA.&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;START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;   DATA : parent type ref to parentclass ,&lt;/P&gt;&lt;P&gt;          child  type ref to childclass  .&lt;/P&gt;&lt;P&gt;   create object : parent ,&lt;/P&gt;&lt;P&gt;                   child  .&lt;/P&gt;&lt;P&gt;   call method : parent-&amp;gt;showval ,&lt;/P&gt;&lt;P&gt;                 child-&amp;gt;subval.&lt;/P&gt;&lt;P&gt;      skip 2.&lt;/P&gt;&lt;P&gt;  parent-&amp;gt;commondata = &amp;#145;User changing public data&amp;#146;.&lt;/P&gt;&lt;P&gt;  write:/5 parent-&amp;gt;commondata.&lt;/P&gt;&lt;P&gt;Output&lt;/P&gt;&lt;P&gt; All data from parentclass shown:-   &lt;/P&gt;&lt;P&gt;                                     &lt;/P&gt;&lt;P&gt; Accessible to all                   &lt;/P&gt;&lt;P&gt; Protected data                      &lt;/P&gt;&lt;P&gt; Private data                        &lt;/P&gt;&lt;P&gt;                                     &lt;/P&gt;&lt;P&gt; Data of parent shown from child-    &lt;/P&gt;&lt;P&gt;                                     &lt;/P&gt;&lt;P&gt; Accessible to all                   &lt;/P&gt;&lt;P&gt; Protected data                      &lt;/P&gt;&lt;P&gt;                                     &lt;/P&gt;&lt;P&gt; Public data changed in subclas      &lt;/P&gt;&lt;P&gt; Protected data changed in subclass                                                                                &lt;/P&gt;&lt;P&gt;User changing public data      &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If access outside of class &lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-----------------------------------------" /&gt;&lt;P&gt;CLASS c1 DEFINITION .&lt;/P&gt;&lt;P&gt; PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;  DATA : commondata(30) type c value 'Accessible to all'.&lt;/P&gt;&lt;P&gt; PROTECTED SECTION.&lt;/P&gt;&lt;P&gt;  DATA : protectdata(40) type c value 'Protected data'.&lt;/P&gt;&lt;P&gt; private section.&lt;/P&gt;&lt;P&gt; data : privatedata(30) type c value 'Private data'.&lt;/P&gt;&lt;P&gt; ENDCLASS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; CLASS c1 IMPLEMENTATION.&lt;/P&gt;&lt;P&gt; endclass.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;   DATA : obj1 type ref to c1.&lt;/P&gt;&lt;P&gt;   create object : obj1.&lt;/P&gt;&lt;P&gt;   write:/5 obj1-&amp;gt;protectdata ,&lt;/P&gt;&lt;P&gt;            obj1-&amp;gt;privatedata.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  it gives compilation error  will be generated which will prove that protected and private components of a class cannot be accessed by external users.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Reward points.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 May 2008 12:13:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/accessing-protected-class/m-p/3788308#M911361</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-08T12:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: accessing protected class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/accessing-protected-class/m-p/3788309#M911362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is it that you want to access? The static methods and attributes can be access without any problems like this:&lt;/P&gt;&lt;P&gt;  DATA: gc_formfield TYPE string.&lt;/P&gt;&lt;P&gt;  gc_formfield = cl_http_server=&amp;gt;co_form_field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But this is only possible if the attribute is public, otherwise you will have to create an instance of the class as well to access it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If, however, you want to access the instance attributes you will have to create the instance first like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT zzz_test3.



*----------------------------------------------------------------------*
*       CLASS lcl_user DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_user DEFINITION INHERITING FROM cl_user_defaults CREATE PUBLIC.

  PUBLIC SECTION.

    DATA: gr_user TYPE syuname.


ENDCLASS.                    "lcl_user DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_user IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_user IMPLEMENTATION.



ENDCLASS.                    "lcl_user IMPLEMENTATION

START-OF-SELECTION.

  DATA: gr_defaults TYPE REF TO lcl_user,
        gt_defaults TYPE usrdflt_itab,
        wa_defaults LIKE LINE OF gt_defaults.

  CREATE OBJECT gr_defaults
       EXPORTING
          iv_calling_program = sy-repid.

  gt_defaults = gr_defaults-&amp;gt;get( ).

  LOOP AT gt_defaults INTO wa_defaults.

  ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nothing really happens here, but I just want to show you how you instantiate this class and have access to the instance methods and attributes.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 May 2008 12:20:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/accessing-protected-class/m-p/3788309#M911362</guid>
      <dc:creator>Sm1tje</dc:creator>
      <dc:date>2008-05-08T12:20:26Z</dc:date>
    </item>
  </channel>
</rss>

