Understanding Instance and Static Components


Steps

  • Go to transaction code SE24.
  • Initial screen of Class Builder looks like this.
  •  Enter the Object Type (class name ) , start's with YCL_ or ZCL_ <class name > and click on create button.
  • Enter the short description and click on SAVE button.
  • Save it in either Package or Local Package.
  • Class Interface looks like this.
  • Click on attributes Tab,
  • Enter the attribute name.
  • Click on Level and press F4 help.


  • Select the Level  ( instance ) of the attribute.
  • Click on Visibility and press F4 help.
  • Select the Visibility of the attribute.
  • Enter the Associated type( data type ).
  • Enter the Description.
  • Enter the initial Value ( optional ) .
  • Note : N1 is known as Instance Public attribute .
  • To Add static public attribute follow following steps.
  • Enter attribute name.
  • Click on Level and press F4 help.

  • Select static attribute.
  • Click on Visibility and press F4 help.

  • Select the visibility.

 

  •  Enter the Associated Type .




  •  Enter the description.

  • Enter the initial value.
  • Similarly create different attributes as shown below as per Level and Visibility.
  • Note :
  1. N3 is known as instance protected.
  2. N4 is known as static protected.
  3. N5 is known as instance private.
  4. N6 is known as static private.
  • Save -> Check -> Activate.

Understanding Instance and Static Components

  • Go to transaction code SE38.
  • Enter the program name start's with Y or Z<program name > and click on create button.
  • Enter the Title , select attribute type as executable program and click on Save .

  • To declare the object.
                     DATA : <object name > Type  <Class name >.
  • Ex : obj type ZCL_FIRST_CLASS.
  • To create  the object.
                 CREATE OBJECT < object name> .
  • Ex : Create object OBJ.
  • We can call instance attributes using ,
            <object name >-><attribute name>.
  • We can call static attribute using,
                  <object name >-><attribute name>.
                          
                               or
                  <Class name >=><attribute name>.

  • Call attributes default value's.




  • Save -> Check->Activate.
  • Execute.

  • Change the values of instance and static public attributes .
  • Save ->Check->Attributes.
  • Execute.
  • Now call another object attributes.
  • Save -> Check -> Activate.
Note : Whenever static attribute's changes it's value , then  static attribute' s changes it's initial value.

Source Code.


DATA OBJ TYPE REF TO ZCL_FIRST_CLASS,
       OBJ2 TYPE REF TO ZCL_FIRST_CLASS.

START-OF-SELECTION.

CREATE OBJECTOBJ OBJ2.

"Call attributes default values

WRITE ' N1 INSTANCE PUBLIC ATTRIBUTE : ' OBJ->N1.
WRITE ' N2 INSTANCE PUBLIC ATTRIBUTE : ' OBJ->N2.

ULINE.

" CHANGE THE VALUES OF  INSTANCE AND STATIC PUBLIC ATTRIBUTE VALUE

OBJ->N1 76.
OBJ->N2 34.

WRITE ' N1 INSTANCE PUBLIC ATTRIBUTE : ' OBJ->N1.
WRITE ' N2 INSTANCE PUBLIC ATTRIBUTE : ' OBJ->N2.

" Now call the object 2.
uline .

WRITE ' N1 INSTANCE PUBLIC ATTRIBUTE : ' OBJ2->N1.
WRITE ' N2 INSTANCE PUBLIC ATTRIBUTE : ' OBJ2->N2.

ULINE.

Comments

Popular posts from this blog

FOR ALL ENTRIES (FAE) -4 TABLES USING ALV_GRID_DISPLAY

RADIO-BUTTONS IN BASIC REPORT