Simple example to show the Object Oriented Approach for ABAP Programming.
Summation of two numbers in ABAP through OO
Summation of two numbers in ABAP through OO
CLASS add DEFINITION. PUBLIC SECTION. METHODS: do_sum IMPORTING p_num1 TYPE i p_num2 TYPE i EXPORTING p_res TYPE i . ENDCLASS. CLASS add IMPLEMENTATION. METHOD do_sum. p_res = p_num1 + p_num2. ENDMETHOD. ENDCLASS. SELECTION-SCREEN: BEGIN OF BLOCK b1. PARAMETERS: p_num1 TYPE i, p_num2 TYPE i. SELECTION-SCREEN: END OF BLOCK b1. START-OF-SELECTION. DATA: obj_add TYPE REF TO add, res TYPE i VALUE 0 . CREATE OBJECT obj_add. CALL METHOD obj_add->do_sum EXPORTING p_num1 = p_num1 p_num2 = p_num2 IMPORTING p_res = res. WRITE: res.
No comments:
Post a Comment