<?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: Object casting: confusion in ABAP Objects: Complete Reference book in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/object-casting-confusion-in-abap-objects-complete-reference-book/m-p/1258780#M146964</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I believe it does checks at both syntax check and runtime. Sometimes it cannot do the precise check until runtime, for example if you are using field symbols, but it tries to do as much as it can at the syntax check stage.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 05 Mar 2006 23:52:29 GMT</pubDate>
    <dc:creator>former_member186741</dc:creator>
    <dc:date>2006-03-05T23:52:29Z</dc:date>
    <item>
      <title>Object casting: confusion in ABAP Objects: Complete Reference book</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/object-casting-confusion-in-abap-objects-complete-reference-book/m-p/1258779#M146963</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;During Object Assignments using casting, is a Type Test carried out during the syntax check or at runtime?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A.5.2.2 (page 1008) of 'ABAP Objects: The Complete Reference' says about Widening Cast: "...you must check at runtime...". However on the next page under A.5.3.2 it says of Widening Cast in Data References: "The syntax check precludes...".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A.5.4 (page 1010) concerns Assignments between Object Reference Variables, but makes no mention of whether checks are carried out by a syntax check or at runtime.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also nowhere does it mention when Type Tests for Narrow casting takes place. Can anyone clear my confusion please? Unfortunatly I don't know enough about this stuff to test by writing some code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 05 Mar 2006 14:30:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/object-casting-confusion-in-abap-objects-complete-reference-book/m-p/1258779#M146963</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-03-05T14:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: Object casting: confusion in ABAP Objects: Complete Reference book</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/object-casting-confusion-in-abap-objects-complete-reference-book/m-p/1258780#M146964</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I believe it does checks at both syntax check and runtime. Sometimes it cannot do the precise check until runtime, for example if you are using field symbols, but it tries to do as much as it can at the syntax check stage.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 05 Mar 2006 23:52:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/object-casting-confusion-in-abap-objects-complete-reference-book/m-p/1258780#M146964</guid>
      <dc:creator>former_member186741</dc:creator>
      <dc:date>2006-03-05T23:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Object casting: confusion in ABAP Objects: Complete Reference book</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/object-casting-confusion-in-abap-objects-complete-reference-book/m-p/1258781#M146965</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suspose the core of the question is whether a Widening Cast for an object assignment carries out a Type Test during runtime, or during the syntax check?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 12:23:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/object-casting-confusion-in-abap-objects-complete-reference-book/m-p/1258781#M146965</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-03-06T12:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: Object casting: confusion in ABAP Objects: Complete Reference book</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/object-casting-confusion-in-abap-objects-complete-reference-book/m-p/1258782#M146966</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi William,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I haven't read the book but as far as I know the check is performed at runtime. That's why casting statements a useually followed by a try - catch statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 14:17:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/object-casting-confusion-in-abap-objects-complete-reference-book/m-p/1258782#M146966</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-03-06T14:17:45Z</dc:date>
    </item>
    <item>
      <title>Re: Object casting: confusion in ABAP Objects: Complete Reference book</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/object-casting-confusion-in-abap-objects-complete-reference-book/m-p/1258783#M146967</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;William,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your questions can be answered by the following rule for object references, which I found in the book "ABAP Objects" by Horst Keller and Sascha Krüger:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"... that the static type of the target variable must be equal to or more general than the dynamic type of the source variable." &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here "static type" means the type with which an object reference variable is declared. "Dynamic type" is the type that the object reference variable has at runtime. The dynamic type of an object reference is always more special than its static type, otherwise a runtime error occurs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With this rule all your questions can be answered:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. The Narrowing Cast is always checked during the syntax check. Example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA o_ref1 TYPE REF TO object.&lt;/P&gt;&lt;P&gt;DATA o_ref2 TYPE REF TO class_1.&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;o_ref1 = o_ref2.   &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here the reference o_ref2 has a dynamic type "class_1" or a subclass of it, which is narrower than its static type "class_1", which is narrower than the static type "object" of the reference o_ref1. Therefore, the syntax check says that the assignment is OK.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. The Widening Cast is always checked at runtime and requires an assignment using the operator ?=. If you use the operator = in the assignment, a syntax error occurs. Therefore the following  example produces a syntax error (try it yourself):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA o_ref1 TYPE REF TO object.&lt;/P&gt;&lt;P&gt;DATA o_ref2 TYPE REF TO class_1.&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;o_ref2 = o_ref1.   &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The correction for this syntax error is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA o_ref1 TYPE REF TO object.&lt;/P&gt;&lt;P&gt;DATA o_ref2 TYPE REF TO class_1.&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;o_ref2 ?= o_ref1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now the syntax check is satified, and the correctness of the widening cast is checked at runtime.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Michael Kraemer&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Michael Kraemer&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 15:12:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/object-casting-confusion-in-abap-objects-complete-reference-book/m-p/1258783#M146967</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-03-06T15:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: Object casting: confusion in ABAP Objects: Complete Reference book</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/object-casting-confusion-in-abap-objects-complete-reference-book/m-p/1258784#M146968</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rgds,&lt;/P&gt;&lt;P&gt;William.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Mar 2006 10:22:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/object-casting-confusion-in-abap-objects-complete-reference-book/m-p/1258784#M146968</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-03-07T10:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: Object casting: confusion in ABAP Objects: Complete Reference book</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/object-casting-confusion-in-abap-objects-complete-reference-book/m-p/1258785#M146969</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for the very detailed reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rgds,&lt;/P&gt;&lt;P&gt;William.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Mar 2006 10:22:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/object-casting-confusion-in-abap-objects-complete-reference-book/m-p/1258785#M146969</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-03-07T10:22:50Z</dc:date>
    </item>
  </channel>
</rss>

