ABAP (Advanced Business Application Programming) is the programming language used in SAP systems. It is mainly used for developing applications in the SAP environment. SAP uses ABAP to customize workflows, reports, and user interfaces. Core ABAP refers to the fundamental aspects of ABAP programming that every SAP developer should know.
Basic Features of Core ABAP
Core ABAP includes various essential concepts that form the base of SAP development. These concepts include data types, control statements, modularization, database access, and debugging techniques. Let’s discuss them in detail.
1. Data dictionary in ABAP
SAP data dictionary is a unified repository for data definitions and metadata in core abap. It’s utilized to design, modify, and manage database objects such as tables, views, and structures.
- Stores technical characteristics such as data type and length
- Stores semantic information like short descriptions
- Controls metadata regarding data objects utilized within SAP applications and ABAP programs
- Acts as a collection of all database objects, structures, domains, tables, and views
2. Reports in ABAP
Reports display data from SAP tables based on user inputs. There are two types:
- Classical Reports: Display simple list-based outputs.
- ALV (ABAP List Viewer) Reports: Provide a structured and interactive display.
Example:
WRITE: 'This is a classical report'.
3. Modularization in ABAP
Modularization makes code reusable and structured. It divides code into different units such as:
- Subroutines (FORM…ENDFORM): Used for defining reusable procedures.
- Function Modules: Used for performing specific tasks with input and output.
- Methods: Used in Object-Oriented ABAP for defining class behavior.
Example of a subroutine:
FORM display_message.
WRITE: 'Hello, ABAP!'.
ENDFORM.
4. Database Access
ABAP interacts with the database using Open SQL statements. Some commonly used statements include:
- SELECT: Retrieves data from a table.
- INSERT: Adds new records to a table.
- MODITY: Modifies existing records or adds new records.
- UPDATE: Modifies existing records.
- DELETE: Removes records from a table.
Example:
SELECT * FROM mara INTO TABLE lt_materials WHERE matnr = '1000'.
5. Internal Tables
Internal tables store temporary data during program execution. There are three main types:
- Standard Tables: Contains unique records with an internal index.
- Sorted Tables: Stores records in sorted order.
- Hashed Tables: Uses a hash algorithm for quick data retrieval.
Example:
DATA: lt_data TYPE TABLE OF mara.
SELECT * FROM mara INTO TABLE lt_data.
6. Debugging in ABAP
Debugging helps in identifying and fixing errors in the code. Some key debugging techniques include:
- Breakpoints: Used to stop execution at a specific point.
- Watchpoints: Used to monitor variable changes.
- Single Step Execution: Used to execute code line by line.
Using a breakpoint:
BREAK-POINT.
7. Control Statements
Control statements help in decision-making and looping operations. Some important control statements are:
- IF…ELSE: Used for conditional execution.
- CASE: Used for multiple conditions.
- LOOP, WHILE, DO: Used for repeating operations.
- EXIT, CONTINUE: Used to control loop execution.
Example:
IF lv_number > 10.
WRITE: 'Number is greater than 10'.
ELSE.
WRITE: 'Number is 10 or less'.
ENDIF.
8. Object-Oriented ABAP (OO-ABAP)
OO-ABAP introduces object-oriented programming concepts in ABAP. It uses:
- Classes and Objects: Defines templates and their instances.
- Inheritance: Allows one class to reuse properties of another.
- Polymorphism: Enables a method to have different implementations.
- Interfaces: Defines common methods without implementation.
Example:
CLASS lcl_example DEFINITION.
PUBLIC SECTION.
METHODS: display.
ENDCLASS.
CLASS lcl_example IMPLEMENTATION.
METHOD display.
WRITE: 'Hello from class'.
ENDMETHOD.
ENDCLASS.
DATA: obj TYPE REF TO lcl_example.
CREATE OBJECT obj.
obj->display().
9. Smart Forms and SAP Scripts
Smart Forms and SAP Scripts help in designing print layouts and forms in SAP.
- Smart Forms: Graphical interface for creating forms without programming.
- SAP Scripts: Older form technology requiring coding.
10. Enhancements and User Exits
SAP provides mechanisms to enhance standard functionalities without modifying the core system. These include:
- User Exits: Custom logic added at predefined SAP points.
- BADI (Business Add-Ins): Object-oriented method for adding enhancements.
- Enhancement Spots: Modern technique for extending functionalities.
11. Exception Handling in ABAP
Errors can be handled using exception handling techniques. ABAP supports:
- TRY…CATCH: Used to catch and handle errors.
- RAISE EXCEPTION: Used to trigger custom errors.
Example:
TRY.
DATA: lv_value TYPE I.
lv_value = lv_value / 0.
CATCH cx_sy_arithmetic_error.
WRITE: 'Division by zero error'.
ENDTRY.
12. Performance Optimization in Core ABAP
Performance tuning ensures efficient execution of ABAP programs. Techniques include:
- Using Proper Indexing: Improves database query speed.
- Avoiding Nested Loops: Reduces processing time.
- Buffering Tables: Reduces database access time.