Import Parameter in Constructor

Import Parameter in Constructor


A constructor can have Import parameter and that parameter will get the value at the time of creating the object. Here we have a program where we have declared a constructor with Import parameter. Then we have implement the method constructor. After that we create the object and export a value to the import parameter.

REPORT  zsr_test.

PARAMETERS p_text TYPE char20.

*----------------------------------------------------------------------*
*       CLASS cl_construct DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_construct DEFINITION.
  PUBLIC SECTION.
    METHODS constructor IMPORTING i_text TYPE char20.
ENDCLASS.                    "cl_construct DEFINITION

*----------------------------------------------------------------------*
*       CLASS cl_construct IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_construct IMPLEMENTATION.
  METHOD constructor.
    WRITE: /3 i_text,
           /3 'Date: ', sy-datum DD/MM/YYYY.
  ENDMETHOD.                    "constructor
ENDCLASS.                    "cl_construct IMPLEMENTATION

START-OF-SELECTION.  DATA obj TYPE REF TO cl_construct.
  CREATE OBJECT obj EXPORTING i_text = p_text.

Below is the output:



Share this

Related Posts