SAP ABAP Programming: Beginner's Guide
ABAP (Advanced Business Application Programming) is SAP’s proprietary programming language, used to customize and extend SAP ERP systems — from simple reports that display customer data to complex transaction workflows that process millions of records.
What You’ll Learn
- The basic structure of an ABAP program
- Data types, variables, and internal tables
- How to write a simple report program with selection criteria
- Real-world ABAP examples you can run in SAP
Why ABAP Matters
ABAP is the language of SAP customization. Every company that runs SAP has custom ABAP code — reports, enhancements, interfaces. Over 5 million ABAP programs exist in production worldwide. ABAP developers earn $90,000-$140,000 because the skill is in high demand and short supply.
DodaZIP uses ABAP-inspired internal table patterns for batch data processing. Durga Antivirus Pro applies ABAP-style modularization concepts in its scanning engine architecture.
Learning Path
flowchart LR
A[SAP Overview] --> B[ABAP Programming<br/>You are here]
B --> C[SAP Modules Deep Dive]
C --> D[SAP HANA Database]
D --> E[SAP BASIS Admin]
What Is ABAP?
Think of ABAP as the language that lets you talk to SAP in its own dialect. While SAP S/4HANA has standard screens and reports for 99% of business needs, companies always need that 1% of custom functionality — a specialized report, a custom input screen, or an interface to an external system.
That’s where ABAP comes in.
Analogy: ABAP Is Like Adding Rooms to a House
Imagine SAP S/4HANA is a house with all the standard rooms (kitchen, bedroom, bathroom). Most people are fine with these rooms.
But some companies need a home office, a workshop, or a wine cellar — custom spaces that aren’t in the standard floor plan.
ABAP is the tool you use to build those custom rooms. It works with SAP’s existing structure (walls, plumbing, electricity) and extends it without breaking anything.
Basic ABAP Syntax
ABAP is often compared to COBOL because both use English-like syntax. Let’s start with the simplest program:
REPORT Z_HELLO_WORLD.
WRITE: 'Hello, SAP World!'.- REPORT: Every ABAP program starts with REPORT followed by a name
- Z_HELLO_WORLD: Program names starting with
Zindicate customer-developed programs (SAP reservesYandZnamespaces) - WRITE: Displays text on the screen
Expected output in SAP GUI:
Hello, SAP World!Data Types and Variables
ABAP has both elementary data types (like other languages) and complex types unique to SAP.
REPORT Z_DATA_TYPES.
DATA: lv_name TYPE string,
lv_age TYPE i,
lv_salary TYPE p DECIMALS 2,
lv_date TYPE d,
lv_amount TYPE c LENGTH 10.
lv_name = 'Alice'.
lv_age = 30.
lv_salary = 75000.50.
lv_date = sy-datum.
lv_amount = 'FIVEHUNDRED'.
WRITE: / 'Name:', lv_name,
/ 'Age:', lv_age,
/ 'Salary:', lv_salary,
/ 'Today:', lv_date,
/ 'Amount:', lv_amount.Explanation:
- TYPE string: Variable-length string (like Python's
str) - TYPE i: Integer (whole numbers)
- TYPE p DECIMALS 2: Packed number with 2 decimal places (perfect for currency)
- TYPE d: Date field (format YYYYMMDD)
- TYPE c LENGTH 10: Character field with fixed 10-character length
- sy-datum: System field that contains today’s date
- WRITE: /: Writes on a new line
Expected output:
Name: Alice
Age: 30
Salary: 75,000.50
Today: 20260606
Amount: FIVEHUNDREDInternal Tables — ABAP’s Superpower
Internal tables are ABAP’s version of arrays or database result sets, but more powerful. They store multiple rows of structured data in memory.
Declaring an Internal Table
First, define a structure (like a row), then a table of that structure:
REPORT Z_INTERNAL_TABLE.
* Define a structure for customer data
TYPES: BEGIN OF ty_customer,
id TYPE i,
name TYPE string,
city TYPE string,
balance TYPE p DECIMALS 2,
END OF ty_customer.
* Declare an internal table using the structure
DATA: gt_customers TYPE TABLE OF ty_customer,
gs_customer TYPE ty_customer.
* Populate the table
gs_customer-id = 1001.
gs_customer-name = 'Acme Corp'.
gs_customer-city = 'New York'.
gs_customer-balance = 50000.00.
APPEND gs_customer TO gt_customers.
gs_customer-id = 1002.
gs_customer-name = 'GlobalTech'.
gs_customer-city = 'London'.
gs_customer-balance = 75000.00.
APPEND gs_customer TO gt_customers.
* Loop through and display
LOOP AT gt_customers INTO gs_customer.
WRITE: / gs_customer-id, gs_customer-name,
gs_customer-city, gs_customer-balance.
ENDLOOP.Explanation:
- TYPES: Defines a custom data type (structure)
- TYPE TABLE OF: Declares an internal table based on that structure
- APPEND: Adds a row to the table
- LOOP AT … INTO: Iterates over every row in the table
Expected output:
1001 Acme Corp New York 50,000.00
1002 GlobalTech London 75,000.00Internal tables are the backbone of ABAP programming. Every report, every interface, every data conversion uses them.
Selection Screen (User Input)
ABAP makes it easy to build reports with user input fields:
REPORT Z_CUSTOMER_REPORT.
* Selection screen fields
PARAMETERS: p_id TYPE i,
p_city TYPE string.
* Local structure and table
TYPES: BEGIN OF ty_cust,
id TYPE i,
name TYPE string,
city TYPE string,
END OF ty_cust.
DATA: gt_cust TYPE TABLE OF ty_cust,
gs_cust TYPE ty_cust.
* Fill some demo data
gs_cust-id = 1001. gs_cust-name = 'Alpha'. gs_cust-city = 'Paris'.
APPEND gs_cust TO gt_cust.
gs_cust-id = 1002. gs_cust-name = 'Beta'. gs_cust-city = 'Berlin'.
APPEND gs_cust TO gt_cust.
* Process selection and display results
WRITE: / 'Customer Report for City:', p_city.
ULINE. "horizontal line
LOOP AT gt_cust INTO gs_cust WHERE city = p_city.
WRITE: / gs_cust-id, gs_cust-name, gs_cust-city.
ENDLOOP.- PARAMETERS: Creates an input field on the selection screen
- ULINE: Draws a horizontal line
- WHERE: Filters the loop to matching rows
When executed, SAP shows a selection screen asking for a Customer ID and City. Enter “Paris” and the output is:
Customer Report for City: Paris
____________________________________
1001 Alpha ParisOpen SQL in ABAP
ABAP includes Open SQL — embedded SQL statements that work regardless of which database runs underneath (MySQL, Oracle, HANA):
REPORT Z_SQL_SELECT.
DATA: gt_flights TYPE TABLE OF spfli,
gs_flight TYPE spfli.
* Select data from SAP's standard flight database
SELECT * FROM spfli
INTO TABLE gt_flights
UP TO 10 ROWS.
LOOP AT gt_flights INTO gs_flight.
WRITE: / gs_flight-carrid, gs_flight-connid,
gs_flight-cityfrom, gs_flight-cityto.
ENDLOOP.- SELECT * FROM spfli: Queries the SAP standard demo table
- INTO TABLE: Stores results in an internal table
- UP TO 10 ROWS: Limits the result set
Real-World Use: Month-End Sales Report
In a real company, ABAP generates month-end reports for management:
REPORT Z_MONTHLY_SALES.
TABLES: vbak, vbap. "Sales document tables
DATA: gt_sales TYPE TABLE OF vbap,
gs_sales TYPE vbap.
PARAMETERS: p_month TYPE sdate DEFAULT sy-datum.
SELECT vbeln~erdat posnr~netwr
FROM vbak
INNER JOIN vbap ON vbak~vbeln = vbap~vbeln
INTO TABLE gt_sales
WHERE vbak~erdat BETWEEN p_month AND p_month + 30.
WRITE: / 'Monthly Sales Report for', p_month.
ULINE.
LOOP AT gt_sales INTO gs_sales.
WRITE: / gs_sales-vbeln, gs_sales-netwr.
ENDLOOP.
SKIP.
WRITE: / 'Total records:', sy-tabix.Security Angle
ABAP programs run under the user’s authorization. If a user lacks authorization for S_TCODE (transaction code) or S_TABU_DIS (table access), the ABAP program aborts with an authorization error. This prevents unauthorized users from reading sensitive data.
Durga Antivirus Pro applies ABAP-style authorization checks in its enterprise dashboard to ensure only authorized roles can view scan reports or modify policies.
Common Mistakes
1. Forgetting to use APPEND
gs_customer-id = 1001.
* Mistake: forgetting APPEND — the row is not added to the tableAlways use APPEND after populating your work area.
2. Confusing TYPE with LIKE
TYPE creates a new variable of a data type. LIKE copies the type of an existing variable or field.
3. Not using CLEAR before reusing a work area
Work areas retain previous values. Always CLEAR gs_variable before reusing it for a new row.
4. Hardcoding values
Never hardcode company codes, plant IDs, or fiscal years. Use PARAMETERS or SELECT-OPTIONS for user input.
5. Not handling exceptions in Open SQL
Always check sy-subrc after database operations. If sy-subrc <> 0, the SQL statement failed.
Practice Questions
What does
REPORT Z_MYPROGdo? Declares a standalone ABAP program. Program names starting withZare customer-developed.What is an internal table? An in-memory data structure that holds multiple rows of structured data, similar to a database result set.
How do you add a row to an internal table? Use
APPEND gs_work_area TO gt_table.What does
LOOP AT ... INTOdo? Iterates over each row of an internal table and copies the current row into a work area.What is Open SQL? SAP’s embedded SQL dialect that works across all supported databases (HANA, Oracle, DB2, etc.).
Challenge: Write an ABAP report that accepts a department ID as input, selects all employees for that department from a custom table (ZEMPLOYEES), calculates the average salary, and displays the results sorted by last name.
FAQ
Try It Yourself
If you have access to an SAP system (trial or sandbox), run this:
REPORT Z_TRY_ABAP.
DATA: lv_message TYPE string.
lv_message = 'Your first ABAP is running!'.
WRITE: / lv_message.
WRITE: / 'System:', sy-sysid.
WRITE: / 'Client:', sy-mandt.
WRITE: / 'User:', sy-uname.
WRITE: / 'Date:', sy-datum.Expected output (varies by system):
Your first ABAP is running!
System: A80
Client: 100
User: DEVELOPER
Date: 20260606Open SAP GUI, enter transaction code SE38, type Z_TRY_ABAP as the program name, click Create, paste the code, and click Activate. Then press F8 to run.
What’s Next
| Tutorial | What You’ll Learn |
|---|---|
| SAP Modules Explained — FI, CO, SD, MM & HR | How SAP modules work and how each one uses ABAP programs |
| SAP Overview — Complete Guide | Foundational SAP concepts and ERP basics |
| Python for ERP Data Processing | Compare ABAP data processing with Python ETL techniques |
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Updated 2026-06-06.
What’s Next
Congratulations on completing this Sap Abap tutorial! Here’s where to go from here:
- Practice daily — Consistency is more important than long study sessions
- Build a project — Apply what you learned by building something real
- Explore related topics — Check out other tutorials in the same category
- Join the community — Discuss with other learners and share your progress
Remember: every expert was once a beginner. Keep coding!
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro