Home > SAP software/management Tips > SAP ABAP/Java developer tips > More on ABAP Objects instanceOf commands
SAP Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

SAP ABAP/JAVA DEVELOPER TIPS

More on ABAP Objects instanceOf commands


Holger Janz
11.08.2004
Rating: -3.89- (out of 5) Hall of fame tip of the month winner


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


One year ago a user posted the question: Is there an equivalent to Java's instanceOf-operator in ABAP? The answer in the tip ABAP Objects instanceOf command was quite interesting. The example has one problem. It deals with class names! In ABAP it is possible to have global and local classes and it is possible that a global class has the same name as a local class. The scope of the use of the class name decides what class to use. So this example will not work correctly in some cases.

Actually ABAP has the functionality of an instanceOf-operator. The difference is that it is not an operator but a method of the RTTI. Please see the code example below. You can ask an instance of the RTTI directly whether a given instance belongs to the type described by the RTTI instance or not. This method is quite fast and if you use it in a loop you have to take into accou...


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



RELATED CONTENT
SAP ABAP/Java developer tips
How to do additional dialog processing after SAP COMMIT WORK statement
How to find a piece of SAP ABAP code without debugging
How to read an SAP transaction in an ABAP code
How to provide an SAP R/3 4.5B application server with a Web service interface
How to find owners and transports of deleted ABAP programs
Fixing a common OPEN_FORM and START_FORM error in SAPscript
Select Text fields: Case-insensitive
Is this the quickest way to find a BADI?
Easily debug error messages in SAP processes
Accessing private attributes in ABAP Objects

SAP ABAP
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
Using subclasses to develop applications that run on different releases of SAP
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
How can I get an ABAP program displaying Excel data to wrap text?
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


nt that the RTTI instance has only to be derived once. It does not matter how this RTTI instance is derived (e.g. by RTTI methods DESCRIBE_BY_NAME, DESCRIBE_BY_OBJECT_REF or it is a parameter given from some other service). I hope this tip will help to simplify the code. If you have any further question about the RTTI or reflection in ABAP in general, do not hesitate to write me.
Regards,
Holger.Janz@sap.com

Code

program rtti_instanceof.

class c00 definition.
endclass.

data:
class_ref type ref to cl_abap_classdescr,
any_object type ref to object.

create object any_object type c00.

* This works also for cl_abap_intfdescr.
* In this case APPLIES_TO means whether the interface is implemented
* by the instance or it is not.
class_ref ?= cl_abap_typedescr=>describe_by_name( 'C00' ).

if abap_true = class_ref->applies_to( any_object ).
write / 'Object is intance of C00.'.
else.
write / 'Object is not intance of C00.'.
endif.

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.


Submit a Tip




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 - 2009, 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