Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to define a class and how to implement a method -explain with sample

Is constructors concept is there in abap

static constructors?

Tags:
Former Member
Former Member replied

Hi,

See this code.

----


  • CLASS addition DEFINITION

----


*

----


CLASS addition DEFINITION.

PUBLIC SECTION.

METHODS

add IMPORTING num1 TYPE i

num2 TYPE i.

METHODS display.

PRIVATE SECTION.

DATA: total TYPE i.

ENDCLASS. "addition DEFINITION

----


  • CLASS addition IMPLEMENTATION

----


*

----


CLASS addition IMPLEMENTATION.

METHOD add.

total = num1 + num2.

CALL METHOD display.

ENDMETHOD. "add

METHOD display.

WRITE:/ ' The Sum is ', total.

ENDMETHOD. "display

ENDCLASS. "addition IMPLEMENTATION

PARAMETERS: p_num1 TYPE i,

p_num2 TYPE i.

START-OF-SELECTION.

DATA cref TYPE REF TO addition.

CREATE OBJECT cref.

CALL METHOD cref->add

EXPORTING

num1 = p_num1

num2 = p_num2.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question