*&---------------------------------------------------------------------*
*& Report YSAP_OBJECT_REFERENCES
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ysap_object_references.
*----------------------------------------------------------------------*
* CLASS counter DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS counter DEFINITION.
PUBLIC SECTION.
METHODS: set IMPORTING value(set_value) TYPE i,
increment,
get EXPORTING value(get_value) TYPE i..
PRIVATE SECTION.
DATA: count TYPE i.
ENDCLASS. "counter DEFINITION
*----------------------------------------------------------------------*
* CLASS counter IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS counter IMPLEMENTATION.
METHOD set.
count = set_value.
ENDMETHOD. "set
METHOD increment.
ADD 3 TO count.
ENDMETHOD. "increment
METHOD get.
get_value = count.
ENDMETHOD. "get
ENDCLASS. "counter IMPLEMENTATION
DATA: cnt_1 TYPE REF TO counter,
cnt_2 TYPE REF TO counter,
cnt_3 TYPE REF TO counter,
cnt_tab TYPE TABLE OF REF TO counter.
DATA: number TYPE i.
START-OF-SELECTION.
CREATE OBJECT: cnt_1.
APPEND cnt_1 TO cnt_tab.
CREATE OBJECT : cnt_2,
cnt_3.
APPEND : cnt_2 TO cnt_tab,
cnt_3 TO cnt_tab.
CALL METHOD: cnt_1->set EXPORTING set_value = 10,
cnt_2->set EXPORTING set_value = 100,
cnt_3->set EXPORTING set_value = 1000.
DO 5 TIMES.
CALL METHOD: cnt_1->increment,
cnt_2->increment,
cnt_3->increment.
ENDDO.
LOOP AT cnt_tab INTO cnt_1.
CALL METHOD cnt_1->get
IMPORTING
get_value = number.
WRITE: number.
ENDLOOP.
Output:
*& Report YSAP_OBJECT_REFERENCES
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ysap_object_references.
*----------------------------------------------------------------------*
* CLASS counter DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS counter DEFINITION.
PUBLIC SECTION.
METHODS: set IMPORTING value(set_value) TYPE i,
increment,
get EXPORTING value(get_value) TYPE i..
PRIVATE SECTION.
DATA: count TYPE i.
ENDCLASS. "counter DEFINITION
*----------------------------------------------------------------------*
* CLASS counter IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS counter IMPLEMENTATION.
METHOD set.
count = set_value.
ENDMETHOD. "set
METHOD increment.
ADD 3 TO count.
ENDMETHOD. "increment
METHOD get.
get_value = count.
ENDMETHOD. "get
ENDCLASS. "counter IMPLEMENTATION
DATA: cnt_1 TYPE REF TO counter,
cnt_2 TYPE REF TO counter,
cnt_3 TYPE REF TO counter,
cnt_tab TYPE TABLE OF REF TO counter.
DATA: number TYPE i.
START-OF-SELECTION.
CREATE OBJECT: cnt_1.
APPEND cnt_1 TO cnt_tab.
CREATE OBJECT : cnt_2,
cnt_3.
APPEND : cnt_2 TO cnt_tab,
cnt_3 TO cnt_tab.
CALL METHOD: cnt_1->set EXPORTING set_value = 10,
cnt_2->set EXPORTING set_value = 100,
cnt_3->set EXPORTING set_value = 1000.
DO 5 TIMES.
CALL METHOD: cnt_1->increment,
cnt_2->increment,
cnt_3->increment.
ENDDO.
LOOP AT cnt_tab INTO cnt_1.
CALL METHOD cnt_1->get
IMPORTING
get_value = number.
WRITE: number.
ENDLOOP.
Output:
No comments:
Post a Comment