Skip to content

Instantly share code, notes, and snippets.

@furlan
Created September 24, 2016 17:54
Show Gist options
  • Select an option

  • Save furlan/fdf5e19e63c2587744ca1647acf60cc6 to your computer and use it in GitHub Desktop.

Select an option

Save furlan/fdf5e19e63c2587744ca1647acf60cc6 to your computer and use it in GitHub Desktop.
Modelo Rico em ABAP
REPORT z_rich_model.
CLASS order_item DEFINITION DEFERRED.
TYPES: order_item_table TYPE TABLE OF REF TO order_item WITH NON-UNIQUE DEFAULT KEY.
CLASS order_item DEFINITION.
PUBLIC SECTION.
METHODS get_price RETURNING VALUE(item_price) TYPE i.
METHODS set_price IMPORTING item_price TYPE i.
METHODS get_quantity RETURNING VALUE(item_quantity) TYPE i.
METHODS set_quantity IMPORTING item_quantity TYPE i.
METHODS get_total RETURNING VALUE(item_total) TYPE i.
PRIVATE SECTION.
DATA price TYPE i.
DATA quantity TYPE i.
ENDCLASS.
CLASS order_item IMPLEMENTATION.
METHOD get_price.
item_price = me->price.
ENDMETHOD.
METHOD set_price.
me->price = item_price.
ENDMETHOD.
METHOD get_quantity.
item_quantity = me->quantity.
ENDMETHOD.
METHOD set_quantity.
me->quantity = item_quantity.
ENDMETHOD.
METHOD get_total.
item_total = me->price * me->quantity.
ENDMETHOD.
ENDCLASS.
CLASS order DEFINITION.
PUBLIC SECTION.
METHODS get_total RETURNING VALUE(order_total) TYPE i.
METHODS add_item IMPORTING order_item TYPE REF TO order_item.
PRIVATE SECTION.
DATA items TYPE order_item_table.
ENDCLASS.
CLASS order IMPLEMENTATION.
METHOD add_item.
APPEND order_item TO me->items.
ENDMETHOD.
METHOD get_total.
DATA item TYPE REF TO order_item.
LOOP AT me->items INTO item.
order_total = item->get_total( ).
ENDLOOP.
ENDMETHOD.
ENDCLASS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment