0% found this document useful (0 votes)
18 views5 pages

SAP Advance ABAPCONCEPTS-1

The document provides an overview of ABAP Object-Oriented Programming concepts, including core concepts like classes, objects, inheritance, and polymorphism. It details types of classes, method types, visibility levels, and the use of interfaces and events. Additionally, it includes examples demonstrating class creation, constructors, attributes, inheritance, interfaces, events, and static methods.

Uploaded by

karthikrammku
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views5 pages

SAP Advance ABAPCONCEPTS-1

The document provides an overview of ABAP Object-Oriented Programming concepts, including core concepts like classes, objects, inheritance, and polymorphism. It details types of classes, method types, visibility levels, and the use of interfaces and events. Additionally, it includes examples demonstrating class creation, constructors, attributes, inheritance, interfaces, events, and static methods.

Uploaded by

karthikrammku
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

ABAP OOPs (Object-Oriented Programming System)

1. Core OOP Concepts


Concept Description
Class Blueprint containing methods, attributes, events, and interfaces.
Object Runtime instance of a class.
Inheritance Create subclasses from a parent class for code reuse.
Polymorphism One interface, many implementations (via method redefinition).
Encapsulation Grouping data and behavior. Promotes data hiding.
***********ABAP does not support multiple inheritance directly, but interfaces can simulate it.*********
2. Types of Classes
Type 1. Description
Global Class Created via SE24, reusable across programs.
Local Class Defined inside reports (SE38), scope limited to that report.
Subtypes of Global Classes:
✓ Usual Class – Reusable logic
✓ Exception Class – Error handling (CX_...)
✓ Persistence Class – DB layer (Insert/Update/Delete)
✓ Test Class – Unit testing framework
3. Method Types
Method Type Description Syntax
Instance Needs an object METHODS ...
Static Called without object CLASS-METHODS ...
4. Visibility Levels
Type Accessible From
Public Everywhere
Protected Class and subclasses only
Private Only inside the class
5. Method Parameters
Parameter Description
Importing Input
Exporting Output
Changing Input + Output
Returning Function-like return (only one allowed)
6. Object Declaration & Creation
Syntax: DATA: lo_obj TYPE REF TO zcl_test.
CREATE OBJECT lo_obj.
7. Static vs Instance Declarations
Component Instance Static
Attribute DATA CLASS-DATA
Method METHODS CLASS-METHODS
✅ Instance methods can access both static and instance components.
❌ Static methods can access only static ones.
8. Final Class
Syntax: CLASS zcl_final DEFINITION FINAL.
🚫 Cannot be inherited.
9. Abstract Class
✓ Cannot be instantiated directly.
✓ May contain abstract (unimplemented) methods.
✓ Subclasses must implement all abstract methods.
10. Interface
✓ All methods are public abstract.
✓ No implementation allowed.
✓ Used to simulate multiple inheritance.
11. Abstract Class vs Interface
Feature Abstract Class Interface
Methods Abstract + Concrete Only Abstract
Visibility Public/Private/Protected Public Only
Inheritance Single Multiple Supported
Redefine Button Required Not Required
12. Events in OOPs
✓ Used for class communication.
✓ Trigger Method – Raises event
✓ Handler Method – Responds to it
✓ Syntax: SET HANDLER lo_handler->on_event FOR lo_trigger.
13. Constructors
Type Description
CONSTRUCTOR Instance constructor (runs on object creation). Accepts parameters.
CLASS_CONSTRUCTOR Static constructor (runs once per program load). No parameters.
14. ME Keyword
✓ Used inside methods to reference attributes when local variables have the same name.
✓ me->attribute_name
15. Exception Classes
✓ Always start with CX_
✓ Base Class: CX_ROOT
Type Notes
CX_STATIC_CHECK Must be declared in TRY-CATCH
CX_DYNAMIC_CHECK Optional declaration
TRY.
RAISE EXCEPTION TYPE cx_demo.
CATCH cx_demo INTO lo_ex.
ENDTRY.
16. Persistence Class
✓ Used for DB persistence logic.
✓ Class starts with CL_
✓ Helper classes:
• CA_... (Agent)
• CB_... (Base)
17. Method Overriding vs Overloading
Feature Overriding (ABAP ✅) Overloading (ABAP ❌)
Location Subclass Same class
Signature Same Different
18. ALV using OOPs
Using CL_GUI_ALV_GRID
➢ Steps:
➢ Create field catalog (LVC_FIELDCATALOG_MERGE or manually)
➢ Design a custom container in the screen
➢ Create CL_GUI_CUSTOM_CONTAINER object
➢ Create CL_GUI_ALV_GRID object and link to container
➢ Use SET_TABLE_FOR_FIRST_DISPLAY
Features:
➢ Sorting, filtering
➢ Double-click, events
➢ Editable

Using CL_SALV_TABLE
CALL METHOD cl_salv_table=>factory
IMPORTING r_salv_table = lo_alv
CHANGING t_table = it_data.
lo_alv->display( ).
Pros Cons
Easy to use ❌ Not editable directly
Fewer setup steps Less control
___________________________________________________________________________________________________

Examples:
Example 1: Class & Object
CLASS zcl_demo DEFINITION.
PUBLIC SECTION.
METHODS: display.
ENDCLASS.

CLASS zcl_demo IMPLEMENTATION.


METHOD display.
WRITE: / 'Hello from OOPs!'.
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
DATA(obj) = NEW zcl_demo( ).
obj->display( ).
___________________________________________________________________________________________________

Example 2: Constructor
CLASS zcl_const_demo DEFINITION.
PUBLIC SECTION.
METHODS: constructor.
ENDCLASS.

CLASS zcl_const_demo IMPLEMENTATION.


METHOD constructor.
WRITE: / 'Object created - constructor triggered'.
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
DATA(obj) = NEW zcl_const_demo( ).
___________________________________________________________________________________________________

Example 3: Attributes
CLASS zcl_person DEFINITION.
PUBLIC SECTION.
DATA: name TYPE string,
age TYPE i.
METHODS: show_data.
ENDCLASS.

CLASS zcl_person IMPLEMENTATION.


METHOD show_data.
WRITE: / 'Name:', name, 'Age:', age.
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
DATA(p1) = NEW zcl_person( ).
p1->name = 'John'.
p1->age = 30.
p1->show_data( ).
___________________________________________________________________________________________________
Example 4: Inheritance
CLASS parent DEFINITION.
PUBLIC SECTION.
METHODS: speak.
ENDCLASS.

CLASS parent IMPLEMENTATION.


METHOD speak.
WRITE: / 'I am parent'.
ENDMETHOD.
ENDCLASS.

CLASS child DEFINITION INHERITING FROM parent.


PUBLIC SECTION.
METHODS: speak REDEFINITION.
ENDCLASS.

CLASS child IMPLEMENTATION.


METHOD speak.
WRITE: / 'I am child'.
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
DATA(obj) = NEW child( ).
obj->speak( ).
___________________________________________________________________________________________________
Example 5: Interface
INTERFACE lif_demo.
METHODS: show.
ENDINTERFACE.

CLASS zcl_interface_demo DEFINITION.


PUBLIC SECTION.
INTERFACES: lif_demo.
ENDCLASS.

CLASS zcl_interface_demo IMPLEMENTATION.


METHOD lif_demo~show.
WRITE: / 'Interface method called'.
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
DATA(obj) = NEW zcl_interface_demo( ).
obj->lif_demo~show( ).
___________________________________________________________________________________________________
Example 6: Events
CLASS event_class DEFINITION.
PUBLIC SECTION.
EVENTS: evt_done.
METHODS: trigger_event.
ENDCLASS.

CLASS event_class IMPLEMENTATION.


METHOD trigger_event.
RAISE EVENT evt_done.
ENDMETHOD.
ENDCLASS.

CLASS listener DEFINITION.


PUBLIC SECTION.
METHODS: on_done FOR EVENT evt_done OF event_class.
ENDCLASS.

CLASS listener IMPLEMENTATION.


METHOD on_done.
WRITE: / 'Event triggered!'.
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
DATA(ev) = NEW event_class( ).
DATA(li) = NEW listener( ).
SET HANDLER li->on_done FOR ev.
ev->trigger_event( ).
___________________________________________________________________________________________________
Example 7: Static Method & Attribute
CLASS zcl_static_demo DEFINITION.
PUBLIC SECTION.
CLASS-DATA: count TYPE i VALUE 0.
CLASS-METHODS: increment.
ENDCLASS.

CLASS zcl_static_demo IMPLEMENTATION.


METHOD increment.
count = count + 1.
WRITE: / 'Count =', count.
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
zcl_static_demo=>increment( ).
zcl_static_demo=>increment( ).
___________________________________________________________________________________________________

*********************** THE END ************************

You might also like