Skip to Content
0
Former Member
Aug 27, 2009 at 11:03 AM

Memory Allocation For a Variable Using Normal ABAP and OOPS ABAP

344 Views

Hi,

I have created a basic program using oops...

   CLASS C1 DEFINITION.

  PUBLIC SECTION.
    DATA : W_TEXT(20) TYPE C VALUE 'oops basics'.
    METHODS : DISPLAY.
ENDCLASS.               

CLASS C1 IMPLEMENTATION.
  METHOD: DISPLAY.
    W_TEXT = 'CHANGED VALUE'.
    WRITE : / W_TEXT.
  ENDMETHOD.                    "DISPLAY
ENDCLASS.                    "c1 IMPLEMENTATION

START-OF-SELECTION.
  DATA : O_C1 TYPE REF TO C1.

  CREATE OBJECT O_C1.

  WRITE : / O_C1->W_TEXT.

           call method o_c1->display.

In the above program as you all see iam creating variable W_TEXT in the public section of the class which has visbility all the people..

now later iam creating and object isntance for the class

CREATE OBJECT O_C1.

now after the system processing the statement

CREATE OBJECT O_C1.

when iam check the value of w_text in debugging i cant see the scope of the variable w_text..

but instead if i see O_C1->W_TEXT

i can see the default value which i have given ie : 'OOPS BASICS'.

as per my knowledge the memory allocation will be done when we create a instance of the class.. but when the scope of the varlable W_TEXT is not yet defined after the statment O_C1->W_TEXT.

ie : since i have used WRITE : / O_C1->W_TEXT.

Its writing the value of w_text in the output... but in dubugging the scope for W_TEXT is not defined...

why is it so....... ? when we comapred with normal abap ie : let us say we have defined

DATA : WAR2(9) TYPE C VALUE 'SAMPLE'.

now if we check in the debugging the scope of the WAR2 will be defined..... ie : it will have the default value 'SAMPLE',

But how will it work in OOPS...

Can any one tell this...

Regards

Kumar

Edited by: Matt on Aug 27, 2009 2:27 PM - added tags