SAP Tech Pro

SAP Technical Blog
Topprice Price Comparison

OO ABAP - Instance Constructors can have Import Parameters

OO ABAP - Instance Constructors can have Import Parameters

Instance constructors can have import parameters. Values to them are passed at the time of CREATE OBJECT statement to create object from the class containing the constructor.

Note: Constructors cannot have any export parameters.

The program contains a class C1 which has one instance constructor with one import parameter. The constructor gets fired at the time of CREATE OBJECT statement.


CLASS c1 DEFINITION.
  PUBLIC SECTION.
    METHODS : constructor IMPORTING today TYPE d.
ENDCLASS.

CLASS c1 IMPLEMENTATION.
  METHOD constructor.
    WRITE:/5 'Today is : ' , today DD/MM/YYYY.
  ENDMETHOD.
ENDCLASS.
*************** main program **************
START-OF-SELECTION.
  DATA: obj1 TYPE REF TO c1.
  CREATE OBJECT: obj1 EXPORTING today = sy-datum.

Output->

image

Add comment

Before Buying, Compare Prices at Topprice.in

Topprice.in