Skip to content
SAP ABAP Programming: Beginner's Guide

SAP ABAP Programming: Beginner's Guide

DodaTech Updated Jun 19, 2026 9 min read

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 Z indicate customer-developed programs (SAP reserves Y and Z namespaces)
  • 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: FIVEHUNDRED

Internal 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.00

Internal 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 Paris

Open 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 table

Always 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

  1. What does REPORT Z_MYPROG do? Declares a standalone ABAP program. Program names starting with Z are customer-developed.

  2. What is an internal table? An in-memory data structure that holds multiple rows of structured data, similar to a database result set.

  3. How do you add a row to an internal table? Use APPEND gs_work_area TO gt_table.

  4. What does LOOP AT ... INTO do? Iterates over each row of an internal table and copies the current row into a work area.

  5. 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

Is ABAP similar to COBOL?
Both use English-like syntax and are business-oriented, but ABAP is modernized with object-oriented features, internal tables, and tight SAP integration.
Can I write ABAP without SAP access?
You can learn syntax from SAP documentation, but you need an SAP system (trial or sandbox) to compile and run ABAP programs.
What is the difference between ABAP and SAP HANA?
ABAP is a programming language. SAP HANA is an in-memory database. Modern ABAP (7.5+) can leverage HANA-specific features like Core Data Services (CDS).
Is ABAP dying?
No. SAP S/4HANA still uses ABAP extensively. SAP has committed to ABAP long-term, though modern development also uses JavaScript (SAPUI5) and Java.
What IDE does ABAP use?
SAP GUI with ABAP Workbench (SE38, SE24) is traditional. SAP also provides ABAP Development Tools (ADT) for Eclipse.
How do I debug an ABAP program?
Use transaction code SE38 to open the program, set breakpoints with /h in the command field, then execute the program.

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: 20260606

Open 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

TutorialWhat You’ll Learn
SAP Modules Explained — FI, CO, SD, MM & HRHow SAP modules work and how each one uses ABAP programs
SAP Overview — Complete GuideFoundational SAP concepts and ERP basics
Python for ERP Data ProcessingCompare 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