‎2009 Mar 26 12:33 PM
REPORT ysubdel212 LINE-SIZE 120 .
*---------------------------------------------------------------------*
* CLASS testclass DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS testclass DEFINITION.
PUBLIC SECTION.
METHODS : testmethod.
CLASS-DATA num TYPE i.
ENDCLASS. "testclass DEFINITION
*---------------------------------------------------------------------*
* CLASS testclass IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS testclass IMPLEMENTATION.
METHOD : testmethod.
num = num + 5.
write : /5 num.
ENDMETHOD. ":
ENDCLASS. "testclass IMPLEMENTATION
START-OF-SELECTION.
DATA : my_obj TYPE REF TO testclass.
DATA: myobj_tab TYPE TABLE OF REF TO testclass.
DO 5 TIMES.
CREATE OBJECT : my_obj.
APPEND my_obj TO myobj_tab.
ENDDO.
LOOP AT myobj_tab INTO my_obj.
CALL METHOD: my_obj->testmethod.Question.
1)I checked in the debugging and checked the value of my_obj in the do loop.
it generated the following values.
tell me what this numbers mean lke 9,10,11,12,13 .
1)9<\PROGRAM=YSUBDEL212\CLASS=TESTCLASS>
2)10<\PROGRAM=YSUBDEL212\CLASS=TESTCLASS>
3)11<\PROGRAM=YSUBDEL212\CLASS=TESTCLASS>
4)12<\PROGRAM=YSUBDEL212\CLASS=TESTCLASS>
5)13<\PROGRAM=YSUBDEL212\CLASS=TESTCLASS>
2) When we need to use pointer table & exception table?
use of pointer table.
3) we can call a static method with the help of object then why we need to declare as static.
one reason may be without object we can call with help of class, is there any other uses?
call method <obj>-> <method>
or call method <class>=><method>
Edited by: Matt on Mar 26, 2009 1:34 PM
‎2009 Mar 26 12:39 PM
1) The numbers are how SAP keeps track of the objects. If you've two references to the same object, you'll see the same number in both references.
So, if you
CREATE OBJECT r1. -> debug shows r1 referes to e.g. 9<\PROGRAM=YSUBDEL212\CLASS=TESTCLASS>
then
r2 = r1. -> debug shows r2 refers to 9<\PROGRAM=YSUBDEL212\CLASS=TESTCLASS>
2) What do you mean by pointer and exception tables?
3) static/class methods and attributes are discussed widely. It's not a topic confined to ABAP. You use static when it's appropriate to do so...
‎2009 Mar 26 8:28 PM
Hello
You define methods (or attributes) as static if they are intended to be INDEPENDENT of any concrete instance of the class.
>> 3) we can call a static method with the help of object then why we need to declare as static.
>> one reason may be without object we can call with help of class, is there any other uses?
>> call method <obj>-> <method>
>> or call method <class>=><method>
Example: You want to calculate the VAT amount. Input parameters are the amount and the VAT rate, output is the VAT amount. This method CALCULATE_VAT_AMOUNT should be defined as static because it does not need any additional input from any instance.
Regards
Uwe