Visibility sections example(Abstraction) in ABAP Objects

Go down

Visibility sections example(Abstraction) in ABAP Objects

Post  Admin on Sun Apr 08, 2012 9:40 pm

*&---------------------------------------------------------------------*
*& Report Z_05
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZKRISH_OOPS_05.

*----------------------------------------------------------------------*
* CLASS c1 DEFINITION
*----------------------------------------------------------------------*
CLASS C1 DEFINITION.
PUBLIC SECTION.
DATA: X TYPE I,
Y TYPE I.
METHODS: M1 IMPORTING A TYPE I EXPORTING B TYPE I.
METHODS: M2.
METHODS: M3 IMPORTING X TYPE I Y TYPE I.
PRIVATE SECTION.
DATA: P TYPE I,
Q TYPE I.
ENDCLASS. "c1 DEFINITION
*----------------------------------------------------------------------*
* CLASS c1 IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS C1 IMPLEMENTATION.
METHOD: M1.
B = A * A.
ENDMETHOD. "M1

METHOD: M2.
WRITE: / X, Y.
WRITE: / P, Q.
ULINE.
ENDMETHOD. "M2

METHOD: M3.
P = X.
Q = Y.
ENDMETHOD. "M3

ENDCLASS. "c1 IMPLEMENTATION


START-OF-SELECTION.
DATA: O1 TYPE REF TO C1.
CREATE OBJECT O1.
DATA: O2 TYPE REF TO C1.
CREATE OBJECT O2.
DATA: O3 TYPE REF TO C1.
CREATE OBJECT O3.

DATA: RESULT TYPE I.
CREATE OBJECT O1.

CALL METHOD O1->M1
EXPORTING
A = 4
IMPORTING
B = RESULT.
WRITE: RESULT.

O2->X = 2. O2->Y = 4.
CALL METHOD O2->M2.

* NOT ALLOWED, SINCE P AND Q ARE PRIVATE
* O3->P = 3.
* O3->Q = 6..

DATA: A1 TYPE I VALUE 3.

DATA: B1 TYPE I VALUE 6.
CALL METHOD O3->M3
EXPORTING X = A1 Y = B1.

CALL METHOD O3->M2.

Admin
Admin

Posts : 92
Join date : 2012-01-26

http://mysaplab.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum