SAP ABAP Basics and Programming Guide
SAP ABAP Basics and Programming Guide
1 Basic Of ABAP
1 What is SAP ABAP? 6
2 Where is ABAP Used? 6
3 What is a Transport Request in SAP? 7
4 What is system landscape 8
5 Create transport request 9
6 What is package? 12
7 Types and package creation? 13
8 What is ABAP Editor? 16
9 Create first program 18
10 What is comment in ABAP 23
11 What are system variables in ABAP? 26
12 How to use system variable in program? 27
13 What is a Data Type? 28
14 What is a Data Object in SAP ABAP? 30
15 ABAP Operators example codes 34
2 ABAP DICTIONARY 38
1 Create first database table 39
2 Record data in table 49
3 Display data 50
4 Change data 51
5 Table Maintenance Generator(TMG) 52
a) One step 52
b) Two step 55
6 Structure 58
a) Include Structure 58
b) Append Structure 67
7 Create second table 70
8 Maintain foreign key relation 72
9 Maintain record in second table using SM30 75
10 Views 76
a) Creation of Base view 77
b) Creation of Projection view 84
c) Creation of Maintenance view 87
d) Creation of Help view 95
11 Search Help 98
a) Creating Elementary Search Help 98
2
b) Collective search help 104
12 Lock Objects 107
3
8 Modify 159
9 Delete 161
10 Delete Adjacent Duplicates From 165
11 Clear, Refresh, Free 167
9 Joins 170
1 Creating a program using inner join 170
2 Creating a program using outer join 172
16 Debugging 319
17 Reports 333
1 Classical report 334
2 Interactive reports 340
3 ALV Reports 351
4
18 Data Migration 375
1 LSMW 377
2 BDC 416
3 BAPI ((Business Application Programming Interface) 453
19 Enhancement 464
1 Customer Exit 464
2 Enhancement framework 495
3 BADI (Business Add-ins) 512
20 Smartform 526
21 OOPs 547
Upcoming Topics
22 Workflow
23 IDoc
24 New Syntax
25 CDS
26 AMDP
27 Odata
5
1. What is SAP ABAP?
ABAP (Advanced Business Application Programming) is the primary programming language used
to develop applications on the SAP platform. It is a high-level, 4th-generation language (4GL)
developed by SAP SE and is primarily used for building custom reports, interfaces, enhancements,
forms, and workflows in SAP ERP systems like ECC and S/4HANA.
Feature Description
Purpose Used to develop SAP applications within the SAP ecosystem.
Type Procedural and object-oriented language.
Platform Runs on SAP NetWeaver (application server).
Integration Deeply integrated with SAP modules (FICO, MM, SD, etc.).
Environment Developed in SE80 (Object Navigator) and SE38 transaction codes.
Custom Reports – To meet specific business requirements (via ALV, classical reports).
Enhancements/User Exits/BADIs – Modify standard SAP behavior without modifying core code.
Forms – Print documents like invoices using SAPscript, SmartForms, Adobe Forms.
Data Migration – Load legacy data using programs like BDC or LSMW.
OData & Fiori – Used in S/4HANA for backend logic behind Fiori apps.
6
3. What is a Transport Request in SAP?
A Transport Request (TR) in SAP is a container that holds changes made to repository objects
(like programs, tables, function modules) or customizing settings. It is part of the Change and
Transport System (CTS) used to move developments or configurations from one SAP system to
another,
Typically:
• Move custom ABAP code from the development system to testing and production.
• Ensure version control and traceability of changes.
• Maintain system consistency across SAP landscapes.
• Facilitate collaborative development with multiple developers working on the same
system.
DEV (Development)
Transport Request
QAS (Quality/Testing)
PRD (Production)
All changes must pass through this flow using Transport Requests.
7
4. What is System Landscape?
System Landscape refers to the arrangement of SAP servers (systems) in an organization that
supports the entire development, testing, and production process of SAP applications.
It defines how different SAP systems are structured and connected to ensure smooth software
development, transport, and maintenance.
Typical SAP System Landscape
A standard SAP landscape consists of three systems:
8
5. Create transport request
Tcode: SE01
[Link] Create
9
Select workbench request and click on copy.
10
11
6. Create Package (SE21)
A Package (previously called a Development Class) is a logical container used to group related
development objects such as programs, classes, function modules, tables, screens, etc.
Packages help organize ABAP objects, manage transport, and define dependencies and access
control for modular development.
Purpose Description
Access Control Packages define interfaces and visibility of objects to other packages.
When you create any development object (e.g., program, table), SAP prompts you to assign it to
a package.
• If you choose a local package ($TMP), the object is not transportable (for
temporary/testing objects only).
• For reusable or deployable code, assign it to a custom package (usually starting with Z or
Y).
12
7. Types of Packages
Type Description
Development
Standard type. Holds development objects and allows transport.
Package
Structure Package Contains only other packages (no objects) to structure the hierarchy.
Test Package Contains test objects like unit tests, test data, etc.
13
Continue.
Enter.
14
Save it.
15
8. What is the ABAP Editor?
The ABAP Editor is the integrated development environment (IDE) inside SAP where developers
write, edit, test, and debug ABAP code.
It is the central tool for ABAP development and allows you to create everything from simple
reports to complex business logic, modular functions, forms, and interfaces.
• Write and edit ABAP programs, classes, function modules, and more
• Check syntax and activate programs
• Run and test code directly
• Perform debugging and analyze program flow
• Manage modularization units like FORM, FUNCTION, and METHOD
SE38 /
Classic ABAP Editor Traditional GUI-based editor in SAP GUI
SE80
Modern ABAP in Eclipse Eclipse-based tool for HANA, S/4HANA, and RAP
—
(ADT) development
➢ Transaction Codes:
16
Key Features:
Benefits:
Action Description
Write Code Type ABAP statements like SELECT, WRITE, LOOP, FORM, etc.
Pretty Printer Format your code for better readability (Shift + F1)
17
9. Create first program
Use Tcode: SE38
Give program name and select create.
18
Enter title and select type – executable program.
19
Give package name and press enter.
Save it.
20
Input
21
Syntax: Write: / pos (width) ‘text1’ left/right/centered justified color <Color number>.
Explanation of each component:
• Write -The WRITE statement in ABAP is used to display data or output on the screen. It's
mainly used in reports, test programs, or to check intermediate results during
development.
Think of it like ABAP’s version of print in Python or [Link] in Java.
• : - chain operator: It is a statement which is used to display multiple texts which are
separated by using a single WRITE statement.
• / – This indicates the start of the new line.
• pos (width) – Defines the position and width of the text box or area where the text will
be displayed.
• 'text1' – The actual text to display (should be enclosed in single quotes).
• left/right/centered – Specifies how the text should be aligned within the defined width.
• justified – Optional keyword if the text should be fully justified (i.e., aligned both left and
right).
• color <Color number> – Sets the text color using a numeric code.
22
10. What is a Comment in ABAP?
A comment in ABAP is a line or part of a line that is ignored during program execution.
Comments are used to:
Comments do not affect the logic or output of your program — they are purely for
documentation and readability.
The * character at the start of a program line indicates that the entire line is a comment.
The “ character, which can be entered at any position in the line, indicates that the remaining
content in the line a comment.
Examples:
23
Write your first program.
Source code:
*&---------------------------------------------------------------------*
*& Report ZDEMO5
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZDEMO5.
24
Output.
25
11. What are System Variables in SAP ABAP?
System Variables (technically called System Fields) are predefined internal variables provided by
the SAP system. These hold runtime information about the current program, user session,
screen data, database access, and more.
They all belong to the structure SYST (or its alias SY) and are automatically available in any ABAP
program - no need for declaration.
26
12. How to use system variable in program?
27
13. What is a Data Type?
A data type defines the type of data a variable can store, such as numbers, characters, dates,
strings, or structures. It ensures that the program uses memory efficiently and performs
accurate operations.
28
2.1. Structure type
A structure is a group of related data objects. For example, you can have a structure address that
contains house_no, street, city, state, zip_code and country.
A structure is an instance of a structure type. To define a structure type, you use the type
statement. For example, the following defines a structure type called address_type.
Example:
The reference types describe reference variables that refer to instances of classes, interfaces,
and runtime data objects.
29
14. What is a Data Object in SAP ABAP?
You use data objects to store, read, and manipulate values during the execution of an ABAP
program.
Example Analogy:
Concept Real World Example
30
Types of Data Objects in ABAP
Examples
31
Why Data Objects Matter
• They are the actual containers that hold your program data
• You manipulate them through ABAP statements (e.g., MOVE, WRITE, LOOP, etc.)
• Without data objects, a program has no memory to work with
32
Named data object-Variable
• Variables are data objects whose contents can be changed.
• Variable are declared using the DATA, CLASS-DATA, STATICS, PARAMETERS, SELECT-
OPTIONS, and RANGES statements.
• Example –DATA: lv_empid(20) TYPE n.
lv_empid = 10.
lv_empid = 20.
33
15. SAP ABAP Operators
In SAP ABAP operators are symbols or special characters that apply particular operations on
operands. Variables, constants, or expressions can all be considered operands. Numerous
operator types are supported by SAP ABAP, such as, arithmetic, comparison, automated type
adjustment, and character string operators.
34
REPORT ZDEMO_PRGM.
*write 'SAP ABAP Development'.
write: / result.
Output
15
5
50
2
0
35
Comparison/ Relational Operators in SAP ABAP
Comparison operators in SAP ABAP are utilized to compare data and offer conclusions depending
on the comparison’s results. These operators include equal to (EQ), not equal to (NE), less than
(LT), less than or equal to(LT) , greater than(GT) , and greater than or equal to (GE). Here we are
sharing you a table in which every comparison operator is discussed in detail.
Operator Function
=, EQ Returns true If two operands are equal to each
other
<>, NE Returns true If two operands are not equal to
each other
<, LT Returns true If first operand is less than
second.
>, GT Returns true If first operand is greater than
second.
<=, LE Returns true If first operand is less than or
equal to second.
>=, GE Returns true If first operand is greater than or
equal to second.
IS INITIAL Returns true if the variable declared is not
modified
IS NOT INITIAL Returns true if the variable declared is
modified
36
Example.
REPORT ZDEMO_PRGM.
Write: / result.
Output
False
37
ABAP Data Dictionary – Create database table
The ABAP Data Dictionary (DDIC) is a central repository in SAP that defines and manages
database objects such as tables, views, data elements, domains, search helps, and lock objects.
It ensures data consistency, integrity, and reusability across the SAP system.
With DDIC, developers can define database structures independently of the underlying database,
making it easier to manage data definitions centrally without redundancy. The transaction code
to access the Data Dictionary is SE11.
1️ Transparent Tables
• These are one-to-one representations of database tables, meaning their structure in SAP is the
same as in the underlying database.
• Used to store actual business data.
• Example: BKPF (Accounting Document Header), MARA (Material Master).
• Multiple small logical tables are stored in a single physical table in the database.
• Used to manage control data with small, rarely accessed records.
• Example: T000 (Client Table).
• Stores multiple records from different tables in a single field of a physical database table.
• Used for storing complex data structures such as HR data.
• Example: BSEG (Accounting Document Segment in ECC).
Note: In SAP S/4HANA, Pooled and Cluster Tables are replaced by Transparent Tables for
performance optimization.
38
1. Create database table.
In this document I have given step by step procedure to create below table.
[Link] Fields Data Element Data Type Length Decimal Short Description
1 MANDT MANDT CLNT 3 Client
2 Order_N Zonum NUMC 14 Order Number
3 Date1 ZDate DATS 8 Order Date
4 Vendor Zvname CHAR 30 Vendor Name
5 POrg Zporg CHAR 4 Purchasing Org
6 Total_A Ztotal CURR 7 2 Total Amount
7 Currency ZCrn CUKY 5 Currency
Select Create.
39
Give client field and data element.
40
Give field name and data element for Order name.
Save it.
Double click on data element (ZONUM).
Click on Yes.
41
• Data Element
42
Select Yes.
43
Click on Yes.
44
Save – Check and Activate.
45
[Link] Fields Data Element Data Length Decimal Short Description
Type
1 MANDT MANDT CLNT 3 Client
2 Order_N Zonum NUMC 12 Order Number
3 ODate ZDate DATS 8 Order Date
4 Vendor Zvname CHAR 30 Vendor Name
5 POrg EKORG CHAR 4 Purchasing Org
6 Total_A Ztotal CURR 7 2 Total Amount
7 Currency ZCrn CUKY 5 Currency
Example:
• Domain: CURRENCY (Data type: CURR, Length: 3, Fixed values: INR, USD, EUR)
46