SAP ABAP Accessing Private Attribute of a Class
TABLES: pa0002.
PARAMETERS: pernr TYPE pa0002-pernr.
DATA: BEGIN OF struct,
pernr TYPE pa0002-pernr,
vorna TYPE pa0002-vorna,
nachn TYPE pa0002-nachn,
END OF struct.
DATA: itab LIKE TABLE OF struct ,
wa LIKE struct.
CLASS class2 DEFINITION DEFERRED.
*----------------------------------------------------------------------*
* CLASS class1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 DEFINITION CREATE PRIVATE FRIENDS class2.
public SECTION.
METHODS : method1.
ENDCLASS. "c1 DEFINITION
*----------------------------------------------------------------------*
* CLASS c1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 IMPLEMENTATION.
METHOD method1.
SELECT * FROM pa0002 INTO CORRESPONDING FIELDS OF TABLE itab WHERE pernr EQ pernr.
LOOP AT itab INTO wa.
WRITE: / 'personnel number:', wa-pernr, 'First name:', wa-vorna,'Last name', wa-nachn.
ENDLOOP.
ENDMETHOD. "m1
ENDCLASS. "c1 IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS class2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class2 DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: method2.
ENDCLASS. "class2 DEFINITION
*----------------------------------------------------------------------*
* CLASS class2 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class2 IMPLEMENTATION.
METHOD method2.
DATA: object1 TYPE REF TO class1.
CREATE OBJECT object1.
CALL METHOD object1->method1.
ENDMETHOD. "method2
ENDCLASS. "class2 IMPLEMENTATION
START-OF-SELECTION.
CALL METHOD : class2=>method2.
PARAMETERS: pernr TYPE pa0002-pernr.
DATA: BEGIN OF struct,
pernr TYPE pa0002-pernr,
vorna TYPE pa0002-vorna,
nachn TYPE pa0002-nachn,
END OF struct.
DATA: itab LIKE TABLE OF struct ,
wa LIKE struct.
CLASS class2 DEFINITION DEFERRED.
*----------------------------------------------------------------------*
* CLASS class1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 DEFINITION CREATE PRIVATE FRIENDS class2.
public SECTION.
METHODS : method1.
ENDCLASS. "c1 DEFINITION
*----------------------------------------------------------------------*
* CLASS c1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 IMPLEMENTATION.
METHOD method1.
SELECT * FROM pa0002 INTO CORRESPONDING FIELDS OF TABLE itab WHERE pernr EQ pernr.
LOOP AT itab INTO wa.
WRITE: / 'personnel number:', wa-pernr, 'First name:', wa-vorna,'Last name', wa-nachn.
ENDLOOP.
ENDMETHOD. "m1
ENDCLASS. "c1 IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS class2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class2 DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: method2.
ENDCLASS. "class2 DEFINITION
*----------------------------------------------------------------------*
* CLASS class2 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class2 IMPLEMENTATION.
METHOD method2.
DATA: object1 TYPE REF TO class1.
CREATE OBJECT object1.
CALL METHOD object1->method1.
ENDMETHOD. "method2
ENDCLASS. "class2 IMPLEMENTATION
START-OF-SELECTION.
CALL METHOD : class2=>method2.
Serkan AKKAVAK
Computer Engineer BSc
SAP Department Deputy Manager
Contact : serkurumsal@yandex.com
0 Comments