Skip to Content
author's profile photo
Former Member

How to access attributes of one model class from some other model


Can i access a internal table that is populated in one model class of mine. and has been set as the attribute of that class from another model or a controller of teh same BSP application.

Can i simply create a object of the model class and access it.

Please advice



Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • author's profile photo
    Former Member
    Aug 09, 2004 at 12:50 PM

    Here were two conversations over in the ABAP forum dealing with tables and classes.

    How to pass an internal table to a Method?

    Now that they answer your question directly, but might help out.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Aug 09, 2004 at 01:34 PM

    Hello Nikhil,

    yes, this is possible.

    Check out the controller-method "GET_MODEL". As you can see in the coding of the method there is a internal list of models you created in your MVC.

    Get your instance by the model id 😊

    Check this out. If this does not work we go the hard way via the main/sub-controllers....

    Regards, Bernd

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Thomas Jung


      to put an instance of the model-class to your controller is a very common way and described in the SAP Standard Examples:

      Create a model in the do_init and set it to an attribute (here called 'model' which has a reference to your model class:

      me->model ?= me->create_model( class_name = 'ZCL_MODEL_CLASS'
                                       model_id   = 'myownmodel' ).

      In the do_request of your main controller you set it to your view as page attribute:

      * datadeclaration
        DATA: li_content TYPE REF TO if_bsp_page.
      * output current view (create, set attibutes, and call)
        li_content = create_view( view_name = 'main.htm' ).
      * set attribute model if needed
        li_content->set_attribute( name = 'model' value = model ).
      * call master views
        call_view( li_content ).

      In a sub controller you first get the model from the main controller in the do_init and set it then to an own attribute:

      * create reference to parent controller class
        DATA: lr_my_parent TYPE REF TO zcl_main_controller.
      * get main controller from attribute
        lr_my_parent ?= me->m_parent.
        set_model( model_instance = lr_my_parent->model
                         model_id = 'myownmodel' ).
        me->model = lr_my_parent->model.

      In do_request you pass it your view (see above).

      Regards, Bernd

  • Aug 09, 2004 at 09:05 PM


    I think the answers you have received are good. However, this implies that you must come back and flag your questions as answered. In addition, SDN is now using a contributor reward system. Which means your question has 10 points that can be assigned to people helping you.

    Recommended is to give 6 and/or 10 points as appropriate, and 2 for each helpful answer. Please do this for your previous quesions as well. Some of them are still flag as unanswered with no comments from your side indicating status quo. See also Contributor" target="_blank">">Contributor Recognition Program FAQ.

    This is important as recognition to those people that have invested the extra to help you. I have also previously emailed you on this topic.


    Add comment
    10|10000 characters needed characters exceeded