- Syntax,
Class <Class name > Definition.
Public Section.
-----
--------
Protected Section.
-----
--------
Private Section.
EndClass.
- Class implementation syntax.
Class <Class name > Implementation.
Method <method name>.
---------
----------
EndMethod.
Method <method name>.
---------
----------
EndMethod.
Method <method name>.
---------
----------
EndMethod.
EndClass
Ex:
To create Local Class.
- Go to transaction code SE38.
- Create the class.
CLASS C1 DEFINITION .
PUBLIC SECTION.
DATA : V1 TYPE I VALUE 10.
CLASS-DATA : V4 TYPE I VALUE 40.
PROTECTED SECTION.
DATA : V2 TYPE I VALUE 20.
CLASS-DATA : V5 TYPE I VALUE 50.
PRIVATE SECTION.
DATA : V3 TYPE I VALUE 30.
CLASS-DATA : V6 TYPE I VALUE 60.
ENDCLASS.
PUBLIC SECTION.
DATA : V1 TYPE I VALUE 10.
CLASS-DATA : V4 TYPE I VALUE 40.
PROTECTED SECTION.
DATA : V2 TYPE I VALUE 20.
CLASS-DATA : V5 TYPE I VALUE 50.
PRIVATE SECTION.
DATA : V3 TYPE I VALUE 30.
CLASS-DATA : V6 TYPE I VALUE 60.
ENDCLASS.
- N1 is known as Instance public.
- N2 is known as Static public.
- N3 is known as instance protected.
- N4 is known as static protected.
- N5 is known as instance private.
- N6 is known as static private.
- Source Code
PUBLIC SECTION.
DATA : V1 TYPE I VALUE 10.
CLASS-DATA : V4 TYPE I VALUE 40.
PROTECTED SECTION.
DATA : V2 TYPE I VALUE 20.
CLASS-DATA : V5 TYPE I VALUE 50.
PRIVATE SECTION.
DATA : V3 TYPE I VALUE 30.
CLASS-DATA : V6 TYPE I VALUE 60.
ENDCLASS.
DATA : OBJ TYPE REF TO C1.
START-OF-SELECTION.
CREATE OBJECT OBJ.
WRITE : / OBJ->V1.
WRITE : / OBJ->V4.
- Save -> Check -> Activate.
No comments:
Post a Comment