Sometimes, we start designing the class in the program itself. Later in the game, we learn that it would be great if we create this class out of the program and make it global. Thus we can make the class more reusable. We might think, why in the world we started with local class.
To ease this type of situation, we have the import utility available in the Class Editor SE24. Let’s start with our local class. We have a local class LCL_REPORT. We want to make it as global class ZCL_MSG_REPORT.
Code snippet of the local class:
PROGRAM ztest_np_temp.
*
CLASS lcl_report DEFINITION.
PUBLIC SECTION.
METHODS: select_data,
write_data.
PRIVATE SECTION.
DATA: t_t100 TYPE STANDARD TABLE OF t100.
ENDCLASS. "lcl_report DEFINITION
START-OF-SELECTION.
DATA: lo_main TYPE REF TO lcl_report.
CREATE OBJECT lo_main.
lo_main->select_data( ).
lo_main->write_data( ).
*
CLASS lcl_report IMPLEMENTATION.
METHOD select_data.
SELECT * FROM t100
INTO TABLE t_t100
UP TO 20 ROWS
WHERE sprsl = sy-langu
AND arbgb = '00'.
ENDMETHOD. "select_Data
METHOD write_data.
FIELD-SYMBOLS: <lfs_t100> LIKE LINE OF t_t100.
LOOP AT me->t_t100 ASSIGNING <lfs_t100>.
WRITE: /(30) <lfs_t100>-arbgb,
(70) <lfs_t100>-text.
ENDLOOP.
ENDMETHOD. "write_data
ENDCLASS. "lcl_report IMPLEMENTATION
Steps to Convert:
- Select Object Type > Import > Local classes in program
- Enter the Program name from which we wish to import the local class. Press Enter
- Select the classes which are required to import and press Import button
- Success message if everything is good
- Methods and Attributes in Class Editor. Activate the class.
Things to Take care after import
- Enter Class Description
- Update Methods and its Signature Description
- Similarly, update all other component description
[…] already created a local class in a program and want to migrate that to Global Class, you can use ABAP Editor Tool Convert Local Classes to Global Classes. Join the forum discussion on this post TAGSABAP Objects OO […]