Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ABAP Objects - MVC

Former Member
0 Likes
1,063

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,012

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.

7 REPLIES 7
Read only

Former Member
0 Likes
1,013

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.

Read only

0 Likes
1,012

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?

Read only

0 Likes
1,012

We can declare it as an object like

DATA : obj TYPE REF TO object.

Read only

0 Likes
1,012

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

Read only

0 Likes
1,012

yes its correct the type should be class_name.

Read only

0 Likes
1,012

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( ).

Read only

0 Likes
1,012

After shifted the o_model TYPE REF TO zcl_test_model to zcl_test_control attribute. The program compiled successfully.

Thanks to all.