11.interfaces in Local Classes in SAP ABAP
11.interfaces in Local Classes in SAP ABAP
Creating a class interface locally and using it in a local class program - SAP
ABAP programming
+ -
The below example explains you using interface concept in SAP ABAP local classes, most of the
times we don`t prefer interfaces in local classes, any how we will learn how to use them in local
calsses.
In the below example we are creating and using interfaces locally, please go through the example
of creating and using interface in global classes , the same we are doing in a local class.
Follow the below steps to create and use interfaces in local classes.
Define an interface
Define an interface and add methods which dosen`t need any implementation.
INTERFACE CL_INTERFACE.
METHODS : GET_MATERIAL_DETAILS
IMPORTING IM_MATNR TYPE MARA-MATNR
EXPORTING EX_MARA TYPE MARA.
METHODS : GET_MATERIAL_DESCRIPTIONS
IMPORTING IM_MATNR TYPE MARA-MATNR
EXPORTING EX_MAKT TYPE MAKT.
ENDINTERFACE.
METHOD CL_INTERFACE~GET_MATERIAL_DETAILS.
SELECT SINGLE * FROM MARA
INTO EX_MARA
WHERE MATNR = IM_MATNR.
ENDMETHOD.
METHOD CL_INTERFACE~GET_MATERIAL_DESCRIPTIONS.
SELECT * FROM MAKT
INTO EX_MAKT WHERE MATNR = IM_MATNR AND SPRAS = 'E'.
ENDSELECT.
ENDMETHOD.
ENDCLASS. "cl_clsss
Creat object and use it in the program
Now the class is created and implemented, we can use the call methods .
DATA LO_CLASS TYPE REF TO CL_CLASS.
DATA : WA_MARA TYPE MARA.
DATA : WA_MAKT TYPE MAKT.
PARAMETERS P_MATNR TYPE MARA-MATNR.
START-OF-SELECTION.
CREATE OBJECT LO_CLASS.
REPORT ZSAPN_LOCAL_CLASS_INTERFACE.
START-OF-SELECTION.
CREATE OBJECT LO_CLASS.
ENDMETHOD.
METHOD CL_INTERFACE~GET_MATERIAL_DESCRIPTIONS.
SELECT * FROM MAKT
INTO EX_MAKT WHERE MATNR = IM_MATNR AND SPRAS = 'E'.
ENDSELECT.
ENDMETHOD.
ENDCLASS. "cl_clsss
Learner Questions