New Keyword in SAP ABAP (7.4+).
* Before ABAP 7.4, we used CREATE OBJECT statement to create an object of the class.
* From ABAP 7.4 onwards, SAP introduced the NEW keyword.
* This NEW keyword is used to create an object of the class.
Report
REPORT zab_rp_new.
PARAMETERS: p_input1 TYPE i,
p_input2 TYPE i.
CLASS a DEFINITION.
PUBLIC SECTION.
METHODS sum IMPORTING pval1 TYPE i
pval2 TYPE i
EXPORTING result TYPE i.
ENDCLASS.
CLASS a IMPLEMENTATION.
METHOD sum.
result = pval1 + pval2.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA: lo_object TYPE REF TO a.
* CREATE OBJECT lo_object. " Old syntax
lo_object = NEW a( ). " New Syntax
lo_object->sum(
EXPORTING
pval1 = p_input1
pval2 = p_input2
IMPORTING
result = DATA(sum)
).
WRITE: 'sum is :',sum.
Input
Output
******************************Thank You***************************
Comments
Post a Comment