<?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: Narrow casting in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4488898#M1062525</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Suresh&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to see a rather weird (yet useful) narrow casting to the root class (OBJECT) you may have a look at my Wiki posting [Accessing the Inacessible - Local Classes within Global Classes|https://wiki.sdn.sap.com/wiki/display/ABAP/Accessing&lt;EM&gt;the&lt;/EM&gt;Inacessible&lt;EM&gt;-&lt;/EM&gt;Local&lt;EM&gt;Classes&lt;/EM&gt;within&lt;EM&gt;Global&lt;/EM&gt;Classes]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;  Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 12 Sep 2008 20:18:22 GMT</pubDate>
    <dc:creator>uwe_schieferstein</dc:creator>
    <dc:date>2008-09-12T20:18:22Z</dc:date>
    <item>
      <title>Narrow casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4488893#M1062520</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;i done coding for narrow casting but iam not getting proper output.can you please explain the narrow casting using below code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;class c1 definition.&lt;/P&gt;&lt;P&gt;public section.&lt;/P&gt;&lt;P&gt;methods : m1.&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;method m1.&lt;/P&gt;&lt;P&gt;data m1 type i value 2.&lt;/P&gt;&lt;P&gt;write:/ m1.&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 c2 definition inheriting from c1.&lt;/P&gt;&lt;P&gt;public section .&lt;/P&gt;&lt;P&gt;methods m2.&lt;/P&gt;&lt;P&gt;endclass.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;class c2 implementation.&lt;/P&gt;&lt;P&gt;method m2.&lt;/P&gt;&lt;P&gt;data m2 type i value 3.&lt;/P&gt;&lt;P&gt;write:/ m2.&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 obj type ref to c1.&lt;/P&gt;&lt;P&gt;data obj1 type ref to c2.&lt;/P&gt;&lt;P&gt; CREATE object obj1.&lt;/P&gt;&lt;P&gt; obj = obj1.&lt;/P&gt;&lt;P&gt;call method obj1-&amp;gt;m2.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Suresh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Sep 2008 13:11:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4488893#M1062520</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-09-12T13:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: Narrow casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4488894#M1062521</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You didn't Cast it properly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you can see, we need to call the method M2 dynamically becasue C1 doesn't contain it. So, compiler will give use error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*----------------------------------------------------------------------*
*       CLASS c1 DEFINITION
*----------------------------------------------------------------------*
CLASS C1 DEFINITION.
  PUBLIC SECTION.
    METHODS : M1.
ENDCLASS.                    "c1 DEFINITION

*----------------------------------------------------------------------*
*       CLASS c1 IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS C1 IMPLEMENTATION.
  METHOD M1.
    DATA M1 TYPE I VALUE 2.
    WRITE:/ M1.
  ENDMETHOD.                    "m1
ENDCLASS.                    "c1 IMPLEMENTATION

*----------------------------------------------------------------------*
*       CLASS c2 DEFINITION
*----------------------------------------------------------------------*
CLASS C2 DEFINITION INHERITING FROM C1.
  PUBLIC SECTION .
    METHODS M1  REDEFINITION.
    METHODS M2.
ENDCLASS.                    "c2 DEFINITION

*----------------------------------------------------------------------*
*       CLASS c2 IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS C2 IMPLEMENTATION.
  METHOD M2.
    DATA M2 TYPE I VALUE 3.
    WRITE:/ M2.
  ENDMETHOD.                    "m2

  METHOD M1.

    WRITE:/ 'M1 from Class C2'.

  ENDMETHOD.                    "m1
ENDCLASS.                    "c2 IMPLEMENTATION

START-OF-SELECTION.
  DATA OBJ TYPE REF TO C1.
  DATA OBJ1 TYPE REF TO C2.
  CREATE OBJECT OBJ1. 
  OBJ ?= OBJ1.     "&amp;lt;&amp;lt;   Casting
*  CALL METHOD OBJ-&amp;gt;M2.     " &amp;lt;&amp;lt; Error M2 is unknown or Protected
  CALL METHOD OBJ-&amp;gt;('M2').   " &amp;lt; Dynamic Access
  CALL METHOD OBJ-&amp;gt;M1.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naimesh Patel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Sep 2008 13:21:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4488894#M1062521</guid>
      <dc:creator>naimesh_patel</dc:creator>
      <dc:date>2008-09-12T13:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: Narrow casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4488895#M1062522</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;i think ?= means widening casting if iam wrong please correct me.How will code for narrowcasting?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Suresh.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Sep 2008 13:42:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4488895#M1062522</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-09-12T13:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: Narrow casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4488896#M1062523</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Oh yes. Sorry I misread the question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you do the O1 = O2 (narrow casting) you will only be able to access the methods which are in the class of O2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Like (from your example):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data obj type ref to c1.
data obj1 type ref to c2.
CREATE object obj1.
obj = obj1.
call method obj1-&amp;gt;m2.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Will generate an output of "3", not "2".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naimesh Patel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Sep 2008 13:51:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4488896#M1062523</guid>
      <dc:creator>naimesh_patel</dc:creator>
      <dc:date>2008-09-12T13:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: Narrow casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4488897#M1062524</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Suresh,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From the above lines..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data obj type ref to c1.
data obj1 type ref to c2.
CREATE object obj1.
obj = obj1.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The OBJ1 can access both the methods M1 and M2 but OBJ can access only M1 method as it is pertaining &lt;/P&gt;&lt;P&gt;to C1 class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So as you had created the object for Class 2 and as class2 inherits class1 so in short class2 has more methods.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So with the object of Class2 ie OBJ1 you can access two methods.&lt;/P&gt;&lt;P&gt;And now coming to OBJ object you can only access M1 method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So as you assigning OBJ1 to OBJ object you are making the scope of OBJ narrower ( 'V' shape )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On top of the V think  that OBJ1 is there which can access two methods...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But at the bottom of the V there is OBJ which can access only one method and that is method of its own class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So in this way the Narrow casting Concept can be understood.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So finally you can do&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Call method OBJ1-&amp;gt;M2.
Call Method OBJ1-&amp;gt;M1.
Call Method OBJ-&amp;gt;M1.
But not 
Call Method OBJ-&amp;gt;M2. " Which is not possible as OBJ doesnot have the scope to Class2
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Finally, Narrowing the scope of object is Narrowing Cast and Widening the Scope of the Object is Widening Cast.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this would help you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Revert back if any questions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck&lt;/P&gt;&lt;P&gt;Narin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Sep 2008 14:53:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4488897#M1062524</guid>
      <dc:creator>narin_nandivada3</dc:creator>
      <dc:date>2008-09-12T14:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Narrow casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4488898#M1062525</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Suresh&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to see a rather weird (yet useful) narrow casting to the root class (OBJECT) you may have a look at my Wiki posting [Accessing the Inacessible - Local Classes within Global Classes|https://wiki.sdn.sap.com/wiki/display/ABAP/Accessing&lt;EM&gt;the&lt;/EM&gt;Inacessible&lt;EM&gt;-&lt;/EM&gt;Local&lt;EM&gt;Classes&lt;/EM&gt;within&lt;EM&gt;Global&lt;/EM&gt;Classes]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;  Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Sep 2008 20:18:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4488898#M1062525</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2008-09-12T20:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: Narrow casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4488899#M1062526</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Below iam using narrow casting code but i able to access m2 method in obj.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      CLASS c1 DEFINITION&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS C1 DEFINITION.&lt;/P&gt;&lt;P&gt;  PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;    METHODS : M1.&lt;/P&gt;&lt;P&gt;ENDCLASS.                    "c1 DEFINITION&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      CLASS c1 IMPLEMENTATION&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS C1 IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;  METHOD M1.&lt;/P&gt;&lt;P&gt;    DATA M1 TYPE I VALUE 2.&lt;/P&gt;&lt;P&gt;    WRITE:/ M1.&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "m1&lt;/P&gt;&lt;P&gt;ENDCLASS.                    "c1 IMPLEMENTATION&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      CLASS c2 DEFINITION&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS C2 DEFINITION INHERITING FROM C1.&lt;/P&gt;&lt;P&gt;  PUBLIC SECTION .&lt;/P&gt;&lt;P&gt;    METHODS M1  REDEFINITION.&lt;/P&gt;&lt;P&gt;    METHODS M2.&lt;/P&gt;&lt;P&gt;ENDCLASS.                    "c2 DEFINITION&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      CLASS c2 IMPLEMENTATION&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS C2 IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;  METHOD M2.&lt;/P&gt;&lt;P&gt;    DATA M2 TYPE I VALUE 3.&lt;/P&gt;&lt;P&gt;    WRITE:/ M2.&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "m2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  METHOD M1.&lt;/P&gt;&lt;P&gt;    WRITE:/ 'M1 from Class C2'.&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "m1&lt;/P&gt;&lt;P&gt;ENDCLASS.                    "c2 IMPLEMENTATION&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;  DATA OBJ TYPE REF TO C1.&lt;/P&gt;&lt;P&gt;  DATA OBJ1 TYPE REF TO C2.&lt;/P&gt;&lt;P&gt;  CREATE OBJECT OBJ1.&lt;/P&gt;&lt;P&gt;  OBJ = OBJ1.     "&amp;lt;&amp;lt;   Casting&lt;/P&gt;&lt;P&gt;  CALL METHOD OBJ-&amp;gt;('M2').   " &amp;lt; Dynamic Access&lt;/P&gt;&lt;P&gt;  CALL METHOD OBJ-&amp;gt;M1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if  iam using  OBJ ?= OBJ1(widening casting) in code also iam getting same output . can you Please explain me clearly narrow casting and widening casting using my classess example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Suresh.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Sep 2008 06:18:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4488899#M1062526</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-09-15T06:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Narrow casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4488900#M1062527</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;Thanks for replies.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Suresh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Sep 2008 13:28:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4488900#M1062527</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-09-16T13:28:00Z</dc:date>
    </item>
  </channel>
</rss>

