*&---------------------------------------------------------------------*
*& Report YSAP_INHERITANCE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ysap_inheritance.
TABLES: pa0001, pa0002.
PARAMETERS: pernr TYPE pa0002-pernr.
DATA: BEGIN OF struct,
pernr TYPE pa0002-pernr,
vorna TYPE pa0002-vorna,
nachn TYPE pa0002-nachn,
begda TYPE pa0002-begda,
endda TYPE pa0002-endda,
END OF struct.
DATA: itab LIKE TABLE OF struct,
wa LIKE struct.
DATA: BEGIN OF struct1,
pernr TYPE pa0001-pernr,
bukrs TYPE pa0001-bukrs,
werks TYPE pa0001-werks,
persg TYPE pa0001-persg,
persk TYPE pa0001-persk,
END OF struct1.
DATA: itab1 LIKE TABLE OF struct1,
wa1 LIKE struct1.
*----------------------------------------------------------------------*
* CLASS class1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 DEFINITION.
PUBLIC SECTION.
METHODS: display,
method0002.
ENDCLASS. "class1 DEFINITION
*----------------------------------------------------------------------*
* CLASS class1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 IMPLEMENTATION.
METHOD display.
WRITE: 'this is superclass method' COLOR 6.
ENDMETHOD. "display
METHOD method0002.
SELECT * FROM pa0002 INTO CORRESPONDING FIELDS OF TABLE itab WHERE pernr EQ pernr.
LOOP AT itab INTO wa.
WRITE: / wa-pernr, wa-vorna, wa-nachn, wa-begda, wa-endda.
ENDLOOP.
ENDMETHOD. "method0002
ENDCLASS. "class1 IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS class2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class2 DEFINITION INHERITING FROM class1.
PUBLIC SECTION.
METHODS: display REDEFINITION,
method0001.
ENDCLASS. "class2 DEFINITION
*----------------------------------------------------------------------*
* CLASS class2 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class2 IMPLEMENTATION.
METHOD display.
WRITE: 'this is subclass method' COLOR 3.
ENDMETHOD. "display
METHOD method0001.
SELECT * FROM pa0001 INTO CORRESPONDING FIELDS OF TABLE itab1 WHERE pernr EQ pernr.
LOOP AT itab1 INTO wa1.
WRITE: / wa1-pernr, wa1-bukrs, wa1-werks , wa1-persg , wa1-persk .
ENDLOOP.
ENDMETHOD. "method0001
ENDCLASS. "class2 IMPLEMENTATION
START-OF-SELECTION.
data: object1 type ref to class1.
create object object1.
call method: object1->display,
object1->method0002.
skip .
uline.
skip.
DATA: object2 TYPE REF TO class2.
CREATE OBJECT object2.
CALL METHOD: object2->display,
object2->method0001.
CALL METHOD: object2->method0002.
uline.
*& Report YSAP_INHERITANCE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ysap_inheritance.
TABLES: pa0001, pa0002.
PARAMETERS: pernr TYPE pa0002-pernr.
DATA: BEGIN OF struct,
pernr TYPE pa0002-pernr,
vorna TYPE pa0002-vorna,
nachn TYPE pa0002-nachn,
begda TYPE pa0002-begda,
endda TYPE pa0002-endda,
END OF struct.
DATA: itab LIKE TABLE OF struct,
wa LIKE struct.
DATA: BEGIN OF struct1,
pernr TYPE pa0001-pernr,
bukrs TYPE pa0001-bukrs,
werks TYPE pa0001-werks,
persg TYPE pa0001-persg,
persk TYPE pa0001-persk,
END OF struct1.
DATA: itab1 LIKE TABLE OF struct1,
wa1 LIKE struct1.
*----------------------------------------------------------------------*
* CLASS class1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 DEFINITION.
PUBLIC SECTION.
METHODS: display,
method0002.
ENDCLASS. "class1 DEFINITION
*----------------------------------------------------------------------*
* CLASS class1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 IMPLEMENTATION.
METHOD display.
WRITE: 'this is superclass method' COLOR 6.
ENDMETHOD. "display
METHOD method0002.
SELECT * FROM pa0002 INTO CORRESPONDING FIELDS OF TABLE itab WHERE pernr EQ pernr.
LOOP AT itab INTO wa.
WRITE: / wa-pernr, wa-vorna, wa-nachn, wa-begda, wa-endda.
ENDLOOP.
ENDMETHOD. "method0002
ENDCLASS. "class1 IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS class2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class2 DEFINITION INHERITING FROM class1.
PUBLIC SECTION.
METHODS: display REDEFINITION,
method0001.
ENDCLASS. "class2 DEFINITION
*----------------------------------------------------------------------*
* CLASS class2 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class2 IMPLEMENTATION.
METHOD display.
WRITE: 'this is subclass method' COLOR 3.
ENDMETHOD. "display
METHOD method0001.
SELECT * FROM pa0001 INTO CORRESPONDING FIELDS OF TABLE itab1 WHERE pernr EQ pernr.
LOOP AT itab1 INTO wa1.
WRITE: / wa1-pernr, wa1-bukrs, wa1-werks , wa1-persg , wa1-persk .
ENDLOOP.
ENDMETHOD. "method0001
ENDCLASS. "class2 IMPLEMENTATION
START-OF-SELECTION.
data: object1 type ref to class1.
create object object1.
call method: object1->display,
object1->method0002.
skip .
uline.
skip.
DATA: object2 TYPE REF TO class2.
CREATE OBJECT object2.
CALL METHOD: object2->display,
object2->method0001.
CALL METHOD: object2->method0002.
uline.
No comments:
Post a Comment