Casting operator

i wonder how i can use normal casting-operators like (byte) in javafx. ok - the datatype byte does not exists, but how can i convert an inputstream with integer in characters in a sinple way? in java i would cast every incoming int to byte and done.
greeting + thanks
ralph

Casting in JavaFX Script is done with the as-operator. For example:
def i = 42;
def b = i as java.lang.Byte;Edited by: michael_heinrichs on Mar 9, 2009 2:51 AM

Similar Messages

  • Dynamic equivalent of the Java language CAST operator

    Hello,
    Here is what I want to do:
    I have an Object that contain "something" (I don't know at compilation time). And I want to do this call:
    Object myObject = new String("Hello");
    myMethod (myObject);
    having declared these:
    public void myMethod (Integer dInt);
    public void myMethod (String sString);
    I want the second method to be called. How can I do that?
    I'm looking for something like a dynamic equivalent of the Java language cast operator:
    ??? myMethod ( (myObject.getClass())myObject ); ???
    or ?? myMethod ( (myObject.castTo(myObject.getClass()) ) ; ??
    Thanks.

    How 'bout using the instanceof operator?
    Like this:
    public myMethod(Object obj)
    if (obj instanceof String)
    //do String stuff
    else if (obj instanceof Integer)
    //do Integer stuff
    }

  • 'CAST' operation ('?=' or 'MOVE ?TO')

    Hi Experts,
    Need your support to understand and fix below WD A error.
    The error is apearing due to casting taking place in Component Controller, could you please redirect me to fix it.
    Error:
    It was tried to assign a reference to a rereference variable using the
    'CAST' operation ('?=' or 'MOVE ?TO').
    However, the current content of the source variable does not fit into
    the target variable.
    Code:
    DATA lv_result TYPE REF TO if_wd_message_area.
      DATA lo_controller TYPE REF TO if_wd_window_controller.
    *&* Comments: Cast error happening at below point.
    lo_controller ?= wd_this->wd_get_api( ).
      CALL METHOD lo_controller->get_message_area
        RECEIVING
          result = lv_result.
      CLEAR lv_result.

    Hi.,
    What exacly u are trying to do., if u want to display message., use message manager., refer below code..
    *       get message manager
           data lo_api_controller     type ref to if_wd_view_controller.
           data lo_message_manager    type ref to if_wd_message_manager.
           lo_api_controller = wd_This1->Wd_Get_Api( ).
           CALL METHOD lo_api_controller->GET_MESSAGE_MANAGER
             RECEIVING
               MESSAGE_MANAGER = lo_message_manager
    *       report message
           CALL METHOD lo_message_manager->REPORT_ATTRIBUTE_ERROR_MESSAGE
             EXPORTING
               MESSAGE_TEXT              = 'Enter user name'  " message text
               ELEMENT                   =       lo_el_user " element
               ATTRIBUTE_NAME            = 'UNAME'   .  " attribute name
    hope this helps u.,
    Thanks & regards
    Kiran

  • Cast operator: Can a date be cast in to a number? Can someone provide an eg

    Hi guys,
    Can someone tell me if a date can be cast in to a number data type? I happen to come across a few lines of code that suggested it might be done.But when I tried it out it gives me an error
    ORA-00932: inconsistent datatypes: expected DATE got NUMBER"
    Would be helpful if anyone provided an example..
    Thanks.

    user8716986 wrote:
    Hi,
    Thanks for the responses..
    Sorry about the operator part.. Guess gt a lil confused with C++ while googling..
    What I am looking fr is to convert '01-JAN-95' to something like this 20120901 (the format I mean).Why not say
    "convert '01-JAN-95' to *19950101* "       or
    "convert *'01-SEP-12'* to 20120901 "       ?
    The code that I came across goes something like this...
    CREATE MATERIALIZED VIEW SUB
    AS
    SELECT cast(SCT as char (3)) SCT,
    cast(EFFECTIVE_DATE as number (9)) EFFECTIVE_DATE,
    cast(CANCEL_DATE as number (9)) CANCEL_DATE,
    where EFFECTIVE_DATE and CANCEL_DATE are of DATE data type...
    I know this can be done using TO_CHAR and TO_NUMBER.. i.e
    TO_NUMBER((TO_CHAR(EFFECTIVE_DATE,'YYYYMMDD'))) EFFECTIVE_DATE,
    TO_NUMBER((TO_CHAR(CANCEL_DATE,'YYYYMMDD'))) CANCEL_DATE,Why do you want NUMBERs in those columns? Why not VARCHAR2s (or even DATEs)?
    I can understand wanting to have output in the desired format, so maybe (just maybe) that justifies converting the DATEs to VARCHAR2s, but why convert those VARCHAR2s to NUMBERs? The properties of NUMBERs don't apply to them. That is, the results you get from averaging those numbers, or adding another NUMBER to them, or subtracting them, just aren't meaningful: you're liable to get results like 20120055. It's true, you can sort and compare those NUMBERs, but you can sort and compare the corresponding VARCHAR2s (and the corresponding DATEs) just as well.
    If you really have to convert the DATE to a NUMBER in that format for some reason, then what you posted above (TO_NUMBER (TO_CHAR ...)) is the right way to do it.
    These stmts give me the desired results .. but what I still would like to know is how is that the above CAST stmts work while when I try them they don't.They don't work for me. I get "ORA-00932: inconsistent datatypes: expected NUMBER got DATE".

  • Casting operation

    Hello Experts,
    I am trying to understand this casting.
    This is the hierachy:
    cl_abap_typedescr
    cl_abap_datadescr
    cl_abap_elemdescr
    cl_abap_complexdescr
    cl_abap_structdescr
    cl_abap_tabledescr
    cl_abap_refdescr
    cl_abap_objectdescr
    cl_abap_classdescr
    cl_abap_intfdescr
    DATA: r_descr            TYPE REF TO cl_abap_typedescr,
          r_descrstructdescr TYPE REF TO cl_abap_structdescr,
    r_descrstructdescr ?= r_descr .
    LOOP AT  r_descrstructdescr->components ASSIGNING <comp_wa>.
    ENDLOOP.
    Why is this casting with r_descrstructdescr ?= r_descr  necessary.
    r_descrstructdescr was cl_abap_structdescr and after the casting it is now
    cl_abap_typedescr.
    Originally r_descrstructdescr was also able to use this function r_descrstructdescr->components.
    Is it correctly ?
    After this assignment r_descrstructdescr ?= r_descr it is now no longer able
    to use all the functions of the other classes like l_abap_elemdescr, cl_abap_complexdescr
    s.o. because it has became cl_abap_typedescr now.
    The classes at the bottom have more functions than the classes
    it sabove in the above shown hierarchy. What sence does it make to restrict "r_descrstructdescr"
    due to this casting r_descrstructdescr ?= r_descr .  ?
    Or do I misunderstand it totally wrong
    Regards
    sas

    P374657 wrote:>
    > Hello,
    >
    > can you say me what happens due to this operation r_descrstructdescr ?= r_descr .
    >
    >
    Do I cast cl_abap_typedescr to cl_abap_structdescr or
    > cl_abap_structdescr to cl_abap_typedescr ????????
    >
    > DATA: r_descr            TYPE REF TO cl_abap_typedescr,
    >       r_descrstructdescr TYPE REF TO cl_abap_structdescr,
    >       
    > r_descrstructdescr ?= r_descr .
    >
    > bye
    > sas
    Thomas has given you a great answer.  It's absolutely precise and accurate.
    cl_abap_typedescr has no attribute "components". Since your actual value of cl_abap_typedescr is the inheriting object cl_abap_structdescr, you have to cast in order to access the attribute.
    You cast the subclass to the super class.  The object referred to by r_descr is in fact a cl_abap_structdescr object - it does have "components".  But so long as the reference variable is defined with reference to cl_abap_typedescr, you can't get at them.  It's like the functionality is there, but the button on your remote control doesn't exist.  By ?= to a reference type that does have "components" you can access them.
    This is quite a difficult concept to get hold of. It is generic to object oriented programming, so you may like to tackle it through an language that's a bit easier - like Java.
    matt

  • FLEX3 : Repeater, databinding, and cast operator

    Hello,
    Having encountered problems using Repeater in our enterprise project, we have decided to process heavy tests on Repeater and databinding.
    And what we have discovered is amazing!
    Please copy paste this code, run the app and click on the button.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
            <mx:Script>
            <![CDATA[
                import mx.collections.ArrayCollection;
                [Bindable]
                private var sourceArray:ArrayCollection = new ArrayCollection([
                             new SimpleBean(),
                             new SimpleBean(),
                             new SimpleBean()
                public function changeValue():void{
                    var objectToModify:SimpleBean = sourceArray.getItemAt(1) as SimpleBean;
                    objectToModify.displayedName="Binding works";
            ]]>
        </mx:Script>
        <mx:VBox>
            <mx:Repeater id="rp" dataProvider="{sourceArray}">
                <mx:Label text="{SimpleBean(rp.currentItem).displayedName}" color="green"/>
                <mx:Label text="{(rp.currentItem as SimpleBean).displayedName}" color="red"/>
            </mx:Repeater>
        </mx:VBox>
        <mx:Button click="changeValue()"/>
    </mx:WindowedApplication>
    Here is the SimpleBean class:
    package
        public class SimpleBean
            [Bindable]
            public var displayedName:String="A default name";
    Amazing, no? It seems that the 2 cast operators behave differently inside a Repeater, and one prevents databinding to be triggered...
    So my question is: is it a SDK bug, or does this difference have an explanation?

    Hi schioche,
    I think it is a bug in Flex 3.* SDK, confirmed the the same behaviour by me.
    This bug was fixed somehow in Flex 4 SDK, verified.
    If upgrading to Flex 4 SDK is not an option to you, then you can initiate binding manually via ActionScript, worked for me
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
        <mx:Script>
            <![CDATA[
                import mx.collections.ArrayCollection;
                [Bindable]
                private var sourceArray:ArrayCollection = new ArrayCollection([
                    new SimpleBean(),
                    new SimpleBean(),
                    new SimpleBean()
                public function changeValue():void{
                    var objectToModify:SimpleBean = sourceArray.getItemAt(0) as SimpleBean;
                    objectToModify.displayedName="Binding works";
                    rp.executeBindings();
            ]]>
        </mx:Script>
        <mx:VBox>
            <mx:Repeater id="rp" dataProvider="{sourceArray}">
                <mx:Label id="labelA" text="{SimpleBean(rp.currentItem).displayedName}" color="green"/>
                <mx:Label id="labelB" text="{(rp.currentItem as SimpleBean).displayedName}" color="red"/>
            </mx:Repeater>
        </mx:VBox>
        <mx:Button click="changeValue()"/>
    </mx:Application>

  • Using the "as" operator vs casting?

    I've recently been reading the docs regarding data types in
    AS3 and am still not clear on a few things. If anyone has blogged
    on this, please point me there.
    One problem is that "casting" syntax is the same as top-level
    function syntax. Compare String(objString) to XML(event.result).
    The latter is a top-level function, but the former is a "cast". Or
    is it?
    An option to the String cast is objString.toString(). What is
    the difference? I am not so much interested in the underlying
    details of the language, as in understanding when to use which.
    The same question exists for the top-level function
    XML(event.result), which can be done with the "as" operator:
    event.result as XML. When to use which? Are there performance
    issues? The "as operator" documentation is unsatisfying.
    Any discussion of this will be appreciated.
    Tracy

    ActionScript 3.0 has the
    as operator because it circumvents a deficiency with the
    cast operation () in ActionScript. Consider this:
    var a:Object = new Array(1,2,3,4);
    var b:Array = Array(a);
    What is b? It is an Array of 1 element: [ [1,2,3,4] ];
    The
    as operator takes care of this:
    var b:Array = a as Array;
    The actual difference in the operators is that if the
    variable being cast is not of the proper type, the
    as operator returns null while the () operator throws an
    exception:
    var j:Number = Number(a); // exception!
    var k:Number = a as Number; // NaN in this case, but null
    normally
    The feeling here at Adobe is to use the
    as operator since it is not ambiguous and just check for
    null. If you prefer to catch exceptions and know when X(y) is a
    cast vs a conversion, then use that. More of a preference but at
    times only
    as will do what you need.

  • Casting in ABAP Objects

    Why the cast error generates only in Widening cast?

    Hi Shyam,
    WELCOME TO SDN!!!
    Please check this link
    http://abapprogramming.blogspot.com/2007/10/oops-abap-8.html
    The widening cast in this case does not cause an error because the reference airplane actually points to an instance in the subclass lcl_cargo_airplane. The dynamic type is therefore u2018REF TO lcl_cargo_airplaneu2019.
    Here the widening cast produces the MOVE_CAST_ERROR runtime error that can be caught with u201CCATCH ... ENDCATCHu201D, because the airplane reference does not point to an instance in the subclass lcl_cargo_airplane, but to a u201Cgeneral airplane objectu201D. Its dynamic type is therefore u2018REF TO lcl_airplaneu2019 and does not correspond to the reference type cargo_airplane.
    The widening cast logically represents the opposite of the narrowing cast. The widening cast cannot be checked statically, only at runtime. The Cast Operator u201C?=u201D (or the equivalent u201CMOVE ... ?TO u2026u201D) must be used to make this visible.
    With this kind of cast, a check is carried out at runtime to ensure that the current content of the source variable corresponds to the type requirements of the target variables. In this case therefore, it checks that the dynamic type of the source reference airplane is compatible with the static type of the target reference cargo_airplane. If it is, the assignment is carried out. Otherwise the catchable runtime error u201CMOVE_CAST_ERRORu201D occurs, and the original value of the target variable remains the same.
    Best regards,
    raam

  • TABLE(CAST()) function not returning the correct results in few scenarios.

    I am using TABLE(CAST()) operation in PL/SQL and it is returning me no data.
    Here is what I have done:
    1.     Created Record type
    CREATE OR REPLACE TYPE target_rec AS OBJECT
    target__id          NUMBER(10),
    target_entity_id NUMBER(10),
    dd           CHAR(3),
    fd           CHAR(3),
    code      NUMBER(10),
    target_pct      NUMBER,
    template_nm VARCHAR2(50),
    p_symbol      VARCHAR2(10),
    pm_init          VARCHAR2(3),
    target_name     VARCHAR2(20),
    targe_type     VARCHAR2(30),
    target_caption     VARCHAR2(30),
    sort_order      NUMBER (4)
    2.     Created Table type
    CREATE OR REPLACE TYPE target_arr AS TABLE OF target_rec
    3.     Created Stored procedure which accepts parameter of type target_arr and runs the Table(Cast()) function on it.
         Following is the simplified form of my procedure.
         PROCEDURE get_target_weights
         p_in_template_target IN target_arr,
         p_out_count          OUT NUMBER,
         IS
         BEGIN
              SELECT count(*) into p_out_count
         FROM TABLE(CAST(p_in_template_target AS                     target_arr)) arr;
         END;
    I am calling get_target_weights from my java code and passing p_in_template_target with 10140 records.
    Scenario 1: If target_pct in the last record is 0, p_out_count returned from the procedure is 0.
    Scenario 2: If target_pct in the last record is any other value(say 0.01), p_out_count returned from the procedure is 10140.
    Please help me understand why the Table(Cast()) is not returning the correct results in Scenario 1. Also adding or deleting any record from the test data returns the correct results (i.e. if keep target_pct in the last record as 0 but add or delete any record).
    Let me know how can I attach the test data I am using to help you debugging as I don’t see any Attach file button on Post Message screen on the forum.

    I am not able to reproduce this problem with a small data set. I can only reproduce with the data having 10140 records.
    I am not sure if this is the memory issue as adding a new record also solves the problem.
    This should not be the error because of wrong way of filling the records in java as for testing purpose I just saved the records which I am sending from java in a table. I updated the stored procedure as well to read the data from the table and then perform TABLE(CAST()) operation. I am still getting 0 as the output for scenario 1 mentioned in my last mail.
    Here is what I have updated:
    1.     Created the table target_table
    CREATE Table target_table
    target_id          NUMBER(10),
    target_entity_id NUMBER(10),
    dd           CHAR(3),
    fd           CHAR(3),
    code      NUMBER(10),
    target_pct      NUMBER,
    template_nm VARCHAR2(50),
    p_symbol      VARCHAR2(10),
    pm_init          VARCHAR2(3),
    target_name     VARCHAR2(20),
    target_type     VARCHAR2(30),
    target_caption     VARCHAR2(30),
    sort_order      NUMBER (4)
    2.     Inserted data into the table : The script has around 10140 rows. Pls let me know how can I send it to you
    3.     Updated procedure to read data from table and stored into variable of type target_arr. Run Table(cast()) operation on target_arr and get the count
    PROCEDURE test_target_weights
    IS
         v_target_rec target_table%ROWTYPE;
         CURSOR wt_cursor IS
         Select * from target_table;
         v_count NUMBER := 1;
         v_target_arr cws_target_arr:= target_arr ();
         v_target_arr_rec target_rec;
         v_rec_count NUMBER;
         BEGIN
         OPEN wt_cursor;
         loop
              fetch wt_cursor into v_target_rec; -- fetch data from table into local           record.
              exit when wt_cursor%notfound;
              --move data into target_arr
              v_target_arr_rec :=                     cws_curr_pair_entity_wt_rec(v_target_rec target_id,v_target_rec. target_entity_id,
                        v_target_rec.dd,v_target_rec.fd,v_target_rec.code,v_target_rec.target_pct,
         v_target_rec.template_nm,v_target_rec.p_symbol,v_target_rec.pm_init,v_target_rec.template_name,
         v_target_rec.template_type,v_target_rec.template_caption,v_target_rec.sort_order);
              v_target_arr.extend();
              v_target_arr(v_count) := v_target_arr_rec;
              v_count := v_count + 1;
         end loop;
         close wt_cursor;
         -- run table cast on target_arr
         SELECT count(*) into v_rec_count
         FROM TABLE(CAST(v_target_arr AS target_arr)) arr;
         DBMS_OUTPUT.enable;
         DBMS_OUTPUT.PUT_LINE('p_out_count ' || v_rec_count);
         DBMS_OUTPUT.PUT_LINE('v_count ' || v_count);
    END;
    Output is
    p_out_count 0
    v_count 10140
    Expected output
    p_out_count 10140
    v_count 10140

  • 关于 narrowing cast 的疑问...

    请教大家一个问题。
    在 ABAP Keyword Documentation 中对 MOVE 的说明中有这样一段话:
    Both these statements assign the content of the operand source to the data object destination. The variants with the addition TO or the assignment operator = are valid for all assignments between operands that are not reference variables, and for assignments between reference variables for which the static type of source is more specific than or the same as the static type of destination (narrowing cast).
    但是在 ABAP Glossay 中对narrowing cast的说明是:Also called a narrowing cast, a down cast is an assignment between reference variables in which the typr static type of the target variable more specific than the static type of the source variable. A down cast is only possible in assignments with the casting operator (?=) or MOVE ... ?TO. Compare with up cast.
    这两段对于narrowing cast的描述是相反的,哪个是正确的?谢谢!

    谢谢您的回复。但是不好意思,我还是没有明白。
    正如您所说的:
    第一段说的是操作符 = 或者语法MOVE...TO...的概念,第二段说的是 ?= 或MOVE...?TO..
    但是到底哪个是narrowing cast?
    第一段说 ...(narrowing cast)。=> 它是narrowing cast
    第二段说 Also called a narrowing cast, a down cast ... => 它也是 narrowing cast,又称 down cast
    您说 不满足以上任何一个Narrowing Casting条件的,要使用Widening Casting(Down Casting)  => narrowing cast 和 down cast 是相反的

  • Change Narrowing and Widening Cast

    I have ABAP Object 2007 book from Horst Keller and I also have a 7.0 SAP System.
    SAP have changed the terminology from SAP 6.40.
    Please see this hyperlink  [Version 7.0 ABAP Modification 6|http://help.sap.com/abapdocu/en/ABENNEWS-70-DOCU.htm#!ABAP_MODIFICATION_6@6@]
    In addition when I click on Help on MOVE and the Casting operator in my 7.0 Version system is explained as
    Up Cast
    Also referred to as widening cast. Assignment between reference variables, where the static type of the target variables is similar or identical to the static type of the source variables.
    Down cast
    Also called a narrowing cast, a down cast is an assignment between reference variables in which the typr static type of the target variable more specific than the static type of the source variable. A down cast is only possible in assignments with the casting operator (?=) or MOVE ... ?TO. Compare with up cast
    SAP now want you to use the unambiguous terms of UP and DOWN  Version 7.0 of course.
    Does anybody have a pre640 SAP system (46C,47) that can confirm that the terminology has changed ?

    Hi,
    The terminology has not changed, but its a prior mistake made while writing notes, but the concept still remains the same as far as I have check in systems...
    Regards,
    Siddarth

  • Narrowing cast and widening cast

    Hi All,
           I want to know what is the use of a narrowing cast and a widening cast in ABAP objects.
    Can someone please give an example ?
    Regards,
    Ashish

    Hi,
    Check out this link, This will guide you on ABAP Objects
    http://www.sap-press.de/katalog/buecher/htmlleseproben/gp/htmlprobID-28?GalileoSession=22448306A3l7UG82GU8#level3~3
    Both narrow and wide casting are related to inheritance.
    In Narrow casting, you assign a runtime object of subclass to runtime object of superclass. By this assignment , you can access your subclass by using runtime object of your superclass. But here the important point is that, you are assigning subclass reference to super class reference, so you can only access the inherited components of subclass through super class reference.
    Suppose you have a super class lcl_vehicle. it has two subclasses lcl_car and lcl_truck.
    r_vehicle = r_car.
    In Wide casting, you assign a superclass reference to subclass reference . Before this, you do narrow casting,
    Now when you assign a superclass reference to subclass reference. You can access the inherited as well as the specific components of subclass.
    taking the same example,
    r_car ?= r_vehicle.
    '?='  wide cast operator.
    Regards
    Abhijeet

  • Narrow Cast and Widening cast in OOPs

    hi friends,
    Can u please clear with the above two concepts ..... i have many doubts on this ...
    first of all Y we need the concept of Narrow cast and widenning cast ?
    Expecting your answers ...
    Thanks in advance
    Cheers
    Kripa Rangachari .....

    hi Kripa,
    “Narrowing” cast means that the assignment changes from a more specialized view (with visibility to more components) to a more generalized view (with visibility to fewer components).
    “Narrowing cast” is also referred to as “up cast” . “Up cast” means that the static type of the target variable can only change to higher nodes from the static type of the source variable in the inheritance tree, but not vice versa.
    <b>Reference variable of a class assigned to reference variable of class : object</b>
    class c1 definition.
    endclass.
    class c1 implementation.
    endclass.
    class c2 definition inheriting from c1.
    endclass.
    class c2 implementation.
    endclass.
    start-of-selection.
    data : oref1 type ref to c1,
            oref2 tyep ref to c2.
    oref1 = oref2.
    <b>Widening Cast</b>
    DATA:     o_ref1 TYPE REF TO object,                o_ref2 TYPE REF TO class.
    o_ref2 ?= o_ref1.
    CATH SYSTEM-EXCEPTIONS move_cast_error = 4.
         o_ref2 ?= o_ref1.
    ENDCATCH.
    In some cases, you may wish to make an assignment in which the static type of the target variable is less general than the static type of the source variable. This is known as a widening cast.
    The result of the assignment must still adhere to the rule that the static type of the target variable must be the same or more general than the dynamic type of the source variable.
    However, this can only be checked during runtime. To avoid the check on static type, use the special casting operator “?=“ and catch the potential runtime error move_cast_error
    Regards,
    Richa

  • How to cast a field in a view

    I have for example 2 tables:
    table A ( a integer(10), b integer(10))
    table B ( a integer(10), x blob,
    b integer(10))
    and want to do inside a view
    an insert from A in B casting
    an null to blob like this
    ( for better understanding of my problem i use the "c"-cast operator)
    insert into B select a, (blob) null x, b
    from A;
    this way i have used because in fact the tables i have to use are a bit big and
    typing all the attributes are very lame.
    thanks for your answer.

    Hi Ashish,
                  I will give a detailed explanation of my requirement. I am working in ICWEB client for utility services, In this case for a particular view in the bsp application CRM_IUFCS_IC/View1.htm i want to add a field but the field is not the context nodes, or any of the related entities in the BOl Model. But its in  another root object in the BOL Model. So i would like to know how can i add this field into my layout.
    e.g.:let context node in view to be modified is buag and the field to be added is under BuilHeader object. This is the scenario.
    Advance Thanks,
    Sujith

  • Widening casting

    Hi,
    I am a debutant in ABAP OO. I am trying to understand the concept of Widening casting with lots of example found in SDN, but still I can't come to any conclusion on this.
    Well I understood from one of the example that , before doing the widening , we have to do narrow casting..
    DATA: lo_animal TYPE REF TO lcl_animal,   " Super Class
            lo_lion          TYPE REF TO lcl_lion,        " Sub class
            lo_tmp_lion   TYPE REF TO lcl_lion.       " Sub class
      CREATE OBJECT lo_tmp_lion.
      lo_animal = lo_tmp_lion.                  " Narrow Casting
    lo_lion ?= lo_animal.     " Widening
    Here my question is why do we have to assign the instance of lo_animal to lo_lion which is having the same instance of lo_lion( lo_lion & lo_tmp_lion are reference var of same class ). and i also found an another example from  one of the SDN thread for widening which i really can't undersatnd.
    DATA lo_tabledescr TYPE REF TO cl_abap_tabledescr.
    DATA lo_structdescr TYPE REF TO cl_abap_structdescr.
    DATA lv_linetypename  TYPE string.
    TRY.
        lo_tabledescr   ?= cl_abap_typedescr=>describe_by_name( 'BAPIRET2_T' ).
        lo_structdescr  ?= lo_tabledescr->get_table_line_type( ).
      CATCH cx_sy_move_cast_error.
        MESSAGE 'Error in downcast!' TYPE 'A'.
    ENDTRY.
    lv_linetypename = lo_structdescr->get_relative_name( ).
    WRITE: /, lv_linetypename.
    * Alternative way using dynamic calling
    DATA lo_typedescr_tab TYPE REF TO cl_abap_typedescr.
    DATA lo_typedescr_str TYPE REF TO cl_abap_typedescr.
    lo_typedescr_tab   = cl_abap_typedescr=>describe_by_name( 'BAPIRET2_T' ).
    TRY.
        CALL METHOD lo_typedescr_tab->('GET_TABLE_LINE_TYPE')
          RECEIVING
            p_descr_ref = lo_typedescr_str.
      CATCH cx_sy_dyn_call_error.
        MESSAGE 'Error in dynamic call!' TYPE 'A'.
    ENDTRY.
    lv_linetypename = lo_typedescr_str->get_relative_name( ).
    WRITE: /, lv_linetypename, '...again'.
    Please give me some hints to break through this.
    Thanks in advace,
    Eti.

    Hello Eti,
    I think you're aware of Narrowing & Widening Cast, if not Arshad's response explains these concepts.
    ... why do we have to assign the instance of lo_animal to lo_lion which is having the same instance of lo_lion( lo_lion & lo_tmp_lion are reference var of same class ) ...
    To understand this you need to know - [Static Type|http://help.sap.com/abapdocu_731/en/abenstatic_type_glosry.htm] and  [Dynamic Type|http://help.sap.com/abapdocu_731/en/abendynamic_type_glosry.htm] for reference variables. (This applies to both data and object reference variables).
    The golden-rule for assignment of reference variables is,
    Dynamic type of a ref. variable must always be more specific than the static type.
    DATA: lo_animal TYPE REF TO lcl_animal,"Super Class
          lo_lion   TYPE REF TO lcl_lion. "Sub Class
    The static type of the ref. variable lo_lion is lcl_lion. Now let's consider this assignment,
    lo_lion = lo_animal.
    The compiler interprets the dynamic type of lo_lion (after this assignment) would be lcl_animal. It is more generic compared to the static type( lcl_lion ), since lcl_animal is a super-class of lcl_lion, so the compiler will throw a static syntax error. (Remember the "golden-rule" of reference variable assignment)
    The [casting operator|http://help.sap.com/abapdocu_731/en/abencasting_operator_glosry.htm] is just an instruction to the compiler to skip the static syntax check during the widening cast,
    lo_lion ?= lo_animal. "Widening Cast
    Always remember that for Widening Casts the "golden-rule" of assignment will be checked during runtime.
    If the rule is not satisfied, it'll result in an exception - CX_SY_MOVE_CAST_ERROR ! In order to avoid this situation, the demo program uses a temporary reference variable - lo_tmp_lion.
    lo_animal = lo_tmp_lion. "Narrow Casting
    lo_lion ?= lo_animal."Widening cast
    Sorry for this big post, hope it helps & reduces your confusion
    BR,
    Suhas
    PS: Normally when you're doing a Widening Cast you would not be required to use a temporary ref. variable.

Maybe you are looking for

  • Terminated employees and system-wide "clean up"

    We have, unfortunately, a pretty high turnover rate in our purchasing department and we use the Oracle Purchasing module. We have over 14,000 purchasable items and around 3,000 on average assigned to each buyer that we have. When someone takes their

  • When i try to play music my screen is frozen

    PLEASE HELP

  • Error at Draft Invoice

    Invoice rejected in oracle the reason for rejection is invoice line with the same invoice number have been separated by the grouping process, causing duplicate invoice number.

  • BAPI_REQUISITION_CREATE question

    Hi all. Help somebody please! Via SAP GUI it is possible to create purchase requsition. User creates items, validate them along the way and just finally saves whole requisition and retrieves it's number. I've only found BAPI_REQUISITION_CREATE to cal

  • TMS - CCMS Alert domain doesn't appear

    On my training system when I go into STMS, then CCMS Alert Monitor,(The "Bell" icon") the domain doesn't appear under change and transport system. It also won't allow me to create it in rz20. I've tried redistributing and activating the stms configur