Quantcast
Channel: SCN : All Content - ABAP Development
Viewing all articles
Browse latest Browse all 8332

OBJECT ORIENTED CONCEPT in ABAP

$
0
0

ABAP OBJECT ORIENTED CONCEPTS

 


What is difference between a variable and Object?


Any Memory allocated for a type or Types is called as Variable.

Any Memory Allocated for a type of Types along with Behaviour is called as an Object.


Classes are the concepts used to define Objects.


CLASS is called as Complex data type in SAP used to Define Objects. Object Required a concept called data Hiding Techniques.

CLASSES ARE DATA TYPES Used to Define Exact Object Properties.

ABAP CLASSES CAN BE DEFINED WITH TWO BLOCKS.

 

1. Definition Block

 

CLASS <NAME> DEFINITION.

   PUBLIC SECTION.

                DATA UNDER THIS AREA IS GLOBAL FOR EVERY BODY.

  PROTECTED SECTION.

              DATA UNDER THIS AREA CAN BE ACCESSED BY SAME CLASS MEMBERS OR OTHER RELATED CLASSES.

  PRIVATE SECTION.

       THIS DATA CAN BE ACCESSED BY ONLY CLASS MEMBERS.

ENDCLASS.


Under each Area ABAPer can define attributes using Data Statement.

METHODS is another statement can be used to define a functionality for class objects.

Using this definition Block ABAPer can define Only method definitions.

 

2. Implementation Block.


Is the block used to write Method Body using Following Syntax.

 

CLASS <NAME> IMPLEMENTAION.

       METHOD <NAME>.

                ABAP STATEMENTS.

       ENDMETHD.

ENDCLASS.

 

EXAMPLE CODE.


CLASS ABC DEFINITION.

  PUBLIC SECTION.

     METHODS FIRST.

ENDCLASS.

CLASS ABC IMPLEMENTATION.

  METHOD FIRST.

         WRITE : 'WELCOME TO ABAP WITH OBJECT ORINTED CONCEPTS'.

  ENDMETHOD.

ENDCLASS.

 

Object Decleration IN ABAP


DATA <OBJ> TYPE REF TO <CLASS_NAME>.

Objects in SAP Must be refered to the classes.

DATA : OBJ TYPE REF TO ABC.

 

When ever Object is defined in SAP there is no memory is allocated for Objects.

 

Create Object is the statement used in ABAP to Allocate memory for Objects in SAP.

 

Note: This statement can't be used directly in ABAP editor. This must be used under one Event.


START-OF-SELECTION " is the event executed in reports in between GUI and LPS invocation.

 

If There is no GUI, this evet is executed Before Loading Ouput

 

START-OF-SELECTION.

CREATE OBJECT OBJ.

 

If Object Memory is allocated then ABAPer can access the Methods using "CALL METHOD" statement.

     "->" is the Access Specified for the Methods and Attributes of an Object.

 

CALL METHOD OBJ->FIRST.

 

Existing Classes are created using a tcode called as "SE24" ( Class Builder ).

Classes defined In a program can be accessed by the Same program it Self. Where as the classes defined using SE24 can be accessed by any program , without using any program name.


Navigations to create a class using "SE24".

 

SE24 -> Name the class ( ZCLA2013 ) -> Click on Create -> Opens an interface -> Select the radiobutton as "class" ( default selected ) -> Click on Continue -> Enter Short Description for class ( any ) -> Click on Save -> Save the object under package -> Name the method ( PRINTDATA ) -> set Level as "Instance Method" -> Set the visibility  as Public ( default private ) -> If we need to pass any arguments for method click on "parametes" pushbutton -> set the type as "Importing" -> Set Associated type as "C" -> Come back to Methods -> Click on Pushbutton "Code" -> to Open Implementation coding area ->Generate the code as Follows ->

 

method PRINTDATA .

  write str.

endmethod.


-> save -> come back -> Activate the class

* Example code invoke class FROM SE38.

DATA  OBJ1 TYPE REF TO ZCLA2013.

PARAMETERS S1(20) .

START-OF-SELECTION.

CREATE OBJECT OBJ1.

CALL METHOD OBJ1->PRINTDATA

   EXPORTING

        STR =  s1.

 



Viewing all articles
Browse latest Browse all 8332

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>