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 DEFINITION.
      PUBLIC SECTION.

        METHODS sum IMPORTING pval1  TYPE i
                              pval2  TYPE i
                    EXPORTING result TYPE i.
    ENDCLASS.

    CLASS IMPLEMENTATION.
      METHOD sum.
        result pval1 + pval2.
      ENDMETHOD.
    ENDCLASS.

    START-OF-SELECTION.
      DATAlo_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

Popular posts from this blog

Pf status and user command in factory method - OOPS ALV in ABAP

fetch the data from table and send an email in ABAP

Enhancements in abap