0% found this document useful (0 votes)
7 views6 pages

Modified OOPS

Object-Oriented Programming (OOP) in SAP ABAP enables developers to create modular and maintainable code using classes, objects, and methods, following principles like encapsulation, inheritance, and polymorphism. Key concepts include classes, objects, attributes, and methods, with distinctions between local and global classes, as well as instance and static methods. Additionally, AMDP allows for database-specific procedures to enhance performance by executing complex operations directly within the database layer.

Uploaded by

ksilla071
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)
7 views6 pages

Modified OOPS

Object-Oriented Programming (OOP) in SAP ABAP enables developers to create modular and maintainable code using classes, objects, and methods, following principles like encapsulation, inheritance, and polymorphism. Key concepts include classes, objects, attributes, and methods, with distinctions between local and global classes, as well as instance and static methods. Additionally, AMDP allows for database-specific procedures to enhance performance by executing complex operations directly within the database layer.

Uploaded by

ksilla071
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/ 6

Object-Oriented Programming (OOP) in SAP ABAP

Object-Oriented Programming (OOP) in SAP ABAP allows developers to create


modular, reusable, and maintainable code using classes, objects, and methods. OOP in ABAP
is based on principles like encapsulation, inheritance, and polymorphism, similar to other
programming languages like Java or C++.

Key Concepts in OOP for SAP ABAP


1. Class: A blueprint for creating objects, containing attributes (data) and methods
(behavior).
2. Object: An instance of a class that holds data and executes methods.
3. Encapsulation: Hides data within a class and exposes it through methods.
4. Inheritance: Enables creating new classes based on existing ones for code reuse.
5. Polymorphism: Allows writing methods that behave differently depending on the
object.
6. Abstraction: Shows only relevant data while hiding unnecessary details about an
object.

Types of Classes
• Local Class: Defined inside an ABAP program and accessible only within the same
program.
• Global Class: Implemented using T-code SE24 and accessible across all programs in
the system.

Attributes in a Class
Attributes are variables that hold information about an object. They define the data
or properties of an object created from a class.
Types of Attributes

1. Instance Attributes:
Specific to each object of the class.
Declared using DATA.
2. Static Attributes:
Shared by all objects of the class.
Declared using CLASS-DATA.
Types of Methods in SAP ABAP Classes
Methods in a class define behavior or actions that objects or the class itself can
perform. In SAP ABAP, methods are categorized into two main types:
1. Instance Methods:
o Tied to a specific object of the class.
o Require an object instance to be called.
o Can access instance attributes.
Example:
CLASS lcl_car DEFINITION.
PUBLIC SECTION.
DATA: brand TYPE string. "Instance attribute
METHODS: display_brand. "Instance method
ENDCLASS.

CLASS lcl_car IMPLEMENTATION.


METHOD display_brand.
WRITE: / 'Brand:', brand. "Access instance attribute
ENDMETHOD.
ENDCLASS.

"Using instance method


DATA: lo_car TYPE REF TO lcl_car.
CREATE OBJECT lo_car.

lo_car->brand = 'Toyota'. "Set attribute


lo_car->display_brand( ). "Call instance method
2. Static Methods:
o Tied to the class itself, not to any specific object.
o Can only access static attributes.
o Called using the class name.

Smartforms in SAP ABAP


Smartforms are tools for creating and formatting documents in SAP.

Steps to Create Smartforms

1. Enter Transaction Code:


Use T-code SMARTFORMS to start creating a Smartform.
2. Create a New Smartform:
Define the Smartform structure.
3. Declare Internal Table in Form Interface:
Provide the internal table to supply data to the form.
4. Declare Work Area in Global Definitions:
Used to hold rows of data from the internal table.
5. Create Secondary Page:
Used for repeating data from the internal table.
6. Design the Layout:
o Header Section:

▪ Create a header in the Main Window for column titles.


▪ Use the Text node to specify field names like Material Number (MATNR).

o Main Area:

▪ Loop through the internal table data and display it.


▪ Assign the Work Area (WA_DATA) fields to display values in the text nodes.

Example:

- Header: Material Number

- Work Area: WA_DATA-MATNR

7. Activate and Save the Smartform:


Activate the form and save changes.
8. Call the Smartform in ABAP Code:
Use the function module SSF_FUNCTION_MODULE_NAME to dynamically retrieve
and execute the generated function module.

Work Area in Global Definitions


In Smartforms, a work area is used to hold individual rows of data from the internal
table. The work area acts as a temporary storage unit to process and display the data in the
form's layout. Declaring it in Global Definitions makes it available throughout the Smartform.

Q. Why Declare a Work Area?


Global definitions ensure the work area is accessible across different nodes of the
form.

Steps to Use SSF_FUNCTION_MODULE_NAME


1. Call SSF_FUNCTION_MODULE_NAME: Get the generated function module name.
2. Execute the Retrieved FM: Output the Smartform.
Q. Use of SSF_FUNCTION_MODULE_NAME in Smartforms
In SAP Smartforms, after activating the Smartform, the system automatically
generates a Function Module (FM) to handle the execution of the form. Since the
name of the generated FM is system-defined and may vary with each transport or
modification, the function module SSF_FUNCTION_MODULE_NAME is used to
dynamically retrieve the name of this generated FM at runtime.

Q. What is AMDP in SAP ABAP?


AMDP (ABAP Managed Database Procedures) is a feature in SAP that allows
developers to create and execute database-specific procedures (e.g., SQLScript)
directly within ABAP classes. It leverages the capabilities of SAP HANA to perform
complex calculations and operations at the database layer, rather than processing
large amounts of data in the ABAP application server.

Q. Why is AMDP Used?


Performance Optimization: Moves intensive data processing tasks to the database
layer, reducing the load on the application layer.

Q. How is AMDP Used?


1. Class Declaration
o AMDP methods are implemented in ABAP classes using the
IF_AMDP_MARKER_HDB interface. This interface marks the class as
containing AMDP procedures.
2. Method Definition
o The AMDP logic is written inside static methods, which are executed at the
database level using SQLScript (HANA's procedural SQL language).
3. Execution
o The AMDP method is called from an ABAP program like any other class
method.
Steps to Create and Use AMDP

Step 1: Define the ABAP Class


• Declare the class and implement the interface IF_AMDP_MARKER_HDB to enable
AMDP capabilities.
Step 2: Implement the Method
• Write the SQLScript logic in the class implementation. Use BY DATABASE PROCEDURE
to define it as an AMDP method.
Explanation:
• FOR HDB: Indicates the procedure is for SAP HANA.
• LANGUAGE SQLSCRIPT: Specifies SQLScript as the language for the
procedure.
• :i_sales_org: Binds the input parameter to the SQL query.
Step 3: Call the AMDP in ABAP Program
• Use the class and method to call the AMDP from an ABAP program.

Key Features of AMDP


1. Interface-Based Implementation:
o Requires the IF_AMDP_MARKER_HDB interface.
o Makes the class HANA-compatible.
2. SQLScript Language:
o Allows complex database-level logic using HANA SQLScript.
3. Static Methods:
o AMDP methods must be static.
4. Database-Specific Execution:
o AMDP methods are executed directly in the database layer.
5. Read-Only or Modification Support:
o Supports both read-only queries and data-modification operations (e.g.,
INSERT, UPDATE).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy