Use inheritance to extend local classes
If you use ABAP Objects and writing local classes, you can extend their functionality with inheritance and global classes.
If you are using ABAP Objects and writing local classes in your programs you can extend their functionality by...
Continue Reading This Article
Enjoy this article as well as all of our content, including E-Guides, news, tips and more.
using inheritance and global classes. This provides benefits in two ways: 1) re-use of tested and implemented code, and 2) not having to instantiate multiple objects. For example, rather than writing methods in your class to do local file operations using FM WS_DOWLOAD or others like it have the local class inherit from global class CL_GUI_FRONTEND_SERVICES. Now your local class has all the functionality needed to do file upload and download, and more. And, you only have to instantiate one object. How: the INHERETING FROM addition to the local class definition can point to either a global class in the repository or to another local class previously defined in your program. I know for sure this works in 4.6x. OO was introduced in pieces starting in 4.0 with new stuff added with every release all the way up to 4.6c. So, I can also say for sure that it won't work prior to version 4.0x.
PROGRAM Z_CLASS_INHERIT_DEMO * Class LOCAL_APPLICATION definition CLASS local_application DEFINITION INHERITING FROM cl_gui_frontend_services. PUBLIC SECTION. METHODS: constructor IMPORTING i_file TYPE text200, ... PRIVATE SECTION. DATA: output_file TYPE string. ... ENDCLASS. ... * Global data delcarations DATA: lcl TYPE REF TO local_application. PARAMETERS: p_file TYPE text200. ... START-OF-SELECTION. CREATE OBJECT lcl TYPE local_application EXPORTING i_file = p_file. ... END-OF-SELECTION. * Call the download method * inherited from global class * cl_gui_frontend_services CALL METHOD lcl->gui_download EXPORTING filename = output_file * FILETYPE = 'ASC' CHANGING data_tab = itab EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 OTHERS = 22.