HANA Eclipse Class

 Introduction:   

  • We will cover the following basic concepts:
  1. How to create a Class in HANA Studio ( HANA Eclipse ).
  2. Basic components of the Class in the HANA Studio.
  3. How to create a simple program in the HANA Studio.
  4. Old VS New ABAP Syntaxes to call the Method of the Created Class.
 Lets Start:

1. Let us Create an Eclipse Class.

  • Login to HANA Eclipse Studio and open the ABAP Perspective.
  • File->New->Other..


  • Select 'ABAP Class'.


  • We can see the CLASS DEFINITION Section and CLASS IMPLEMENTATION Section generated as shown below.
    • We are going to Define a method in the Public Section of Class Definition.
    • And implement the Method in the Class implementation section as well.

      

2. Let us learn the Generated Default Components of the class.
  • Line 1: CLASS CLASS_NAME DEFINITION:
    • Here we define the components of the class. 
    • For Example Attributes, Methods Etc.
  • Line 2: PUBLIC:
    • This means the Class is a Global Class.
  • Line 3:FINAL:
    • This means the Class components cannot be inherited by a sub-class.
    • In fact, there can be no sub-classes that can be derived from the final class.
  • Line 4:CREATE PUBLIC:
    • This defines the visibility of the class as an object.
    • This means the class can be instantiated even outside the Class, in Other Classes, Sub-Classes & SE38 program using CREATE OBJECT. We will discuss more on this topic later.
  • Line 5:PUBLIC SECTION:
    • This defines the visibility of the components of the class.
    • This means the class components like Attributes and Methods defined in this section are visible outside the Class, in Sub-Classes, in a SE38 Program. We will discuss more on this topic later.
  • Line 6:METHODS: METHOD_NAME
    • Here we have defined a method in the PUBLIC SECTION.
  • PROTECTED SECTION:
    • This means the class components like Attributes and Methods defined in this section are visible only to their Classes and in its Sub-Classes.
  • PRIVATE SECTION:
    • This means the class components like Attributes and Methods defined in this section are visible only to their Class.
  • Line 14:CLASS CLASS_NAME IMPLEMENTATION:
    • In this section, we implement all the required methods and utilize the Attributes inside the methods or externally in a Program based on visibility.
  • Line 15:METHOD METHOD_NAME.
    • Method Implementation.


3. Create a Program as shown below.
  • File->New->Other->ABAP Program.






4. We have created the program using Old syntax and New syntax as shown below.
    • Old Syntax:
      • Create a Reference Variable of the Class.
      • Create an Object of the Class using the Reference Variable.
      • Call the Instance Method of the Class.
    • New Syntax:
      • Single line to create both references Variable and Object of the Class.
      • We use Inline Declaration i.e. DATA(LR_CLASS_REF_NEW)  =  NEW ZCLASS_ECLIPSE.
      • Here, on the left-hand side of the assignment operator ( = ), we have an inline declaration.
      • And on the right-hand side of the assignment operator  ( = ), we have the class of interest and that will influence the REF TYPE of the LR_CLASS_REF_NEW variable.
      • NEW: is an INSTANCE OPERATOR that will influence the creation of a NEW object of the CLASS ( ZCLASS_ECLIPSE) of interest.
      • Inline Declaration happens at the time of program compilation, which results in Reference Parameter creation and Object is created once we execute the line i.e. DATA(LR_CLASS_REF_NEW)  =  NEW ZCLASS_ECLIPSE.
      • Call the Instance Method of the Class.
  • Execute the Program. Run->Run As->ABAP Application( Console ).

  • Output in ABAP Console as shown below.

  • Example Code:
*Old Syntax
DATA lr_class_ref_old TYPE REF TO zclass_eclipse.

CREATE OBJECT lr_class_ref_old.

CALL METHOD lr_class_ref_old->method( ).


WRITE:/.

*New Syntax

DATA(lr_class_ref_new) = NEW zclass_eclipse( ).

lr_class_ref_new->method(  ).

Comments

Popular posts from this blog

Class Visibility

Special Method: Constructor

Class Inheritance