打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ABAP Objects Design Patterns – Model View Controller (MVC) Part 2

转载自 By Naimesh Patel

In this post, we will see how we can implement the MVC (Model-View-Controller) design pattern in ABAP using the Objects. If you have not read the previous discussion about MVC: ABAP Objects Design Patterns – Model View Controller (MVC) Part 1, than I strongly recommond to read that before moving forward.

Demo Application

To implement the MVC, we will create two applications – One will generate an output in ALV and other will generate an output Smartforms. We will put our business logic in the MODEL class. We will create one CONTROL class to establish control between Model and Views.

Our business logic for this example is fairly simple – select the Sales Orders from the VBAK which were created in last ten days. The public method GET_DATA in the class ZCL_MODEL will act as the business logic. Additionally, this class has the public attribute T_VBAK which will be set by the GET_DATA and hold our data from the table.

UML

The UML diagram for any of the application would be like:


Model Class Setup

Model Method Definition


Model Attribute definition


Code Snippet of method GET_DATA
This code would be implemented in the method GET_DATA

 
* Parameters
* Importing IR_ERDAT TYPE TPMY_R_DATE Ranges for date
*
METHOD get_data.
*
* Get data and save into attribute T_VBAK
  SELECT * FROM vbak
         INTO  TABLE t_vbak
         WHERE erdat IN ir_erdat.
*
*
ENDMETHOD.
 

Controller Class Setup

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:


Controller Attributes definition:


Code Snippet for method GET_OBJECT:

 
* Parameters
* Importing IF_NAME TYPE CHAR30 Model class name
*
METHOD get_object .
*
  DATA: lo_object TYPE REF TO OBJECT.
*
* Generic object reference to importing class
  CREATE OBJECT lo_object TYPE (if_name).
  IF sy-subrc = 0.
*   Downcasting to assign generic object to O_MODEL
    o_model ?= lo_object.
  ENDIF.
*
ENDMETHOD.
 

In the next post we will see, how we will use the controller class in our view and access the business logic encapsulated in Model class.

Related Links:


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Spring 4 官方文档学习(十一)Web MVC 框架
Design Patterns in C #
如何隐藏SAP CRM搜索页面的某些搜索条件
ruby系列教材(10):Objects and Attributes
ABAP面向对象之单例模式(Singleton Pattern)
Model View Presenter (MVP) design pattern close look - Part 1 (Supervising Controller) - VusCode - C
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服