In my main controller I use do_init( ) to create my model instances and hope to access them via me->m_parent and its m_models attribute in my sub_controllers. I want to do this without having to create instances in every sub_controller's do_request, do_handle_event, etc.
DO_REQUEST of sub_controller
data: main_model type ref to cl_bsp_model,
main type ref to cl_bsp_controller2,
test type string.
main ?= me->m_parent.
main_model = main->get_model( 'plmMain' ).
****problem****
test = main_model->test. "test = attribute in the model.
*****************
Everything I need is available is there at runtime however, I can't compile it! I have figured out how to handle this if I create an instance:
data: main type ref to cl_bsp_controller2,
model type ref to zcl_pmfront_m_obj,
det_model type ref to zcl_pmfront_m_det,
table_event type ref to cl_htmlb_event_tableview,
rowselection type i.
main ?= m_parent.
...
if htmlb_event is bound and htmlb_event->server_event = 'myequnr'.
table_event ?= htmlb_event.
rowselection = table_event->rowselection.
model ?= main->get_model( 'mo' ).
det_model ?= main->get_model( 'md' ).
det_model->sel_event = 'myequnr'.
det_model->sel_equnr = model->zget_selected_equnr(
row = rowselection ).
endif.
But this is undesireable because we have to create instances and hardcode the class name into each and every controller method.
I know about storing model instances in an application class, but we shouldn't have to create instances every time we want access to a model in a sub_controller.
I would appreciate any advice on this matter and can provide any additional code if my problem isn't clear. Thanks in advance.