Abap Book 1
Abap Book 1
You want every single point, nothing missed, full clear notes for Unit 1, lesson by lesson
exactly as per the official S4D400 PDF, but neatly arranged in simple English for perfect
understanding and interview revision.
(You can even read it once before your interview and speak confidently.)
📍 1. Introduction
In SAP BTP (Business Technology Platform), ABAP development is cloud-based.
Development is done using Eclipse IDE with ABAP Development Tools (ADT)
plugin.
No traditional SAP GUI development here — modern Eclipse-based only.
Hierarchy:
📍 2. Project Explorer
Project Explorer shows:
o The list of ABAP cloud projects you connected to.
o The structure of the packages and objects inside the ABAP repository.
Objects inside a project:
o Packages
o Classes
o Interfaces
o Database tables
o Other repository objects
Expand the hierarchy in Project Explorer to view objects inside packages.
📍 3. Favorite Packages
Instead of searching every time, you can add frequently used packages to Favorite
Packages.
How to add:
o Right-click on "Favorite Packages" → Add Package
o Select your desired package.
Advantage:
➔ Quick access to your important packages.
📎 Tip: Use partial name search with * (wildcard) if you don't remember the full name.
📍 5. ADT (ABAP Development Tools) Views
Besides Project Explorer, other important views include:
o Console View ➔ Displays program outputs.
o Outline View ➔ Shows structure of current object (methods, attributes, etc.)
o Problems View ➔ Displays syntax errors, warnings, missing activations.
o Properties View ➔ Metadata about the selected object.
📍 8. Example of Navigation:
Suppose you want to edit a class ZCL_EMPLOYEE:
1. Open Project Explorer
2. Expand your project
3. Expand Favorite Packages
4. Double-click on ZCL_EMPLOYEE
5. View details in the editor
6. Check outline for methods inside
Alternatively:
Jump to Definition F3
✅ This covers 100% of Lesson 2 from your official S4D400 material — full clear
understanding for you.
📍 1. Introduction
In ABAP development, software structure helps organize your work in a clear and
scalable way.
Logistics refers to the transport of development objects between systems:
Development → Test → Production.
📍 2. Packages
A Package is a container to group related ABAP development objects (like classes,
tables, programs).
It replaces the old concept of development classes.
Packages allow modularization and better transport organization.
📍 3. Software Components
A Software Component groups packages that belong together logically.
When transporting objects, the software component ensures everything needed moves
together.
Example:
o ZLOCAL ➔ Software component used for local, non-transported developments.
Customer Namespace Z or Y
✅ This covers 100% of Lesson 3 without missing any important SAP point — now you have
perfect clarity.
Here’s a brief summary of Unit 1, Lesson 4: Developing Your First ABAP Program from
the Basic ABAP Programming - S4D400 course:
🧪 Common Mistakes
Key Takeaways
✅ ABAP programs are class-based and follow naming conventions (start with Z/Y).
✅ IF_OO_ADT_CLASSRUN interface is required to execute the class.
✅ out->write( ) is used to print to the Eclipse console.
✅ Syntax rules are strict:
o No space before (
o Spaces inside ()
o Must end with .
✅ Objects must be activated before running.
✅ Console output helps in quick testing without Fiori or GUI setup.
Unit 2, Lesson 1: Understanding the Basics of ABAP
(as per your PDF Basic ABAP Programming - S4D400 📕).
🎯 Lesson Objectives
After completing this lesson, you should be able to:
1990s (Object-
ABAP Objects introduced (object-oriented features). Concepts from C++ and Java
Oriented
like Classes, Inheritance, Polymorphism were adopted.
Extension)
ABAP for SAP Cloud For developments on SAP BTP (SAP Business Technology Platform).
ABAP for Key Users For In-App Extensibility inside SAP S/4HANA (restricted features).
🧠 Important:
This course uses common ABAP features available in all versions, unless specified.
🔵 Comments in ABAP:
Inline Comment WRITE: 'Hello'. " This is a comment Anything after " is ignored
Tip:
📌 Important Notes
ABAP is case-insensitive (but by convention, keywords are in UPPERCASE,
variables in lowercase).
New ABAP uses inline declarations, string templates, and modern operators
wherever possible.
Traditional ABAP syntax is still valid and widely used.
Constant Fixed value that never changes CONSTANTS pi TYPE p VALUE '3.14'.
Example:
Local types (TYPES) Defined within the program TYPES emp_name TYPE string.
Global types (ABAP Created in SE11, reusable across DATA air TYPE
Dictionary) programs /dmo/airport_id.
variable = '19891109'.
7️⃣ Constants
Used for values that must not change during execution.
✳️Syntax:
CONSTANTS: pi TYPE p VALUE '3.14'.
VALUE is mandatory
You can use VALUE IS INITIAL for initial value
🧠 Tip: Use constants instead of hardcoded literals to make code more maintainable.
Risk Example
🔁 Resetting Variables
Use CLEAR to reset variable to initial value:
🆕 Inline Declarations
Declare + assign in the same line using DATA(...).
Cleaner
Safer (auto type detection)
Modern best practice in ABAP
🎯 Lesson Objectives
After this lesson, you will be able to:
Values
Operators
Functions
+ Addition a + b
- Subtraction a - b
* Multiplication a * b
🧠 Notes:
result = 2 + 3.
*result = 2 - 3.
*result = 2 * 3.
*result = 2 / 3.
*result = sqrt( 2 ).
*result = ipow( base = 2 exp = 3 ).
out->write( result ).
➕ Example:
DATA total TYPE p LENGTH 8 DECIMALS 2 VALUE '99.99'.
DATA text TYPE string.
🔹 Date Formatting:
DATA the_date TYPE d VALUE '19891109'.
🔗 String Concatenation
➕ Example:
DATA part1 TYPE string VALUE `Hello`.
DATA part2 TYPE string VALUE `World`.
* With formatting
text = |Date: { the_date DATE = USER }|.
out->write( text ).
* Concatenation
text = `Total:` && ` ` && |{ amount1 + amount2 }|.
out->write( text ).
🎯 Lesson Objectives
By the end of this lesson, you will be able to:
✅ Examples
DATA int_table TYPE TABLE OF i WITH EMPTY KEY. " Integer table
DATA name_table TYPE TABLE OF string WITH EMPTY KEY. " String table
APPEND 2 TO numbers.
APPEND 3 TO numbers.
APPEND 5 TO numbers.
Declare table DATA table TYPE TABLE OF type. Must include WITH EMPTY KEY
Basic structure:
IF condition.
" Code if condition is true
ELSEIF another_condition.
" Code if another_condition is true
ELSE.
" Code if none of the above are true
ENDIF.
Important:
o sy-index is the loop counter (starts at 1).
o Be careful: Infinite loops can happen if EXIT conditions are missing.
CASE Branch CASE var. WHEN val. ... ENDCASE For fixed comparisons
Exit Loop Early DO. IF condition. EXIT. ENDIF. Stop based on condition
Table Loop LOOP AT table INTO wa. ... ENDLOOP. Row-by-row processing
Exception Handling TRY. ... CATCH ... ENDTRY. Catch and handle errors
1. What is Debugging?
Errors happen in programs — crashes, wrong results, or no results.
As a developer, you must analyze the code line-by-line to find the cause.
Debugger is the tool that helps you investigate program behavior.
Source Code View Shows the code and highlights current line
Step Over (F6) F6 Execute next statement but skip into methods
⚠️Important: F5 enters code blocks like out->write(…), so use F6 if you don't want
to deep-dive.
5. Special Breakpoints
Statement Breakpoint: Stop whenever a specific ABAP keyword (e.g., EXIT) is
reached.
Exception Breakpoint: Stop whenever a specific exception is raised.
Conditional Breakpoint: A breakpoint that triggers only if a condition is true (e.g.,
sy-index > 20).
🎯 Lesson Objective:
After this lesson, you will be able to:
Define a local class inside a global class using correct structure and visibility.
In this course, you are defining local classes inside the Local Types tab of a global class.
Used to:
Basic Syntax:
Used to:
Basic Syntax:
4. Visibility Sections
Section Meaning and Use
Static Attribute CLASS-DATA Belongs to the class itself (shared across all objects).
Examples:
6. Methods (Behavior)
Methods declare inside the definition.
Methods implement inside the implementation.
Example Declaration:
METHODS get_connection.
Example Implementation:
METHOD lcl_connection->get_connection.
" Method logic goes here
ENDMETHOD.
✍️In short:
Step What you do
4 Implement methods
🎯 Lesson Objective:
After completing this lesson, you will be able to:
➤ Creating an Instance
The system infers the class type from the left-hand side (here: lcl_connection).
2. Accessing Attributes
➤ Static Attributes
Accessed using:
ClassName=>attribute.
Example:
lcl_connection=>conn_counter.
➤ Instance Attributes
Accessed using:
ref_var->attribute.
Example:
connection->carrier_id = 'LH'.
The arrow -> is used for instance-level access.
3. Multiple Instances
You can create many instances using the same reference variable:
connection = NEW #( ).
connection->carrier_id = 'AA'.
➤ Solution:
Even if the same variable (connection) is reused, each object is preserved in the
table.
✅ You’ll observe the internal table grows with each appended reference.
🧩 Summary Table
Concept Syntax / Behavior
🎯 Lesson Objective:
After this lesson, you will be able to:
1. Method Definition
➤ Syntax:
METHODS method_name.
➤ Optional Parameters:
METHODS set_attributes
IMPORTING
i_carrier_id TYPE /dmo/carrier_id DEFAULT 'LH'
i_connection_id TYPE /dmo/connection_id.
2. Method Implementation
Must implement every method you define.
Done inside the implementation section:
ADT Quickfix Tip: Place cursor on METHODS line with error → press Ctrl + 1 →
select "Add implementation"
3. Calling a Method
Instance method:
ref->method_name( ... ).
Static method:
ClassName=>method_name( ... ).
➤ Rules:
METHOD set_attributes.
me->carrier_id = i_carrier_id.
ENDMETHOD.
Otherwise, you can skip me-> inside methods
5. Raising Exceptions
Use:
METHODS set_attributes
IMPORTING ...
RAISING cx_abap_invalid_value.
TRY.
connection->set_attributes( ... ).
CATCH cx_abap_invalid_value.
out->write( 'Method call failed' ).
ENDTRY.
METHODS get_output
RETURNING VALUE(r_output) TYPE string_table.
DATA(result) = connection->get_output( ).
out->write( connection->get_output( ) ).
METHODS set_attributes
IMPORTING
i_carrier_id TYPE /dmo/carrier_id
i_connection_id TYPE /dmo/connection_id
RAISING
cx_abap_invalid_value.
METHODS get_output
RETURNING VALUE(r_output) TYPE string_table.
ENDCLASS.
METHOD get_output.
APPEND |Carrier: { carrier_id }| TO r_output.
APPEND |Connection: { connection_id }| TO r_output.
ENDMETHOD.
ENDCLASS.
🧩 Summary Table
Concept Syntax Example
🎯 Lesson Objectives:
By the end of this lesson, you’ll be able to:
1. What is Encapsulation?
Encapsulation means restricting direct access to object data.
Instead of letting programs directly change attributes (like carrier_id), they must
use methods (like set_attributes( )).
This ensures:
o ✅ Validation checks happen
o ✅ Only allowed values are set
o ✅ Object state stays consistent and realistic
Allows read access, but no write access from outside the class.
PUBLIC SECTION.
DATA carrier_id TYPE /dmo/carrier_id READ-ONLY.
✅ Option 2: Move to PRIVATE SECTION
PRIVATE SECTION.
DATA carrier_id TYPE /dmo/carrier_id.
🧠 Tip: Use Ctrl + 1 in ADT to change attribute visibility via quick fix.
✅ Solution:
💡 Syntax of Constructor:
METHODS constructor
IMPORTING
i_carrier_id TYPE /dmo/carrier_id
i_connection_id TYPE /dmo/connection_id
RAISING cx_abap_invalid_value.
💡 Implementation:
METHOD constructor.
IF i_carrier_id IS INITIAL OR i_connection_id IS INITIAL.
RAISE EXCEPTION TYPE cx_abap_invalid_value.
ENDIF.
me->carrier_id = i_carrier_id.
me->connection_id = i_connection_id.
conn_counter = conn_counter + 1.
ENDMETHOD.
TRY.
connection = NEW #(
i_carrier_id = 'LH'
i_connection_id = '0400'
).
APPEND connection TO connections.
CATCH cx_abap_invalid_value.
out->write( `Method call failed` ).
ENDTRY.
Syntax:
CLASS-METHODS class_constructor.
🧠 Tip: Generate with ADT quick fix (Ctrl + 1 > "Generate class constructor")
METHODS constructor
IMPORTING
i_carrier_id TYPE /dmo/carrier_id
i_connection_id TYPE /dmo/connection_id
RAISING
cx_abap_invalid_value.
PRIVATE SECTION.
DATA carrier_id TYPE /dmo/carrier_id.
DATA connection_id TYPE /dmo/connection_id.
ENDCLASS.
CLASS lcl_connection IMPLEMENTATION.
METHOD constructor.
IF i_carrier_id IS INITIAL OR i_connection_id IS INITIAL.
RAISE EXCEPTION TYPE cx_abap_invalid_value.
ENDIF.
carrier_id = i_carrier_id.
connection_id = i_connection_id.
conn_counter = conn_counter + 1.
ENDMETHOD.
METHOD get_output.
APPEND |Carrier: { carrier_id }| TO r_output.
APPEND |Connection: { connection_id }| TO r_output.
ENDMETHOD.
ENDCLASS.
✅ Key Takeaways:
Topic Summary
Static Constructor Executes once per class (e.g., initialize static counters)
Unit 4
🎯 Lesson Objective:
After completing this lesson, you will be able to:
✔ Understand how tables are defined in ABAP
✔ Investigate the structure and properties of database tables using ADT
✔ Use tools like Data Preview to inspect actual data
🔹 Client Field
🔹 Cross-client vs Client-specific
Each field refers to a data element, which defines type and labels.
4. Table Metadata in ADT
When viewing a table in ADT:
You’ll see:
o Field list with key markers
o Field types (linked to data elements/domains)
o Labels and short/medium/long text
Example:
🧠 Summary Table
Concept Description
✅ Key Takeaways
Database tables are central to ABAP programs.
Definitions use a standardized, DB-independent structure.
Use ADT tools to inspect both structure and data in tables.
Always check for the key fields and client field in definitions.
🎯 Lesson Objectives
After completing this lesson, you will be able to:
DDL (Data Definition Language) Create or delete database objects (tables, views, indexes)
DCL (Data Control Language) Restrict data access (ABAP uses its own authorization model)
🔵 In ABAP, DML statements (like SELECT) are used in programs.
DDL is done using ADT (not ABAP code directly).
Clause Meaning
4. Examples
➤ Example 1: Single Field
SELECT SINGLE
FROM /dmo/connection
FIELDS airport_from_id
WHERE carrier_id = @carrier_id
AND connection_id = @connection_id
INTO @DATA(airport_from_id).
sy-subrc = 4 (failure).
The target variable remains unchanged (it is not reset).
IF sy-subrc = 0.
" Found something
ELSE.
" No record found
ENDIF.
5. Important Notes
✅ Always filter properly with a WHERE clause (to avoid performance issues).
✅ SELECT SINGLE picks any matching row, not guaranteed to be the "first" by time
or sort order.
✅ Inline declaration using @DATA(...) is recommended.
✅ Always evaluate sy-subrc after reading from DB.
✅ Modern syntax (FIELDS, INTO) is preferred over old ABAP SQL forms.
🧠 Mini Summary Table
Concept Example / Comment
🎯 Lesson Objectives:
After this lesson, you will be able to:
➤ Associations
➤ Annotations
Example:
@EndUserText.label: 'Connection Information'
DEFINE VIEW ENTITY ...
➤ Example:
SELECT SINGLE
FROM /dmo/i_connection
FIELDS
departureairport,
destinationairport,
_Airline\name
WHERE carrier_id = @carrier_id
AND connection_id = @connection_id
INTO (@airport_from_id, @airport_to_id, @airline_name).
Notes:
SELECT from CDS Like selecting from a table, but more powerful
Unit 5
Lesson 1 – Declaring a Structured Data
Object
🎯 Lesson Objective:
✅ Declare structured data objects in ABAP.
2. What is a Structure?
A structure is a data object with:
o A name,
o A structured type (components inside).
Example:
DATA connection_full TYPE /DMO/I_Connection.
Here, connection_full has multiple components (airline ID, connection ID, etc.).
Method How
🎯 Lesson Objectives:
After this lesson, you will be able to:
connection-airport_from_id = 'ABC'.
connection_nested-message-msgty = 'E'.
🔵 Tip:
Press Ctrl + Space after the - to see available fields (code completion).
connection = VALUE #(
airport_from_id = 'ABC'
airport_to_id = 'XYZ'
carrier_name = 'My Airline'
).
connection_nested = VALUE #(
airport_from_id = 'ABC'
airport_to_id = 'XYZ'
message = VALUE #( msgty = 'E' msgid = 'ABC' msgno = '123' )
carrier_name = 'My Airline'
).
🔵 If you write VALUE #( ) (empty), it fills the structure with initial values (like CLEAR does).
connection_nested = connection.
SELECT SINGLE
FROM /dmo/i_connection
FIELDS departureairport, destinationairport, _airline-name
WHERE carrier_id = @carrier_id
AND connection_id = @connection_id
INTO CORRESPONDING FIELDS OF @details.
Unit 6
Lesson 1 – Declaring a Complex Internal
Table
🎯 Lesson Objective:
✅ Declare complex internal tables in ABAP.
Simple Internal Table Row type = a single scalar value (like I, STRING)
Example:
Key Access Read rows by matching field values (can be slower if table large)
Standard Table No sorted order, default for simple cases. Sequential search for keys.
Example:
🎯 Lesson Objectives:
After this lesson, you will be able to:
🔵 Tip: You can skip the work area and APPEND directly:
connections = VALUE #(
( carrier_id = 'AA' connection_id = '1001' )
( carrier_id = 'BA' connection_id = '1002' )
( carrier_id = 'LH' connection_id = '0400' )
).
Example:
TRY.
connection = connections[ airport_from_id = 'SFO' ].
CATCH cx_sy_itab_line_not_found.
" Handle not found
ENDTRY.
SELECT
FROM /DMO/I_Airport
FIELDS AirportID, Name
WHERE City = 'London'
INTO TABLE @airports.
🎯 Lesson Objectives:
After this lesson, you will be able to:
3. Behavior Implementation
Behavior Implementation = ABAP classes that contain real coding for:
o Validations
o Determinations
o Actions
Two implementation types:
o Unmanaged: You must code Create, Update, Delete yourself.
o Managed: RAP runtime handles Create, Update, Delete.
➤ Example Structure:
6. About Validations
Validations are triggered:
o Always on create.
o On update if specific fields change (example: only if Name changes).
Defined in behavior definition and implemented as methods in ABAP.
7. Using the Business Object
RAP Business Objects are used in:
o Fiori Elements Apps
o Web APIs
o ABAP code (via EML – Entity Manipulation Language).
🔵 EML allows you to READ, CREATE, UPDATE, DELETE business object instances.
🎯 Lesson Objectives:
After this lesson, you will be able to:
1. What is EML?
EML = Entity Manipulation Language.
EML provides special ABAP commands to manipulate Business Object (BO) data:
o Read
o Create
o Update
o Delete.
2. EML Commands
Operation EML Statement
➤ Example:
DATA lt_read_import TYPE TABLE FOR READ IMPORT /dmo/r_agencytp.
DATA lt_read_result TYPE TABLE FOR READ RESULT /dmo/r_agencytp.
Notes:
4. Commit Changes:
COMMIT ENTITIES.
⚡ Important:
If you use EML outside of the BO behavior implementation, you must call COMMIT
ENTITIES manually.
Inside BO behavior ➔ commit is automatic.
Unit 8
Lesson 1 – Introducing the ABAP RESTful
Application Programming Model (RAP)
🎯 Lesson Objective:
After this lesson, you will be able to:
✅ Describe the process to develop an OData Service with RAP.
1. What is RAP?
RAP = ABAP RESTful Application Programming Model.
RAP helps you:
o Build modern applications (like Fiori apps).
o Build services (like OData) easily and quickly in ABAP.
It follows REST principles (stateless communication between client and server).
Step Description
2. Define a CDS View Entity Exposes table fields and defines business object structure.
6. Define & Bind Service Expose the service using OData (for Fiori/UI).
Code push-down Most logic in CDS and database layer for better performance.
Managed scenario You code only validations/actions; SAP runtime handles standard logic.
Draft handling Users can save drafts before submitting final versions.
Consistent APIs Easy to build REST APIs without writing protocol-specific code.
4. Important RAP Concepts
Term Meaning
Business Object (BO) Entity with data + behavior (like flight, agency).
➤ Purpose:
price : abap.dec(15,2);
➤ Columns Example:
🧩 Admin and concurrency fields (created_by, last_changed_at) are mandatory for RAP
generators.
🔵 Better to create custom data elements for clarity (e.g., Z##_CITY_FROM, Z##_CITY_TO).
➤ Objects Generated:
Object Purpose
🔵 Initially, only basic field checks (like number format) happen; no validations yet.
🧩 Quick Summary Table
Step Description