Why narrow casting is must before doing wide casting

Hi everyone,
I know the concept of wide casting ( assign/pass super class instances to subclass instances). So then why we need to do narrow casting before doing wide casting in our logic. I am just struggling into this concept from last 3 days. I have read many thread and blog but did not get satisfactory answer.
Regards,
Seth

Hello Seth
You do not need to do narrow casting. But, if you assign an instance of a super class to variable of subclass and try to run a subclass' method on that instance (of superclass) you will get an exception. Because super class does not have a mentioned method.
Example:
CLASS lcl_vehicle DEFINITION.
ENDCLASS.
CLASS lcl_car DEFINITION INHERITING FROM lcl_vehicle.
  DATA engine TYPE string VALUE 'has_engine'.
ENDCLASS.
DATA:
  lo_vehicle TYPE lcl_vehicle,
  lo_car TYPE lcl_car.
CREATE OBJECT lo_vehicle.
CREATE OBJECT lo_car.
WRITE lo_car->engine.
lo_car ?= lo_vehicle.
WRITE lo_car->engine.
regards

Similar Messages

  • How important it is to understand Concept of Narrow & Wide casting in ABAP Objects

    Hi Friends,
    I Understood that, it is very important to understand the concept of "Casting ( Narrow Casting & Wide Casting )" properly.
    Let us see the following cases where the concept of "Casting ( Narrow Casting & Wide Casting )" comes into the picture in various practices of Abap, Webdynpro abap and FPM.
    1. ABAP:-
    When we are working with RTTS in abap it is very much important we must know the Casting Techniques. Without knowledge of the Casting of objects, there will be a lot of trouble we may faces.
    Mainly RTTS offers Runtime Type Services, means RTTS Programming enables us to find the type of the particular data obejct or data type or data reference in the run time.
    RTTS also enables us to create the data in the run time very dynamically.
    So, in the run time when we finding the type of the data objects or creation of data objects in the run time, We must do the Wide casting and Narrow casting also some times on the references provided by SAP Dynamically.
    So, here we go to have knowledge on Casting is mandatory.
    2. WEBDYNPRO ABAP:-
    The another point where the concept of casting comes into picture is , When we working with the ALV Reports and Dynamic programming of WEBDYNPRO. Here also we should posses good casting skills.
    3. FPM:-
    The major use of casting comes in hand is none other than FPM. When we working with certain Floor Plans or when we woking with Feeder Class concept of FPM, Casting comes into picture again.
    Along with Casting ( Narrow casting & Wide casting ), We must have the knowledge of 'Field Symbols' and 'Data References (known & Unknown)' to work with our all complex scenarios of Webdynpro and FPM and all.
    So guys, please have Knowledge on the following, befor you master on advanced techniques of WEBDYNPRO and FPM etc.
         1. Field Symbols
         2. Data References (known & unknown)
         3. Casting (Narrow casting & Wide casting)
         4. Brief Idea about RTTS
    All the above 4 concepts will definitely make our life easy when dig more into WEBDYNPRO ABAP and FPM.
    Thank You.
    Please share your comments on the same.

    Hi Shankar,
    It's really good to know.
    It could be great if you can share few technicalities for the concepts explained.
    Regards,
    Rafi

  • Hi Apple Team, I would like to change the iCloud account on my iPhone, however it says I must 'delete the account' before doing so? Does this mean that I delete the entire existing account, or just delete it from my phone specifically?

    Hi Apple Team, I would like to change the iCloud account on my iPhone, however it says I must 'delete the account' before doing so? Does this mean that I delete the entire existing account, or just delete it from my phone specifically?

    From the iPhone only.

  • Narrow casting vs wide casting

    Hello All,
    I have small requriemn..
    I have a super class A and a sub class B.
    In both the classes I have a method XYZ.
    So, A has the following methods
    ABC
    XYZ
    B has the following methods
    XYZ
    Now I have want to access the sub class methods from super class...i.e., in my example...Method XYZ of B class needs to be accessed from method ABC or XYZ or A.
    How do I do?
    And more over..what is the difference between Narrow Casting and Wide casting?
    Kalyan

    Hi Priya,
    Consider the below Example for accessing the subclass method from Superclass:
    CLASS LCL_SUPERCLASS DEFINITION.
       PUBLIC SECTION.
           METHODS: ABC, XYZ.
    ENDCLASS.
    CLASS LCL_SUPERCLASS IMPLEMENTATION.
      METHOD ABC.
       CALL METHOD ME->XYZ.
      ENDMETHOD.
      METHOD XYZ.
      ENDMETHOD.
    ENDCLASS.
    CLASS LCL_SUBCLASS DEFINITION
           INHERITING FROM LCL_SUPERCLASS.
       PUBLIC SECTION.
          METHODS XYZ REDEFINITION.
    ENDCLASS.
    CLASS LCL_SUBCLASS IMPLEMENTATION.
      METHOD XYZ.
      ENDMETHOD.
    ENDCLASS.
    START-OF-SELECTION.
    DATA: O_SUPER TYPE REF TO LCL_SUPERCLASS,
               O_SUB     TYPE REF TO LCL_SUBCLASS.
    CREATE OBJECT: O_SUPER, O_SUB.
    CALL METHOD O_SUPER->ABC.
    CALL METHOD O_SUB->ABC.
    In the above example, When you call the superclass method ABC using CALL METHOD O_SUPER->ABC, as you see in the implementation part of the Method it will inturn call the Superclass method XYZ.
    Here ME will point to the instance of the Superclass.
    But the CALL METHOD O_SUB->ABC will call the method ABC ( this is inherited from Superclass to Subclass )and inturn it calls the method XYZ of the SUbclass since ME now points to the object O_SUB of the Subclass.
    Hope this is clear.
    Regards,
    Nirupamaa.

  • Why is iCal in . and not in English? And why does it cast its malign spell over Mail?

    Why is iCal in German and not in English? And why does it cast its malign spell over Mail?

    Go to the Settings app and check under General, International and see what language is set. Even if it correctly set, reset it.
    If that doesn't work, try a rest of the iPad: hold down the On and Home buttons simultaneously until it shuts down. Ignore the Off slider if it appears. This will take 10 - 15 seconds or so. After it shuts down completely, press the On button to restart.

  • Why ?= used in wide casting

    in wide casting , if we are assigning super class object2 to super class object1 using '?='. having the same effect as '='. so y we need to add '?' in wide casting.
    class lcl_super DEFINITION.
       PUBLIC SECTION.
       METHODS method1.
      ENDCLASS.
      CLASS lcl_super IMPLEMENTATION.
        method method1.
          write : 'super class method'.
          ENDMETHOD.
          ENDCLASS.
      class lcl_sub DEFINITION INHERITING FROM lcl_super.
        PUBLIC SECTION.
        methods : method1 REDEFINITION,
                  method2.
        ENDCLASS.
        CLASS lcl_sub IMPLEMENTATION.
          method method1.
            write ' subclass method1'.
            ENDMETHOD.
            method method2.
              write 'subclass method2'.
              ENDMETHOD.
          ENDCLASS.
    data: obj1 type REF TO lcl_super,
           obj2 type REF TO lcl_sub.
    START-OF-SELECTION.
    create OBJECT obj1.
    CREATE OBJECT obj2.
    obj1 = obj2.                                     "Narrrowing casting
    CALL METHOD obj1->method1.
    data obj3 type REF TO lcl_super.
    create OBJECT obj3.
    obj1 ?= obj3.   or obj1 = obj3             "   is having same effect  in Widecasting,  so why need '?'
    obj1->method1( ).

    Hi vijay,
    in addition to what Rudiger said, to know what ?= means, refer to this link: http://help.sap.com/abapdocu_70/en/ABAPMOVE.htm
    In the next example, ?= is needed:
    DATA:  obj_struct  TYPE REF TO cl_abap_structdescr.
    obj_struct ?= cl_abap_structdescr=>describe_by_name( 'DDTAB_NAME' ).
    Regards,
    Angelo.

  • When I try to turn my iPhone off, it automatically restarts itself. It has never done this before; does anyone know why it might be doing this/how to stop it happening?

    When I try to turn my iPhone off, it automatically restarts itself. It has never done this before; does anyone know why it might be doing this/how to stop it happening?

    This had happened to me today as well. I gave constantly tried resetting it, (I don't particularly want to restore it), but earlier did you find that your headphones went funny? Mine would stop playing music, but the phone would keep going. And if I paused it, and then pressed play, No sound would come out. And if I took the headphones out while it was paused it would play on the device, but as before, not through the headphones. But, I fixed it (temporarily) by pulling the headphones out while it was playing, and plugged them back it. But normally this would pause the music, and it didn't, just continued on the phone, with no sound coming out of the speakers. And it would only last for a couple of minutes and happen again. Then I tried resetting the phone, and it wouldn't turn off. Them I fixed the turn off problem by placing on a dock, and I think this also fixed the headphone problem. But then I took it off and then on the dock, and now it won't play through the dock (but it charges) and it won't turn off, again!
    Also, apples customer serivice is plainly crap. This should be easy to fix. And I shouldnt have to pay a fee to ring them up for service help.

  • Wide casting problem

    Hi All,
    Can u explain Wide casting in detail ? already i gone through sdn links but still i didnt get clear .  please go through the follwing code snippet and explain where i made mistake in order to getting wide casting.. my problem is as wide casting i want to access the base class methods with reference of sub class when the base class methods are redefined in sub class(actually sub class reference access the  subclass methods only if we have same methods in base and as well as sub class) in my program after performing wide cast also it is accessing sub class methods only please send the answer.
    REPORT  ZNARROW_WIDE.
    CLASS C1 DEFINITION.
    PUBLIC SECTION.
    METHODS:M1,M2.
    ENDCLASS.
    CLASS C1 IMPLEMENTATION.
    METHOD M1.
    WRITE:/ ' THIS IS SUPER CLASS METHOD M1'.
    ENDMETHOD.
    METHOD M2.
    WRITE:/ ' THIS IS SUPER CLASS METHOD M2'.
    ENDMETHOD.
    ENDCLASS.
    CLASS C2 DEFINITION INHERITING FROM C1.
    PUBLIC SECTION.
    METHODS:M1 REDEFINITION.
    METHODS:M2 REDEFINITION,
                      M3.
    ENDCLASS.
    CLASS C2 IMPLEMENTATION.
    METHOD M1.
    WRITE:/ ' THIS IS SUB CLASS METHOD M1'.
    ENDMETHOD.
    METHOD M2.
    WRITE:/ ' THIS IS SUBCLASS METHOD M2'.
    ENDMETHOD.
    METHOD M3.
    WRITE:/ ' THIS IS SUB CLASS METHOD M3'.
    ENDMETHOD.
    ENDCLASS.
    DATA:O_SUPER TYPE REF TO C1,
         O_SUB TYPE REF TO C2.
    START-OF-SELECTION.
    CREATE OBJECT O_SUPER.
    CREATE OBJECT O_SUB.
    CALL METHOD O_SUPER->M1.
    CALL METHOD O_SUPER->M2.
    CLEAR O_SUPER.
    O_SUPER = O_SUB.
    CALL METHOD O_SUPER->('M3').
    SKIP 5.
    ULINE 1(80).
    CLEAR O_SUB.
    O_SUB ?= O_SUPER.
    CALL METHOD O_SUB->M1.
    CALL METHOD O_SUB->M2.
    CALL METHOD O_SUB->M3.
    Thanks in advance.
    sreenivas P

    Hi,
    consider the following sample code:
    REPORT  ZA_TEST93.
    class class_super definition.
      public section.
        data: var_area type i.
        methods:
        area importing length type i breadth type i.
    endclass.
    class class_super implementation.
      method area.
        var_area = length * breadth.
        write:/ 'Area of rectangle = '.
        write: var_area.
      endmethod.
    endclass.
    class class_sub definition inheriting from class_super.
      public section.
      data:height type i.
      methods:
      area redefinition.
    endclass.
    class class_sub implementation.
      method area.
        var_area = 6 * length * breadth * height.
        write:/ 'Area of the cube ='.
        write: var_area.
      endmethod.
    endclass.
    start-of-selection.
    data: object_superclass type ref to class_super,
          object_subclass type ref to class_sub,
          object2_superclass type ref to class_super.
    create object object_superclass.
    create object object2_superclass.
    create object object_subclass.
    call method object_superclass->area exporting length = 10 breadth = 5.
    "Narrow casting
    object_subclass->height = 10.
    object_superclass = object_subclass.
    call method object_superclass->area exporting length = 10 breadth = 10.
    "Wide casting
    object_superclass ?= object2_superclass.
    call method object_superclass->area exporting length = 10 breadth = 5.
    Explanation:
    In the above code, consider the super class named 'class_super'.
    This class has a method called 'area' which is used to calculate the area of a rectangle.
    Consider the subclass 'class_sub', which inherits all the attributes and methods of super class 'class_super'.
    Now we want to use the same method of super class 'class_super', 'area', but this time we want it to calculate the area of a cube.
    For this purpose we use the 'redefinition' keyword in the definition part of 'class_sub' and enter the code for cube area calculation in the 'area' method body in the implementation part of 'class_sub'.
    From the above code, consider the following code snippet:
    create object object_superclass.
    create object object2_superclass.
    create object object_subclass.
    call method object_superclass->area exporting length = 10 breadth = 5.
    Explanation: Two objects of the superclass and one object of the subclass are created and the 'area' method of the superclass is called to compute the area of a rectangle.
    Now consider what comes next:
    "Narrow casting
    object_subclass->height = 10.
    object_superclass = object_subclass.
    call method object_superclass->area exporting length = 10 breadth = 10.
    Explanation:
    We assign a value of 10 to the 'height' instance variable of the subclass object.
    Then we perform narrow casting in the next line(object_superclass = object_subclass.).
    Now the instance of the superclass(object_superclass) now points or refers to the object of the subclass, thus the modified method 'area' of the subclass is now accessible.
    Then we call this method 'area' of the subclass to compute the area of the cube.
    Moving on to the final piece of code:
    "Wide casting
    object_superclass ?= object2_superclass.
    call method object_superclass->area exporting length = 10 breadth = 5.
    Explanation:
    The object 'object_superclass' now refers to the object of the subclass 'object_subclass'.
    Thus the 'area' method of the superclass cannot be called by this object.
    In order to enable it to call the 'area' method of the superclass, wide casting has to be perfomed.
    For this purpose, the RHS of the wide casting must always be an object of a superclass, and the LHS of the wide casting must always be an object reference declared as 'type ref to' the superclass(objectsuperclass ?= object2_superclass.)._
    Otherwise a runtime error will occur.
    Finally the 'area' method of the superclass can now be called once again to compute the area of the rectangle.
    The output of the above example program is as follows:
    Area of rectangle =          50
    Area of the cube =      6,000
    Area of rectangle =          50
    Also note that wide casting cannot be performed on subclass objects, wide casting can only be performed on superclass objects that have been narrow cast.
    Hope my explanation was useful,
    Regards,
    Adithya.
    Edited by: Adithya K Ramesh on Dec 21, 2011 11:49 AM
    Edited by: Adithya K Ramesh on Dec 21, 2011 11:51 AM

  • HT5622 I am the owner of my iPhone 4 and it had not been updating and allowing me to download apps. So I decided to do factory setting, before doing so I had backed up my phone on my computer then I had erased everything from my iphone. But now I want to

    I am the owner of my iPhone 4 and it had not been updating and allowing me to download apps. So I decided to do factory setting, before doing so I had backed up my phone on my computer then I had erased everything from my iphone. But now I want to start everything from the beginning, and on my setting my Apple ID is present however when I put my password in it doesn't let me log in. The message that I receive says that I would have to remove my Apple ID  as it will not let me log in with that I'd even though I am the original owner, I have tried  everything on find my iPhone as well, even there my Apple ID not showing on the devise.
    If anyone has had a similar experience could you please advise me on what to do,
    Thanks

    You must have the credentials that were used to turn on Find my iPhone on the device. Without them, you can not get past the activation lock.

  • I changed jobs and had to change emails/Apple ID.  Before doing so, I did not save my photos from the photo stream to the camera roll.  Now, all the old pictures that are still on my iPhone are not streaming to the iPad, only new ones.  Please help.

    I changed jobs and had to change email/AppleID.  Before doing so, I did not copy the pics on the photo stream of my iPad to the album and now the only pics being synce with my iPad are new pics either saved or taken on phone.  Old pics are still on phone.  There has to be a way to get these pics to be able to stream them on to iPad, right?

    You have a couple of options to get them in your photo stream:
    Open the photos one at a time and take a screenshot.  This will add a new low resolution copy of the photo to the camera roll, which will then upload to your photo stream;
    Email the photos a few at a time to yourself, then save the attached photos to your camera roll.  This will add a copy of the photo at full resolution to your camera roll and upload to photo stream;
    Use an app like PhotoSync, which will allow you to wirelessly transfer copies of all your old photos to your computer all at once.  Then delete these photos from your camera roll and use PhotoSync to transfer them back from your computer to your camera roll.  These will be the original resolution and will upload to your photo stream.  (You need an app like this because iTunes will not transfer photos back to your camera roll, where they must be in order to add to your photo stream.)
    Or, you can add them to a shared stream and invite yourself as a subscriber (see http://help.apple.com/icloud/#/mmc0cd7e99).  The shared stream will appear on your iPad and you can either leave things this way, or save them to the camera roll on your iPad and delete the shared stream.  They won't be in your photo stream but they will at least be on your iPad.

  • Can anyone tell me why im getting this error while doing expdp?

    Hi,
    My question is
    I have a script scheduled in cronjob which is having stmts for taking export backup for many schemas.
    Before doing that it will remove all the dmp files in the directory to create new dmp files everyday.
    But yesterday, it took backup for only one schema, it failed for remaining schemas.
    So currently one dmp file is there in dmp destination.
    and previous day log files are there in log destinaton.
    So, after checking this i have taken logical backup for a single schema in background.
    then i checked in another terminal whether any backup is going on or not.
    It was showing nothing even though i have given the backup manually.
    So, i tried to take the backup again normally (not in background)
    then it was giving the following errors.
    ORA-31634: job already exists
    ORA-31664: unable to construct unique job name when defaulted
    Can any one tell why this happens?
    Thanks in advance.

    Error:     ORA-31664 (ORA-31664)
    Text:     unable to construct unique job name when defaulted
    Cause:     The job name was defaulted, and the name creation algorithm was
         unable to find a unique job name for this schema where the table
         name (for the master table) didn't already exist.
    Action:     Specify a job name to use or delete some of the existing tables
         causing the name conflicts.

  • Why think about Application virtualization before going to VDI or desktop virtualization

    Hi Team,
    I am new in ThinApp technology.
    My question is that "Why think about Application virtualization before going to VDI or desktop virtualization."
    Please help to clear my question.
    Thanks
    Yogesh

    With Application Virtualization you'll make any transition easier. While the term isn't really clear to understand for anyone new to the technology I usually find it easier to explain by calling it Application Isolation/Redirection, which actually gives a clearer idea of what it is doing. What ThinApp (or any other Application Virtualization) does is catch calls the operating system does to the registry and files and reroute that to a single contained environment. With Application Virtualization you can deploy your applications without touching the other applications or operating system. The nice thing about ThinApp is that it's clientless so there is no need for any backend or client. The runtime is contained in the ThinApp, which is why you can even use multiple versions at the same time.
    With VDI you try to consolidate resources and not buy 1000's of desktops every few years, because physical desktop migrations are a pain. You also try to make managing them easier because basically you'll only have to manage a single desktop (master image). But to get there you will have to do a migration, having Application Virtualization in place will make it an easy project instead of a hard one.
    The second reason why you would want to do it is because with ThinApp there is no need to actually deploy the application to the VDI, they can be shown on the machine but actually run from a share or even dynamically mapped with virtual disks.

  • Verifying which photos will be skipped BEFORE doing an import.

    When doing an import, is there any way to tell which photos will be considered "duplicates" BEFORE I actually do the import?  It's a little complicated to explain, but I'm in a situation where when I do an import, I sometimes end up importing photos that I thought would be skipped as duplicates.  When this happens, I have to go though hundreds of photos and manually select and delete all the duplicates.  If I could see that this was going to happen BEFORE doing the import -- i.e. if Lr could give me a list of photos that would be skipped before doing the import rather than after it -- I could take appropriate actions before doing the import.
    Thanks,
    Larry

    johnbeardy wrote:
    You could set up a smart collection to pick up files with "-2" in the name.
    But why the copying back and forth? Can you not keep your catalogue pointed at the central drive? If for example you need to go offline or have local copies for a while, you could use the Update Folder Location to switch the catalogued folder between your local drive or the central one. It sounds like there''s some aspect of your workflow that's making things in LR unnecessarily awkward.
    John
    The "-2" could pick up other files.  I use dates in names, so "2009-08-20" would be picked up by the search.
    Regarding the "copying back and forth," the issue stems from the fact that the "central drive" is NOT a "Lr" drive.  The photos on this drive are accessed by more than one person using more than one application.  This would lead to complications if I actually manipulated these photos in Lr since each person would have to constantly worry about keeping everything in sync, including making corrections or changes to the folder structure.  By having a completely separate copy of everything on my own "local" drive I don't have to worry about this.  I also end up with a completely "clean" backup copy of all my photos on the main drive in case anything gets corrupt in Lr (although I do also keep ANOTHER backup of my LOCAL drive, so I have multiple redundant backups.)
    As I mentioned earlier, it's difficult to completely explain all the aspects of the setup, but suffice it to say that it evolved over time based on the issues that arose for us.  There are a LOT of factors to consider given any particular situation (too many to even list off the top of my head), but my setup satisfies "most" of my parameters in relatively simple ways.  Unfortunately, there is no way to completely resolve "every" issue (hence this thread) -- my setup is simply the best approach I've found given MY particular needs.
    In other words, given all of my (our) particular needs, I don't believe that this setup is "unnecessarily" awkward.  It's perhaps more complex than other setups, but given the situation of multiple people, multiple networked systems, and multiple applications, I think it's actually "relatively" straight forward.
    Larry

  • Wide casting

    Hi all,
    Can anybody please tell the usuage of wide casting.
    preferable with simple code.
    Anirban Bhattacharjee

    Hi,
    1. Wider/up casting :
    This means a ref object used is of a parent. Now here technically speaking you can only call the methods of the parent class and not of the child class. Even if the parent object is referencing to a child object at runtime, the compiler does not allow you to call the child method.
    Wide casting does not have run-time errors as the compiler is able to identify the error at compile time only.
    Wide casting is helpful when you want to have a generic parameter as the importing parameter in OOPs.
    For eg.
    Class p1
    method x.
    Class c1 parent p1
    method y.
    Class c2 parent p1
    method z.
    In the above example both class c1 and c2 are subclasses of p1 and therefore has method x.
    Now let us say the user at runtime can pass object of c1,c2 or p1 and method x has to be capable of receiving all these, then in such case you can assign reference object of parent to method x.
    So method x can be defined as follows
    Class p1
    method x importing p  -
    > where p is type ref to p1.
    I hope this explains your query.
    Regards,
    Saurabh

  • Why there is implicit commit before and after executing DDL Statements

    Hi Guys,
    Please let me know why there is implicit commit before and after executing DDL Statements ?
    Regards,
    sushmita

    Helyos wrote:
    This is because Oracle has design it like this.Come on Helyos, that's a bit of a weak answer. :)
    The reason is that it makes no sense to update the structure of the database whilst there is outstanding data updates that have not been committed.
    Imagine having a column that is VARCHAR2(50) that currently only has data that is up to 20 characters in size.
    Someone (person A) decides that it would make sense to alter the table and reduce the size of the column to varchar2(20) instead.
    Before they do that, someone else (person B) has inserted data that is 30 characters in size, but not yet committed it.
    As far as person B is concerned that insert statement has been successful as they received no error, and they are continuing on with their process until they reach a suitable point to commit.
    Person A then attempts to alter the database to make it varchar2(20).
    If the database allowed that to happen then the column would be varchar2(20) and the uncommitted data would no longer fit, even though the insert was successful. When is Person B going to find out about this? It would be wrong to tell them when they try and commit, because all their transactions were successful, so why should a commit fail.
    In this case, because it's two different people, then the database will recognise there is uncommitted transactions on that table and not let person B alter it.
    If it was just one person doing both things in the same session, then the data would be automatically committed, the alter statement executed and the person informed that they can't alter the database because there is (now) data exceeding the size they want to set it to.
    It makes perfect sense to have the database in a data consistent state before any alterations are made to it, hence why a commit is issued beforehand.
    Here's something I wrote the other day on the subject...
    DDL's issue a commit before carrying out the actual action
    As long as the DDL is syntactically ok (i.e. the parser is happy with it) then the commit is issued, even if the actual DDL cannot be executed for another reason.
    Example...
    We have a table with some data in it...
    SQL> create table xtest as select rownum rn from dual;
    Table created.
    SQL> select * from xtest;
            RN
             1We then delete the data but don't commit (demonstrated by the fact we can roll it back)
    SQL> delete from xtest;
    1 row deleted.
    SQL> select * from xtest;
    no rows selected
    SQL> rollback;
    Rollback complete.
    SQL> select * from xtest;
            RN
             1
    SQL> delete from xtest;
    1 row deleted.
    SQL> select * from xtest;
    no rows selectedSo now our data is deleted, but not committed, what if we issue a DDL that is syntactically incorrect...
    SQL> alter tab xtest blah;
    alter tab xtest blah
    ERROR at line 1:
    ORA-00940: invalid ALTER command
    SQL> rollback;
    Rollback complete.
    SQL> select * from xtest;
            RN
             1... the data can still be rolled back. This is because the parser was not happy with the syntax of the DDL statement.
    So let's delete the data again, without committing it, and issue a DDL that is syntactically correct, but cannot execute for another reason (i.e. the database object it refers to doesn't exist)...
    SQL> delete from xtest;
    1 row deleted.
    SQL> select * from xtest;
    no rows selected
    SQL> truncate table bob;
    truncate table bob
    ERROR at line 1:
    ORA-00942: table or view does not exist
    SQL> rollback;
    Rollback complete.
    SQL> select * from xtest;
    no rows selectedSo, there we have it. Just because the statement was syntactically correct, the deletion of the data was committed, even though the DDL couldn't be performed.
    This makes sense really, because if we are planning on altering the definition of the database where the data is stored, it can only really take place if the database is in a state where the data is where it should be rather than being in limbo. For example, imagine the confusion if you updated some data on a column and then altered that columns datatype to be a different size e.g. reducing a varchar2 column from 50 character down to 20 characters. If you had data that you'd just updated to larger than 20 characters whereas previously there wasn't, then the alter table command would not know about it, would alter the column size and then the data wouldn't be valid to fit whereas the update statement at the time didn't fail.
    Example...
    We have a table that only allows 20 characters in a column. If we try and insert more into that column we get an error for our insert statement as expected...
    SQL> create table xtest (x varchar2(20));
    Table created.
    SQL> insert into xtest values ('012345678901234567890123456789');
    insert into xtest values ('012345678901234567890123456789')
    ERROR at line 1:
    ORA-12899: value too large for column "SCOTT"."XTEST"."X" (actual: 30, maximum: 20)Now if our table allowed more characters our insert statement is successful. As far as our "application" goes we believe, nay, we have been told by the database, we have successfully inserted our data...
    SQL> alter table xtest modify (x varchar2(50));
    Table altered.
    SQL> insert into xtest values ('012345678901234567890123456789');
    1 row created.Now if we tried to alter our database column back to 20 characters and it didn't automatically commit the data beforehand then it would be happy to alter the column, but then when the data was committed it wouldn't fit. However the database has already told us that the data was inserted, so it can't go back on that now.
    Instead we can see that the data is committed first because the alter command returns an error telling us that the data in the table is too big, and also we cannot rollback the insert after the attempted alter statement...
    SQL> alter table xtest modify (x varchar2(20));
    alter table xtest modify (x varchar2(20))
    ERROR at line 1:
    ORA-01441: cannot decrease column length because some value is too big
    SQL> rollback;
    Rollback complete.
    SQL> select * from xtest;
    X
    012345678901234567890123456789
    SQL>Obviously, because a commit statement is for the existing session, if we had tried to alter the table column from another session we would have got
    SQL> alter table xtest modify (x varchar2(20));
    alter table xtest modify (x varchar2(20))
    ERROR at line 1:
    ORA-00054: resource busy and acquire with NOWAIT specified
    SQL>... which is basically saying that we can't alter the table because someone else is using it and they haven't committed their data yet.
    Once the other session has committed the data we get the expected error...
    ORA-01441: cannot decrease column length because some value is too bigHope that explains it

Maybe you are looking for