OOPS ABAP: Local Interfaces with Example
Interfaces:
- The ABAP statement “INTERFACE" is used to define the interfaces.
- The ABAP statement “INTERFACES" is used to access the interfaces in a class.
- The interfaces do not have their own implementation sections.
- The symbol "~ (tilt)" is used to refer the attributes of the interfaces.
Example:
*&---------------------------------------------------------------------*
*& Report ZVB_INTERFACES
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zvb_interfaces.
PARAMETERS:p_vbeln TYPE vbeln_va.
DATA:it_vbak TYPE ztt_vbak, "table type
is_vbak TYPE zst_vbak. "structure
*Creating interface and method
INTERFACE interface1.
METHODS display IMPORTING pp_vbeln TYPE vbeln_va
EXPORTING pt_vbak TYPE ztt_vbak.
ENDINTERFACE.
*Creating subclass and calling interface
CLASS subclass1 DEFINITION.
PUBLIC SECTION.
INTERFACES interface1.
ENDCLASS.
*Implementing the interface method
CLASS subclass1 IMPLEMENTATION.
METHOD interface1~display.
SELECT vbeln erdat erzet
FROM vbak
INTO TABLE pt_vbak
WHERE vbeln = pp_vbeln.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA:lo_obj TYPE REF TO subclass1.
CREATE OBJECT lo_obj.
*Calling interface method by calling object of subclass
CALL METHOD lo_obj->interface1~display
EXPORTING
pp_vbeln = p_vbeln
IMPORTING
pt_vbak = it_vbak.
IF it_vbak IS NOT INITIAL.
LOOP AT it_vbak INTO is_vbak.
WRITE: / is_vbak-vbeln,
10 is_vbak-erdat,
25 is_vbak-erzet.
ENDLOOP.
ENDIF.
Comments
Post a Comment