METHOD GET_MATERIAL.
DATA: G_MATNR TYPE MARA-MATNR.
SELECT SINGLE MATNR FROM MARA
INTO G_MATNR
WHERE MATNR = P_MATNR.
IF SY-SUBRC = 0.
SELECT MATNR
ERNAM
MATKL FROM MARA
INTO TABLE IT_MARA
WHERE MATNR = P_MATNR.
ELSE.
RAISE MATERIAL_NOTFOUND.
ENDIF.
ENDMETHOD.
REPORT ZO_CLASS4.
PARAMETERS: P_MATNR TYPE MARA-MATNR.
TYPES: BEGIN OF T_MARA,
MATNR LIKE MARA-MATNR,
ERNAM LIKE MARA-ERNAM,
MATKL LIKE MARA-MATKL,
END OF T_MARA.
DATA: IT_MARA TYPE STANDARD TABLE OF T_MARA,
WA_MARA LIKE LINE OF IT_MARA.
START-OF-SELECTION.
DATA: OREF TYPE REF TO ZO_CLASS5.
CREATE OBJECT OREF.
CALL METHOD OREF->GET_MATERIAL
EXPORTING
P_MATNR = P_MATNR
IMPORTING
IT_MARA = IT_MARA
EXCEPTIONS
MATERIAL_NOTFOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID 'ZACLASS' TYPE 'I' NUMBER '000'
WITH P_MATNR.
ELSE.
LOOP AT IT_MARA INTO WA_MARA.
WRITE:/ WA_MARA-MATNR, WA_MARA-ERNAM, WA_MARA-MATKL.
ENDLOOP.
ENDIF.
PARAMETERS: P_MATNR TYPE MARA-MATNR.
TYPES: BEGIN OF T_MARA,
MATNR LIKE MARA-MATNR,
ERNAM LIKE MARA-ERNAM,
MATKL LIKE MARA-MATKL,
END OF T_MARA.
DATA: IT_MARA TYPE STANDARD TABLE OF T_MARA,
WA_MARA LIKE LINE OF IT_MARA.
START-OF-SELECTION.
DATA: OREF TYPE REF TO ZO_CLASS5.
CREATE OBJECT OREF.
CALL METHOD OREF->GET_MATERIAL
EXPORTING
P_MATNR = P_MATNR
IMPORTING
IT_MARA = IT_MARA
EXCEPTIONS
MATERIAL_NOTFOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID 'ZACLASS' TYPE 'I' NUMBER '000'
WITH P_MATNR.
ELSE.
LOOP AT IT_MARA INTO WA_MARA.
WRITE:/ WA_MARA-MATNR, WA_MARA-ERNAM, WA_MARA-MATKL.
ENDLOOP.
ENDIF.