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
Requires Free Membership to View
When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.
Hannah Smalltree, Editorial DirectorNext 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.
|
||||
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.
This was first published in September 2009