Ex :-
Steps
- Go to transaction code SE38.
- Enter the program name which start's with Y or Z < program name > and click Create.
Source Code
CLASS C1 DEFINITION.
PUBLIC SECTION.
METHODS : CONSTRUCTOR IMPORTING N1 TYPE I
N2 TYPE I,
ADD EXPORTING RES TYPE I.
CLASS-METHODS : CLASS_CONSTRUCTOR .
PROTECTED SECTION.
PRIVATE SECTION.
DATA : V1 TYPE I,
V2 TYPE I.
ENDCLASS.
CLASS C1 IMPLEMENTATION.
METHOD CONSTRUCTOR.
V1 = N1.
V2 = N2.
ENDMETHOD.
METHOD CLASS_CONSTRUCTOR.
WRITE : / 'AM STATIC CONSTRUCTOR'.
ENDMETHOD.
METHOD ADD.
RES = V1 + V2.
ENDMETHOD.
ENDCLASS.
DATA : OBJ TYPE REF TO C1.
DATA : RES TYPE I.
PARAMETERS : P1 TYPE I,
P2 TYPE I.
START-OF-SELECTION.
CREATE OBJECT OBJ EXPORTING
N1 = P1
N2 = P2.
CALL METHOD OBJ->ADD
IMPORTING
RES = RES.
WRITE : / RES.
No comments:
Post a Comment