Example: Converting a local class in a report to a global class

 

This example demonstrates how to convert a local class in a report to a global class, and calling it from a report.

Click here to see the code for the report which implements the local class.

Creating the class in the Class Builder

Go to the class builder SE24 and create a class called Z_CL_KUNDER.

Go to methods screen and create the two methods below:

Implementing metod KUNDE_ADDNEW

This method nserts a new entry in the transparent table ZKUNDER.

Click on method KUNDE_ADDNEW and insert the follwing code:

method KUNDE_ADDNEW .
    INSERT INTO zkunder VALUES pkunde.
endmethod.
The class uses the import parameter PKUNDE which is a structure with the same type as the transparent table ZKUNDER. 
Click on the paremter button and create the parameter:

 

Implementing method KUNDE_GETTABLE

This method returns an internal table with all entries from transparent table ZKUNDER.

Click on method KUNDE_GETTABLE and insert the follwing code:

method KUNDE_GETTABLE .
     SELECT *
      FROM zkunder
      INTO TABLE kunde_table.
endmethod.
Before you can return a table, you have to define it as a table type in SE11:

After you have created the table type, click on the paremeter button for method KUNDE_GETTABLE and create the table parameter:

Use the class testtool to inster a new entry in table ZKUNDER and to display all entries in ZKUNDER

Using the class in a report

This reports creates a new entry in ZKUNDER, and shows all the entries currently in the table

REPORT  ztest_object                            .


DATA: g_kunde TYPE zkunder,
      gi_kunder TYPE STANDARD TABLE OF zkunder,
      o_kunde TYPE REF TO Z_CL_KUNDER. "Global class



START-OF-SELECTION.
* Create new entry in ZKUNDER
  CLEAR g_kunde.
  g_kunde-zzkunnr = '3'.
  g_kunde-zzkunnavn = 'Baloo export'.

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



END-OF-SELECTION.
* Display all entries in ZKUNDER
        
  CLEAR g_kunde.
  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)