Problem solve Get help with specific problems with your technologies, process and projects.

Write shorter, more readable code using ABAP Objects

Develop a simple class hierarchy to describe functionality found in programs and implement it using template programs.

Most programs seem to borrow or repeat code that exists in other programs. In most cases the repetition is used...

to create nearly the exact same functionality. But, when that functionality has to change, it needs to get changed in perhaps hundreds of programs.

In versions prior to object orientation in ABAP modularization was achieved through using macros, includes, and function modules. Each of which has problems ranging from number-of-lines inefficiency to not being available in the debugger.

Instead, develop a very simple class hierarchy to describe functionality found in most programs and implement it using template programs. This creates smaller, smarter, self-documenting, and maintainable code that is available in the debugger.

Classes also allow you to do things that couldn't always be done
in other modularization techniques.  For example, variables and constants
for standard text or boolean values can not be declared
(or sometimes defined) in the main program body using function modules.
But as properties of a class they can be referenced simply with
INSTANCE->PROPERTY (ie: hrapp->true)without being declared and defined
in the main program body.  Otherwise they would be declared and defined
using DATA...VALUE... and then referenced by variable name.

Sample class heirarchy...

My_company_program_class
(File operations, titles/headers, text and boolean constants)

  HR Mstr Data & Planning

  HR Benefits

  HR Time & Payroll

    HR Application Class
    (This class is primarily an
    interface, inhereting most of 
    its properties and methods from
    the four classes above.  This is
    the class that will be
    implemented.)

Sample simple report template...

REPORT  zgbhtst10  
        LINE-SIZE 80 
        LINE-COUNT 65
        NO STANDARD PAGE HEADING.

DATA: hrapp TYPE REF TO
      zhr_application_class.

INITALIZATION.
  IF hrapp IS INITIAL.
    CREATE OBJECT hrapp.
  ENDIF.

START-OF-SELECTION.
  IF hrapp IS INITIAL.
    CREATE OBJECT hrapp.
  ENDIF.

* insert selection body here
...

END-OF-SELECTION.
* insert output body here
...

  CLEAR hrapp.  
  FREE hrapp.

TOP-OF-PAGE.
  CALL METHOD hrapp->hr_report_title.
This was last published in May 2001

Dig Deeper on SAP ABAP

PRO+

Content

Find more PRO+ content and other member only offers, here.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close