Home > SAP software/management Tips > > Using subclasses to develop applications that run on different releases of SAP
SAP Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 


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


Matthew Billingham
09.16.2009
Rating: -4.00- (out of 5)


SAP news, tips and expert advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


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.
ELSE.
 CREATE OBJECT r_ref TYPE zcl_640.
ENDIF.

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 SearchSAP.com'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.

Rate this Tip
To rate tips, you must be a member of SearchSAP.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
SAP ABAP
How to write an SAP ABAP program to read source code and create a new SAP ABAP function module
Using SAP change documents to make change logs visible
SAP talent management FAQ: Fresh answers to frequently asked questions
How to do additional dialog processing after SAP COMMIT WORK statement
SAP TechEd Demo Jam 2009: Winners use beer keg in demo
How to implement SAP BADIs
Tips on SAP ABAP
How to find a piece of SAP ABAP code without debugging
Configuring SAP EDI for sales orders
How to correct an SAP ABAP dump with an oversize condition
SAP ABAP Research

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
ABAP  (SearchSAP.com)
ABAP Objects  (SearchSAP.com)
ABAP Workbench  (SearchSAP.com)
BAPI  (SearchSAP.com)
CATT  (SearchSAP.com)
R/3 Repository  (SearchSAP.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



NetWeaver SAP White Papers
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2010, TechTarget | Read our Privacy Policy
SearchSAP.com is a search service provided by TechTarget and is completely
independent of and not affiliated with SAP AG.
  TechTarget - The IT Media ROI Experts