Example: Using Parameters in Class

 

This example demonstrates how to use paremeters when calling methods in class, including returnings a table.

The example updates a custom table ZKUNDER, and retrieves a list of entries in the table.

 

REPORT  ztest_object                            .

*---------------------------------------------------------------------*
*       CLASS kunder DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS clskunder DEFINITION.
  PUBLIC SECTION.

    TYPES: t_kunder TYPE STANDARD TABLE OF zkunder.

    METHODS:

    kunde_addnew IMPORTING value(pkunde) TYPE zkunder,

    kunde_gettable EXPORTING value(kunde_table) TYPE t_kunder.


ENDCLASS.                    "kunder DEFINITION


*---------------------------------------------------------------------*
*       CLASS kunder IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS clskunder IMPLEMENTATION.

  METHOD kunde_addnew.
    INSERT INTO zkunder VALUES pkunde.

  ENDMETHOD.                    "kunde_addnew

  METHOD kunde_gettable.

    SELECT *
      FROM zkunder
      INTO TABLE kunde_table.


  ENDMETHOD.                    "kunde_liste




ENDCLASS.                    "kunder IMPLEMENTATION

DATA: g_kunde TYPE zkunder,
      gi_kunder TYPE STANDARD TABLE OF zkunder,
      o_kunde TYPE REF TO clskunder.



START-OF-SELECTION.
  CLEAR g_kunde.
  g_kunde-zzkunnr = '1'.
  g_kunde-zzkunnavn = 'Sørens griseexport'.

* Create entry in table ZKUNDER

  CREATE OBJECT o_kunde.
  CALL METHOD o_kunde->kunde_addnew
    EXPORTING
      pkunde = g_kunde.

  CLEAR g_kunde.

END-OF-SELECTION.
* Read transparent table into internal table and display
  
CALL METHOD o_kunde->kunde_gettable
    IMPORTING
      kunde_table = gi_kunder.

  LOOP AT gi_kunder INTO g_kunde.
    WRITE: / g_kunde-zzkunnr, g_kunde-zzkunnavn.


  ENDLOOP.
Converted from CHM to HTML with chm2web Standard 2.7 (unicode)