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

Using subclasses to develop applications that run on different releases of SAP

App development pro Matthew Billingham rewrites a program using object-oriented programming to create subclasses for developing applications that run on any release of SAP Basis.

During a recent project, I encountered the following problem: I'd written an end-user report, and naturally, I was using CL_SALV_TABLE. But I then discovered my program was needed in a Basis 6.20 system.

But CL_SALV_TABLE doesn't exist in 6.20! Oops!

So now the question became, how could I rewrite the program so that in Basis 6.40 it would use the newer ABAP classes while using the older ABAP classes in 6.20?

Here's the solution I came up with, using the power of OOP (object-oriented programming). I created an abstract superclass ZCL_SUPER, which has a static method – FACTORY -- and a public abstract instance method, DISPLAY.

Next I created two subclasses of ZCL_SUPER. One subclass, ZCL_620, implemented DISPLAY using CL_GUI_ALV_GRID. The other subclass, ZCL_640, implemented DISPLAY using CL_SALV_TABLE.

ZCL_SUPER=>FACTORY has a returning parameter, r_ref TYPE REF TO zcl_super.

IF sy-saprl EQ '620'.
 CREATE OBJECT r_ref TYPE zcl_620.
 CREATE OBJECT r_ref TYPE zcl_640.

My calling program is: DATA: r_output TYPE REF TO zcl_super. " Get data into the internal table it_mydata r_output = zcl_super=>factory( ). r_output->display( it_mydata ).

Due to inheritance, the display method for the correct class will automatically be called. The calling program doesn't have to be concerned about which release of SAP Basis it is on.

Ah, I hear you say, when you import this code into the 6.20 system, ZCL_640 will have syntax errors. This is true.

More on SAP application development
Read Matthew's tip on how to find a piece of ABAP code without going through debugging hell

Read Matthew's answers to reader questions related to SAP application development.

However, subclasses are loosely coupled to the superclass ( the subclass knows who its superclass is, but the superclass doesn't know, or care, who its subclasses are), so it doesn't matter! The program will still work – ZCL_620 and ZCL_SUPER won't have any errors and will run perfectly well.

Now, convincing Quality and Basis that an RC8 on a transport import isn't always an issue – that's the hard part!

About the creator of this tip: Matthew Billingham is's application development expert. He has worked for companies such as Eurotunnel and Vodafone, served as development manager for Coats PLc, and as head of application development with Novartis Pharma in Switzerland, managing the development side of a global SAP rollout.

Matthew now runs his own SAP consultancy, providing guidance and designing solutions (particularly for intractable problems) for third parties. His expertise is in program design, troubleshooting and knowing just how SAP works; his clients describe him as "Consultant for everything." He is co-founder of SecureBI, delivering innovative software solutions in the SAP security space.

Dig Deeper on SAP ABAP

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.