ABAP OBJECTS: Dynamic Create object

Hi folks!
I have a problem... I need to create a dynamic type object with:
<b>DATA: my_instance TYPE REF TO class1.
CREATE OBJECT my_instance TYPE (class2).</b>
<i>* where class1 is a superclass of class2.</i>
When I do:
<b>my_instance ?= m_parent.</b>
<i>* where m_parent is an instance of class1</i>
My problem is when I want to access to an attribute of the class2, the compiler says that it cannot find the attribute <i>(this is OK, because the attribute is only in the class2).</i>
My question:
Is there anyway to access to an atribute of second class when is not in the first class? (i don't want to create the attribute as an attribute of the first class).
Thanx!!!!

Hi David,
When you do the debugging, you are dealing with run-time - i.e., the program is now running and you are just interrupting it at each statement to examine the program state. You will reach the point where the object is already created. That is why you can see all those attributes. But when you comiple, the program is not yet <i>running</i>, so the attributes will be unknown because of the dynamic type specification.
I think you will have to redesign the program logic. As i had already said in my earlier post, it is not proper to have the attributes specified statically while the class itself is specified dynamically.
Your situation is somewhat similar to -
DATA ITAB TYPE TABLE OF SPFLI.
PERFORM TEST TABLES ITAB.
FORM TEST TABLES ITAB.
  LOOP AT ITAB.
    WRITE: / ITAB-CARRID.
  ENDLOOP.
ENDFORM.
Hope the point is clear.
Regards,
Anand Mandalika.

Similar Messages

  • Dynamically created object

    Hi
    I did not find any way of accessing a dynamically created
    object by using notation this[id].
    As the code below shows, only hard coded id objects are
    recognised by this[id] notation.
    Any way to do it ?
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    creationComplete="init()">
    <mx:Script>
    <![CDATA[
    import mx.controls.*;
    public var l:Label;
    public function init():void {
    l = new Label();
    l.id = 'label1';
    l.text = 'firstname';
    addChild(l);
    public function fred(event:Event):void {
    mytextarea1.text+=this['mytextarea1'].name + '\n';
    mytextarea1.text+=this['label1'].name + '\n';
    ]]>
    </mx:Script>
    <mx:TextArea id="mytextarea1" width="1300"
    height="200"/>
    <mx:Button click="fred(event)" />
    </mx:Application>

    Thanks guys but I think my example is too simple compared to
    my "real world" current problem ...
    In my project, I dynamically create containers and children.
    I'd like to reach directly a then dynamically created child by its
    id, but notation this[id] is not recognised.
    A better example : form f1 (id='form1) contains 2 labels (ids
    'form1label1' and 'form1label2') ; f1 is included in form f0.
    Calling this['form1label1'] crashed even though it is a
    declared id control ! The same example using <mx> tags would
    not crash...
    And I have gone aroud 10000 articles but never found an
    answer to this.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    creationComplete="init()">
    <mx:Script>
    <![CDATA[
    import mx.controls.*;
    import mx.containers.*;
    public function init():void {
    var f0:VBox = new VBox();
    var f1:VBox = new VBox();
    var l:Label;
    f0.id = 'form0';
    f1.id = 'form1';
    l= new Label();
    l.id = 'form1label1';
    l.text = 'mobile';
    f1.addChild(l);
    l = new Label();
    l.id = 'form1label2';
    l.text = 'work';
    f1.addChild(l);
    f0.addChild(f1);
    addChild(f0);
    public function fred(event:Event):void {
    mytextarea1.text+=Label( this['form1label1'] ).text + '\n';
    ]]>
    </mx:Script>
    <mx:TextArea id="mytextarea1" width="1300"
    height="200"/>
    <mx:Button click="fred(event)" />
    </mx:Application>

  • Accessing dynamically created objects

    If objects are created dynamically in AS3, using code like
    this:
    for (var num:Number = 0; num<10; num++){
    var txtFld:TextField = new TextField();
    txtFld.text = 'This is the original text';
    this.addChild(txtFld);
    then later, i want to changet the text of one of the
    TextFields, how can I do that? The only instance listed in the
    variables is a single instance of "txtFld" and it is the last one
    that is created. How can I access the others?
    Thanks

    Two ways pop to my mind.
    Give them a name property when you create them and then use
    getChildByName().
    Push each instance into an array/vector as you create it and
    then iterate over the values in the array.
    A combination of both?

  • Access dynamically created objects

    Hello!
    I create some images dynamically by running a for from 1 to a
    variable preset. The pictures have the IDs image1, image2 ...
    ("image"+i). I then add other properties.
    Problem is for each I need an onMouseOverHandler thant will
    swap the image with another.
    I can get the target image with event.currentTarget.id. But I
    cannot set it's properties with this["image"+i].source (I need to
    change the ones up to that as well) and I cannot access it with
    this.getChildByName("image"+i).source either.
    What am I doing wrong please?

    "M*A*S*H 4077" <[email protected]> wrote in
    message
    news:go74q6$fbb$[email protected]..
    > Hello!
    >
    > I create some images dynamically by running a for from 1
    to a variable
    > preset.
    > The pictures have the IDs image1, image2 ...
    ("image"+i). I then add other
    > properties.
    >
    > Problem is for each I need an onMouseOverHandler thant
    will swap the image
    > with another.
    > I can get the target image with event.currentTarget.id.
    But I cannot set
    > it's
    > properties with this["image"+i].source (I need to change
    the ones up to
    > that as
    > well) and I cannot access it with
    this.getChildByName("image"+i).source
    > either.
    >
    > What am I doing wrong please?
    ID is about as useful as your appendix when you create
    objects dynamically.
    The event.target property will contain a reference to your
    image.

  • This[id] doesn't see dynamically created objects????

    Hey all!
    If i have
    <mx:Canvas id="TopCanvas" initialize="Init()">
    <mx:Canvas id="VisibleCanvas" >
    </mx:Canvas>
    </mx:Canvas>
    <fx:Script>
    function Init(){
    var NewO = new Canvas();
    NewO.id="InvisibleCanvas";
    TopCanvas.addChild(NewO);
    if (this["VisibleCanvas"]){
    //We can see non-dynamically created canvas
    if (this["InvisibleCanvas"]){
    //ERROR we cannot see the new one!
    Help please! How to access dynamically created Canvases via their id? I know i can save linkage to them in array, but i need to do it through id.
    Cheers!

    If you set the id property on a dynamically created instance, you can check
    the id of an instance later if it happens to be a target of an event, for
    example.  But it will not be assigned to a variable in the document.
    By default, MXML generates a non-dynamic class so you can't add properties
    to it at runtime.  You can set the name property and search the immediate
    parent by calling getChildByName, but if the parent is not the document, you
    still can't search the document.

  • HOW TO remove nodes add nodes dynamically create objects branchgroup

    After much trial and error, frustration and reading this forum I have come across a good way to dynamically add/remove objects. This is working in my model with 1.3 and jdk 1.4.1_02 Sorry if its sloppy.
    Here goes:
    Adding objects (cap bits may not be optimised):
    (A)
    BranchGroup newDynObj = null;
    switch (workerType)
    case 1: //create a rawEntry BranchGroup
    newDynObj = new RawEntry();
    break;
    case 2: //create a Finshed Node
    newDynObj = new FinishedNode();
    break;
    default:
    newDynObj.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    newDynObj.setCapability(BranchGroup.ALLOW_DETACH);
    newDynObj.setCapability(Group.ALLOW_CHILDREN_READ);
    newDynObj.setCapability(Group.ALLOW_CHILDREN_WRITE);
    Transform3D t = new Transform3D();
    t.set(scale, new Vector3d(xpos, ypos, zpos));
    TransformGroup objTrans2 = new TransformGroup(t);
    objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objTrans2.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
    objTrans2.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
    objTrans2.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    Sphere obj = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS,
    5, app);
    //add to scene graph
    objTrans2.addChild(obj);
    newDynObj.addChild(objTrans2);
    newDynObj.compile();
    return newDynObj;
    call this ftn with:
    Space3DPanel.objTrans.addChild(createObject(createAppearance(workerType), 0.04, x, y, z, 2)); where objTrans is your tansformGroup
    Removing branchgroup:
    Its easy to add. But the trick is to delete/remove these !?! Detach doesnt seem to do anything. The method/pattern that works for me is to..
    1. make a new class subclassing BranchGroup like this:
    public class FinishedEntry extends BranchGroup
    { private String type;
    public FinishedEntry(){  }
    public FinishedEntry(String type)
    { this.type = type; }
    and
    public class RawEntry extends BranchGroup
    private String type;
    public RawEntry(){  }
    public RawEntry(String type)
    { this.type = type;}
    2. To when adding the BG to the TG of the parent (objTrans)
    add a BG of the type you subclassed.
    see (A) above.
    3. Now scan through the children of the TG that you have been adding these children to. Like this:
    static synchronized public void removeNodeFromModel(int workerType)
    try {
    switch (workerType)
    case 1: //raw Entry
    for (int i = 0; i < Space3DPanel.objTrans.numChildren(); i++)
    if (Space3DPanel.objTrans.getChild(i) instanceof RawEntry)
    Space3DPanel.objTrans.removeChild(i);
    break;
    break;
    case 2: //result Entry
    for (int i = 0; i < Space3DPanel.objTrans.numChildren(); i++)
    if (Space3DPanel.objTrans.getChild(i) instanceof FinishedNode)
    Space3DPanel.objTrans.removeChild(i);
    break;
    } //end for
    break;
    default:
    } catch (Exception e) { e.printStackTrace(); }
    The main idea is to use instanceof !! then use removeChild (see above).. Also, you can compile your BGs using this method.
    Thanks for the great forum!
    Jacob Pyrett
    [email protected]

    First, to add child nodes to a branch group, you must follow two rules:
    (1) The child you are adding to the branch group is also a BranchGroup
    (2) The BranchGroup.ALLOW_CHILDREN_EXTEND capability is set
    From here, you are able to add children on the fly.
    To remove a child from the branch group was harder to figure out, but I eventually got it to work. To accomplish this you must do the following:
    (1) have the capability BranchGroup.ALLOW_DETACH) set on the child BranchGroup you wish to remove.
    (2) call the child's detach() method rather than calling the parent's removeChild()
    Hope this helps.

  • Dynamically create objects at runtime - Collections?

    Dear Experts
    During runtime i need to create several objects. Can you help me by pointing out the best practice here? Is it possible to store Man and Dog object in the single collection?
    Thank you for the help
    The code is as follows
    abstract class Mammal {
        String name;
        Mammal(String n)
            name = n;
        void sleep()
            System.out.println( name + "! is asleep! zzzzzzz!");
        abstract void talk();
    class Man extends Mammal {
        Man(String n)
            super(n);
        void talk()
            System.out.println("H1 My Name is "+name+" How do you do?");
    class Dog extends Mammal {
        Dog(String n)
            super(n);
        void talk()
            System.out.println("Wrf!Wrf!");
    public class Main {
        public static void main(String[] args) {
           Dog d1 = new Dog("Dots");
           Man m1 = new Man("Joe");
           Dog d2 = new Dog("Dollar");
           Man m2 = new Man("Mike");
           // ideally i would like to push this into collection of objects
    }

    standman wrote:
    thank you
    i tried this. If it is wrong please let me know. If all you need is a List, it may work fine. I didn't try it. Some suggestions:
    Declare 'al' as a List:
    List al = new ArrayList();Then if you decide you need a LinkedList or other List, you only have to change the right side construction.
    Try to use generics (as YoungWinston suggested).
    Use an Iterator or an "enhanced 'for' loop" for the iteration, instead of constantly checking "size" and using "get(i)". Since you have a short random-access list (ArrayList), your loop may work okay. But, if you had a long non-random-access list (such as LinkedList), an Iterator or "enhanced 'for' loop" (which uses an Iterator behind-the-scenes) would work faster.
    If you do need thread-safety, there are other considerations, too.

  • Preloading dynamically created objects

    Hi,
    I have some Object I would like to create on runtime, but it initialization takes some time. So normally I would code something like
    Class SimpleFoo
    private BigObject bO = new bO("parameters here");
    BigObject getBigObject()
    return bO;
    }but now I have a lot (say around 30 in the total class, which is more complicated) of them, so it would be something like
    Class MessyFoo
    private BigObject bOprime = new bO("prime parameters here");
    private BigObject bOeven = new bO("even parameters here");
    BigObject getBigObject(int i)
    if (isPrime(i))
    return bOprime;
    else if (isEven(i))
      return bOeven;
    }which gets really messy. I'd rather code
    Class CleanLookingFoo
    BigObject getBigObject(int i)
      if (isPrime(i))
       return new bO("prime parameters here");
      else if (isEven(i))
        return new bO("even parameters here");
    }but then I miss the caching and initialization advantages. What is the best way to build this? So far my best option is to pre-process the CleanLookingFoo and make a MessyFoo out of it, and then pass it through to the Java compiler, which probably isn't the best solution.

    The usual pattern is to use a synchronization mechanism and a lazy initialiser. The simplest mechanism is to use a holder class with a static field, since it won't get initialised until it's first used:
    public class LazyBigObjects {
         static class BigObject {
              BigObject (String params) {
                   System.out.println(params);
         static class PrimeBigObjectHolder {
              static final BigObject INSTANCE = new BigObject("prime parameters here");
         static class EvenBigObjectHolder {
              static final BigObject INSTANCE = new BigObject("even parameters here");
         public static BigObject getBigObject(int i) {
              System.out.println("getBigObject called with " + i);
              switch (i) {
                   case 0: {
                        return PrimeBigObjectHolder.INSTANCE;
                   case 1: {
                        return EvenBigObjectHolder.INSTANCE;
                   default:
                        throw new IllegalArgumentException(i + " out of range.");
         public static void main (String...args) {
                 getBigObject(0);
              getBigObject(1);
    }Output:
    getBigObject called with 0
    prime parameters here
    getBigObject called with 1
    even parameters here
    The JVM handles synchronisation issues of class initialisation, so you don't need to do anything about that.

  • Getting the coordinates of dynamically created objects

    i have created 3 movie clips via actionscript and given them
    instance names of cS_1, cS_2, and cS_3. however, i can't manage to
    trace their x coordinates. i know i gotta do something with
    getChildByName but i'm really stuck and can't figure it out. Could
    someone please explain to me what i have to do like explaining to
    an 8 year old. Thank you!
    Here's the code:

    To use the getChildByName method you want to cast a MovieClip
    variable to capture a reference to it, as in:
    var cs1:MovieClip = this.getChildByName(cs_1);
    trace(cs1.x);

  • Dynamically create object

    i want to write a program that need to connect database.
    The table should be like this:
    uid, type
    1, input
    2, password
    3, report
    And i already have following classes:
    public String input() {...};
    public String password() {...};
    public String report() {...};
    then the java program fetch the row:
    while (next_record)
    the_type = column(type);
    (the_type) new_object = new (the_type)(); //this line is my problem!!!
    Do any one can tell me how to write the above line correctly?

    Thank you!
    i have used forName and newInstance to solve my problem.

  • Dynamic creating SAPBobsCOM objects using reflection

    Hi All,
    I'm writing a tool (C#) for SBO for exporting object (oItems, oBanks etc.) to XML files. And I have a problem how to dynamically create object by it's string description. I'm trying to create it using System.Reflection, but cant't find right way to create it.
    It must be like that, but it doesn't work:
               Type  sboObject = System.Type.GetType("SAPbobsCOM.Items, Interop.SAPbobsCOM", true, true);
               object ibaseObject = Activator.CreateInstance(sboObject);
    Any ideas?)

    Hi
    I've writen this code for instantiating DI API objects using .NET reflection
            private object getObjectBo(int tipo) //tipo: integer representing the object type
                object o = null;
                try
                    Type tipoComp = kernel.Company.GetType(); //Type SAPbobsCOM.Company
                    MethodInfo info = tipoComp.GetMethod("GetBusinessObject");
                    object[] parametros = new object[1]; //Parameters of GetBusinessObject
                    object tipoObj = Enum.ToObject(typeof(SAPbobsCOM.BoObjectTypes), tipo);
                    parametros[0] = tipoObj;
                    o = info.Invoke(kernel.Company, parametros);  //Calling GetBusinessObject           
                catch (Exception ex)
                    kernel.Application.MessageBox(ex.Message, 0, "", "", "");
                return o;
    The object returned is COM object (not managed code) then we can't use .NET reflection directly for exploring its methods and attributes .. I think we should use C++ and IDispatch interface, but i don't know how do this yet.
    Hope it helps.
    Regards

  • Why objects are  dynamically created in java

    Why objects are dynamically created in java even if dynamically created object requires more space & more memory references as compared to static object?

    I don't even know where to start...
    KAMAL.MUKI wrote:
    Why objects are dynamically created in javaWhat is the alternative?
    even if dynamically created object requires more space & more memory referencesCan you prove that?
    as compared to static object?Can you define "static object"?
    I vote "troll".

  • CREATE OBJECT  in OOP

    hello experts,
    I am new to ABAP OOP world and having a doubt. Whenever we are creating an object using CREATE OBJECT statement in export parameter we pass something. For eg if i create an object of CL_GUI_CUSTOM_CONTAINER in EXPORT parameter we pass CONTAINER_NAME. How we can come to know wat to pass in EXPORT parameter while creating an object of  an unknown class.

    Those are the values passed to the constructors, check the method constructor of the class and its parameters.

  • Create object/package

    Hi,
    in 9i version (db 9.2.0) is it possible to recreate
    1-an object by
    CREATE OBJECT newobject AS myobject
    or
    2-a package by
    CREATE PACKAGE newpackage AS mypackage ?
    just like
    CREATE TABLE newtable AS SELECT * from mytable
    Many thanks before and happy new year.

    AS keyword is acceptable only with TABLE object of CREATE clause and not for any other object.
    CREATE TABLE DUP_EMP AS SELECT * FROM EMP;
    its called CTAS (Create Table As Select).

  • Is it possible to dynamically create form fields in PDF form?

    Hi all,
    I would like to dynamically create object like textbox, dropdown list from xml data. For example:
    When I receive following xml data:
    <field name="Check Box" type="selectbox"/>
    <field name="Text Field" type="textbox"/>
    I want to generate 2 form fields check box and text field with title "Check Box" and "Text Field" accordingly.
    Is it possible to do it in javascript for PDF form?
    Thank you and regards,
    Anh

    You cannot dynamically create objects on the fly like that but you can create interpret the XML and create an XDP file (which is the language of the template file) then bring that into Designer and create a PDF from that.
    Paul

Maybe you are looking for

  • What's wrong with Musicstore?

    Has anyone else been experiencing crashes when they try to access certain categories on Musicstore? I'm using the latest iTunes and the problem started yesterday - I had downloaded some content the day before with no problems. I've tried malware scan

  • Checkbox and date/text feild

    I need to create a form with a checkbox and a date/text feild in the same row. Is this possible? An example is below: Form [ check box ] name of document [date/text feild] [  ] document name [1/30/2014]

  • Automatic updation of org data while creating wbs.

    While creating a new wbs, can we inherit organizational data like plant, profit center automatically from its higher level wbs, if this data does not exist in project profile. Please assist. Regards, Rahul

  • Can we capture two types of Serial Numbers for a material?

    Hi, I have scenario where i need to capture two different types of serial numbers for a material. This scenario is very similar to the below one - Say if a CAR is a serialized material, then i want to capture engine no. and chasis no. for each car. I

  • Retry option in partnerlink of BPEL.

    Hi All, Is anyone succeded using retry option in the partnerlink of BPEL. I tried by setting the retryMaxCount and retryInterval property in the partnerlink. But that doesn't seems to work. I couldn't able to see anything in the audit trail of BPEL C