SAP Tutorials Blog


SAP ABAP Protected Class

TABLES: pa0002.

PARAMETERS: pernr TYPE pa0002-pernr.

DATABEGIN OF struct,
      pernr TYPE pa0002-pernr,
      vorna TYPE pa0002-vorna,
      nachn TYPE pa0002-nachn,
      END OF struct.

DATA: itab LIKE TABLE OF struct ,
      wa LIKE struct.

*----------------------------------------------------------------------*
*       CLASS class1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 DEFINITION CREATE PROTECTED  .
  PUBLIC SECTION.
    METHODS : method1.
ENDCLASS"c1 DEFINITION

*----------------------------------------------------------------------*
* CLASS c1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 IMPLEMENTATION.
  METHOD method1.
    SELECT * FROM pa0002 INTO CORRESPONDING FIELDS OF TABLE itab WHERE pernr EQ pernr.
    LOOP AT itab INTO wa.
      WRITE: / 'personnel number:', wa-pernr, 'First name:', wa-vorna,'Last name',  wa-nachn.
    ENDLOOP.
  ENDMETHOD"m1

ENDCLASS"c1 IMPLEMENTATION

*----------------------------------------------------------------------*
*       CLASS class2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class2 DEFINITION INHERITING FROM class1.
  PUBLIC SECTION.
    CLASS-METHODS: method2.
ENDCLASS.                    "class2 DEFINITION

*----------------------------------------------------------------------*
*       CLASS class2 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class2 IMPLEMENTATION.
  METHOD method2.
    DATA: object1 TYPE REF TO class1.
    CREATE OBJECT object1.
    CALL METHOD object1->method1.
  ENDMETHOD.                                                "method2
ENDCLASS.                    "class2 IMPLEMENTATION

START-OF-SELECTION.
  CALL METHOD class2=>method2.



Serkan AKKAVAK
Computer Engineer BSc
SAP Department Deputy Manager
Contact : serkurumsal@yandex.com