Skip to main content

Module 3 - ABAP Language Basics

This module introduces the core building blocks of the ABAP language. You will learn how ABAP programs are structured, how data is defined and used, and how modern ABAP (7.4+) simplifies coding.


1. ABAP Program Structure

An ABAP program follows a top-down, event-driven structure.

Basic Structure

REPORT z_demo_program.

DATA gv_text TYPE string.

START-OF-SELECTION.
gv_text = 'Hello ABAP'.
WRITE gv_text.

Common Program Sections

  • REPORT – Program declaration

  • DATA – Data definitions

  • INITIALIZATION – Initialization logic

  • START-OF-SELECTION – Main processing block

  • END-OF-SELECTION – Output processing

Event-Driven Nature

ABAP reports execute based on events, not just sequential code like many other languages.

2. Data Types in ABAP

ABAP is a strongly typed language.

2.1 Elementary Data Types

  • i — Integer
  • p — Packed number
  • string — Variable-length text
  • d — Date
  • t — Time
  • c — Character
DATA gv_count TYPE i.
DATA gv_price TYPE p DECIMALS 2.
DATA gv_name TYPE string.

2.2 Complex Data Types

  • Structures

  • Internal Tables

TYPES: BEGIN OF ty_employee,
emp_id TYPE i,
name TYPE string,
END OF ty_employee.

DATA gs_emp TYPE ty_employee.
Best Practice

Prefer TYPES for reusable data definitions.

3. Variables & Constants

Variables

DATA gv_total TYPE i VALUE 10.

Constants

CONSTANTS gc_tax TYPE p DECIMALS 2 VALUE '18.00'.
Naming Convention
  • gv_ → Global variable
  • lv_ → Local variable
  • gc_ → Constant
  • gs_ → Structure
  • gt_ → Internal table

4. Inline Declarations (ABAP 7.4+)

Inline declarations reduce boilerplate code.

Inline DATA

DATA(lv_sum) = 10 + 20.

Inline in SELECT

SELECT * FROM spfli INTO TABLE @DATA(lt_spfli).
Modern ABAP Style

Use inline declarations where scope is small and readability improves.

5. Operators & Expressions

5.1 Arithmetic Operators

  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
lv_total = lv_price * lv_qty.

5.2 Comparison Operators

  • = Equal
  • <> Not equal
  • < Less than
  • > Greater than
  • <= Less than or equal to
  • >= Greater than or equal to
IF lv_total > 100.
WRITE 'High value'.
ENDIF.

5.3 Logical Operators

  • AND

  • OR

  • NOT

IF lv_qty > 0 AND lv_price > 0.
WRITE 'Valid input'.
ENDIF.

6. Expressions in Modern ABAP

Expressions allow writing logic in a functional style.

Example

DATA(lv_result) = lv_a + lv_b * 2.

Conditional Expression

DATA(lv_status) = COND string(
WHEN lv_score >= 60 THEN 'PASS'
ELSE 'FAIL'
).
Why Expressions Matter

Expressions reduce temporary variables and improve readability when used correctly.

7. Comments in ABAP

Single-Line Comments

" This is a comment
* This is a full-line comment

Inline Comments

DATA lv_count TYPE i.  " Counter variable
Comment Wisely

Good code explains how. Comments should explain why.

8. Common Beginner Mistakes

Avoid These

  • Overusing global variables

  • Ignoring data types

  • Declaring variables too early

  • Mixing old and new ABAP syntax randomly

9. Summary

  • ABAP programs are event-driven

  • ABAP is strongly typed

  • Use TYPES for reusable definitions

  • Inline declarations simplify code

  • Expressions improve clarity

  • Naming conventions improve readability

10. Practice Exercises

  1. Create a program that calculates total price using quantity and unit price.

  2. Use inline declarations for variables.

  3. Create a structure for employee data.

  4. Use a conditional expression to determine pass/fail.

11. What’s Next?

➡️ Module 4: Control Structures

  • IF / CASE

  • Loops

  • CONTINUE / EXIT / CHECK

  • Nested logic best practices

Learning Tip

Write small programs for every concept — ABAP becomes easy only by practice.