‎2009 Apr 28 2:57 AM
Hello all,
I am trying to a tutorial from a website which were published by Mr Naimesh Patel.
It is a tutorial showing an example of MVC of ABAP Objects.
You can find the URL http://help-abap.blogspot.com/2008/10/abap-objects-design-patterns-model-view_13.html.
I have tried to copy the necessary code including methods and parameters as provided in the article. However while compiling, I got an error Field "O_MODEL->GET_DATA" is unknown.
Based on the article and code, anyone knows how should I resolve this?
What should I define for o_model?
I cant wait for the author to reply my message as I do not know when he will be asnwering me question.
Thanks in advance.
‎2009 Apr 28 3:41 AM
Have you declared any attribute with O_model?
This type of error comes when we have not declared any attribute or u might have declared but written incorrectly (spelling) in method.
‎2009 Apr 28 3:41 AM
Have you declared any attribute with O_model?
This type of error comes when we have not declared any attribute or u might have declared but written incorrectly (spelling) in method.
‎2009 Apr 28 3:45 AM
Hi Pradeep,
Thanks for your reply. Yes, you are right. I have not declared the o_model, as the article does not mentioned this.
Any idea what should the o_model defines in attribute?
‎2009 Apr 28 4:12 AM
We can declare it as an object like
DATA : obj TYPE REF TO object.
‎2009 Apr 28 4:22 AM
Hello Myahsam
The definition of O_MODEL as root class OBJECT obviously does not work because this class does not have any methods.
However, it is clear what O_MODEL should be because the Controller class is a composition containing a reference to the model class as well as the view class. Thus:
" O_... = Object instance attribure
" ..._MODEL = representing the model in MVC
DATA: o_model TYPE REF TO zcl_model.
Well, that's what Naimesh says in this tutorial:
>Our controller class ZCL_CONTROL will have a method GET_OBJECT which will give us an object of the >model class. We require a public attribute which can refer to the object created in the method >GET_OBJECT.
>Controller Method definition:
Regards
Uwe
‎2009 Apr 28 4:26 AM
‎2009 Apr 28 5:08 AM
Hi all,
After added in the o_model TYPE REF TO zcl_test_model.. I am still having the same error message "Field "O_MODEL->GET_DATA" is unknown.".
*&---------------------------------------------------------------------*
*& Report ZTEST_OOP_MVC_ALV
*&---------------------------------------------------------------------*
REPORT ZTEST_OOP_MVC_ALV.
*
START-OF-SELECTION.
*---------
* Controller
*---------
DATA: lo_control TYPE REF TO zcl_test_control,
o_model TYPE REF TO zcl_test_model.
*
* Initiate controller
CREATE OBJECT lo_control.
*
* Get the object from Control
CALL METHOD lo_control->get_object
EXPORTING
if_name = 'ZCL_TEST_MODEL'.
*
*---------
* Model - Business Logic
*---------
* Date Range
DATA: r_erdat TYPE RANGE OF vbak-erdat,
la_erdat LIKE LINE OF r_erdat.
*
la_erdat-sign = 'I'.
la_erdat-option = 'BT'.
la_erdat-low = sy-datum - 10.
la_erdat-high = sy-datum.
APPEND la_erdat TO r_erdat.
*
* Get data method
CALL METHOD lo_control->o_model->get_data
EXPORTING ir_erdat = r_erdat.
*
*---------
* View - ALV output
*---------
DATA: lo_alv TYPE REF TO cl_salv_table,
lx_msg TYPE REF TO cx_salv_msg.
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = lo_control->o_model->t_vbak ).
CATCH cx_salv_msg INTO lx_msg.
ENDTRY.
*
*Displaying the ALV
lo_alv->display( ).
‎2009 Apr 28 8:32 AM
After shifted the o_model TYPE REF TO zcl_test_model to zcl_test_control attribute. The program compiled successfully.
Thanks to all.