Interface Data are Valued by DATA VALUES
Interface attributes can be initiated with values at the time of Interface declaration in any class definition. If we give values like class attributes then compile error will come as follows:
Below is the program where we have initiated the Interface attribute values at the time of declaration by statement DATA VALUES. Now it successfully runs and produces the output.
Below is the program where we have initiated the Interface attribute values at the time of declaration by statement DATA VALUES. Now it successfully runs and produces the output.
*&---------------------------------------------------------------------*
*& Report ZSR_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zsr_test.
*----------------------------------------------------------------------*
* INTERFACE it
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
INTERFACE it.
DATA: v_txt1 TYPE char40,
v_txt2 TYPE char40.
METHODS mit.
ENDINTERFACE. "it
*----------------------------------------------------------------------*
* CLASS cls DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls DEFINITION.
PUBLIC SECTION.
INTERFACES it DATA VALUES
v_txt1 = 'SAP ABAP'
v_txt2 = 'Object Oriented'.
ENDCLASS. "cls DEFINITION
*----------------------------------------------------------------------*
* CLASS cls IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls IMPLEMENTATION.
METHOD it~mit.
WRITE: / it~v_txt1,
/ it~v_txt2.
ENDMETHOD. "it~mit
ENDCLASS. "cls IMPLEMENTATION
START-OF-SELECTION.
DATA obj TYPE REF TO cls.
CREATE OBJECT obj.
CALL METHOD obj->it~mit.
The output is following:
Post a Comment