SAP ABAP Tutorial

FREE Online Courses: Your Passport to Excellence - Start Now

In this tutorial, we’ll be learning about the introduction to SAP ABAP. We will learn what SAP ABAP means, its history and dive deep into why and how it is an important language in today’s business systems.

What is SAP ABAP?

  • ABAP stands for Advanced Business Application Programming.
  • It is a high-level, fourth-generation programming language used in SAP software.
  • Along with Java, ABAP is the main programming language used for large SAP business applications.
  • SAP systems run on three-tier software, with ABAP at the application server level.
  • ABAP program runs inside the SAP database.
  • The run-time or execution system runs all ABAP statements while the program is running.
  • Along with executable code, ABAP also runs database languages like open SQL and native SQL to access, create, update, and other operations on databases.

Inside the SAP database, the ABAP code runs in two forms:

  1. Source code: the basic program that is written, edited, or updated by a programmer.
  2. Generated code: similar to Java bytecode, generated code is an intermediate level of code between written code and final machine code.

Why ABAP?

  • It is the main language of SAP software, which is used by more than half of the world’s businesses.
  • It is a simple, easy-to-understand, object-oriented language.
  • However, it also allows you to choose if you want to run it as procedure-oriented.
  • It is used to develop SAP R3 systems.
  • ABAP helps improve SAP applications.
  • It can easily be learned by both programmers and non-programmers.
  • It provides many features such as data-sharing, data-hiding, inheritance, persistence, etc.
  • You can access any database via SAP ABAP.

SAP ABAP Features

History of SAP ABAP

  • SAP created ABAP in the 1980s.
  • The world came to know of ABAP as a development language, great for businesses stepping into technology and data.
  • In the 1990s, SAP released object-oriented ABAP.
  • In 2006, they released a version offering a switch framework.
  • Then in 2012, they released the table expressions feature.
  • In 2015, they released open SQL support.
  • In 2017, they released virtual sorting of internal tables.
  • They have also recently introduced Machine Learning (ML) and Artificial Intelligence (AI) extensions to the language, to keep up with the times.

SAP ABAP Architecture

  • ABAP runs on 3-tiered architecture

SAP ABAP Architecture

  • The three layers are as follows:
    1. Presentation layer: This layer controls the entire system. It is the devices and interfaces through which the user interacts with the system. This can include a computer, mobile, browser, etc. An ABAP program starts at this layer but executes at the application layer
    2. Application layer: This layer is the middling layer that acts as an interface between the presentation and database layer. It performs processing and communication with the other two tiers.
    3. Database layer: As the name goes, the database layers contain the stored data of the program in memory that is accessed as and when required by the execution.
  • ABAP programs are stored in the SAP system itself
  • There are two parts of code: source code (written and edited by user) and generated code (binary code used to execute)

Types of ABAP Programs

ABAP programs can be divided into two types:

  1. Reports: standalone programs that are executable, contain one screen.
  2. Module pools: many screens that are logically linked together as one.

ABAP also has non-executable programs:

  1. Interface type pools
  2. Object classes
  3. INCLUDE modules
  4. Function groups
  5. Subroutine pools

Basic Syntax of ABAP programs

1. Statements

  • Each ABAP program comprises executable lines of code called ‘statements’.
  • Every statement in ABAP is a collection of keywords, variable names, etc. that have some meaning and produce some meaningful output when the program is executed.
  • Each statement ends in a period (.)
  • ABAP is not case-sensitive, so we can exchange uppercase and lowercase statements to mean the same thing.
  • The first statement in an ABAP program is always the REPORT statement, which declares the name of the report we are writing.
  • ABAP is case insensitive, i.e. it does not differentiate between uppercase and lowercase statements except when they are in single quotes
  • You can write multiple statements on a single line, as long as each individual statement ends with a period (.)

Example of Statements in ABAP

REPORT ZDATAFLAIR_REPORT_001.
    WRITE: ‘HELLO WORLD!’.
    *The output will write whatever is included within single quotes

Output:

HELLO WORLD!

2. Comments in ABAP

  • Comments are non-executable lines of code.
  • We usually add comments to express the meaning of the statements we write in the program.
  • We use comments to explain, reiterate or simply add a comment of value to the program.
  • Adding comments helps us and others understand the executable code better.
  • We do not have to end comments with a period as they do not run.
  • Full line comments are written with an asterisk (*) and half line comments are written with double quotes (“)

Example

REPORT ZDATAFLAIR_REPORT_001.
    * this is a full-line comment
    WRITE: ‘HELLO WORLD!’.	“ this is a half-line comment

Output:

HELLO WORLD!

Few Keywords in ABAP

1. ULINE: to add an underline below the statement

E.g.  

REPORT ZDATAFLAIR_REPORT_001.
    WRITE: ‘HELLO WORLD!’.
    ULINE.

Output:

HELLO WORLD!

2. SKIP: to go to the next line in the display

E.g.

REPORT ZDATAFLAIR_REPORT_001.
    WRITE: ‘HELLO WORLD!’.
    SKIP.
    WRITE: ‘BYE BYE WORLD!’.

Output:

HELLO WORLD!
BYE BYE WORLD!

Messages in ABAP

A message displays errors, warnings, and other messages that the system may want to send to the programmer. It is usually a 2-character text that pops up to inform the user of the happenings in the execution.

Let’s see a few examples of messages:

MESSAGEMEANINGDESCRIPTION
EErrorThis message showcases an error that leads to the program stopping its execution
WWarningThis message pauses execution due to a warning, and needs user intervention for the execution to continue
IInformationThis message displays some information for the user which they need to intervene to pop out of
AAbendThis message abends or retracts whatever transaction was being done by user
SSuccessThis showcases the success of a transaction
XAbortThis message creates dump and halts execution of program

How to write your first ABAP Report in ABAP Environment

  1. Open SAP System
  2. Go to SE38 – this opens the ABAP Editor/Workbench – the workbench includes several features of ABAP like the Editor, which we will use now and the rest we shall see in further tutorials
  3. Under field ‘Program’ enter your report name. It must start with a ‘Z’ or ‘Y’ and is case insensitive e.g. ‘ZDATAFLAIR_HELLOWORLD’

ABAP Report in ABAP Environment

     4. Now select the ‘Create’ button on the right

     5. Click on ‘OK’ and choose the ‘Executable Program’ option from the dropdown menu

SAP ABAP Program

Write the following statements to create your first Hello World program:

REPORT ZDATAFLAIR_HELLOWORLD.
WRITE 'Hello World!'.

Output

Hello World!

Colon Notation in ABAP

In ABAP, we can combine a few lines of code if all of them begin with the same statement. We can do this by using the colon notation (:).

For e.g.

Instead of writing –

WRITE ‘Hello’.
WRITE ‘My’.
WRITE ‘Name’.
WRITE ‘Is’.
WRITE ‘Dataflair’.

We can write –

WRITE: ‘Hello’,
      ‘My’,
      ‘Name’,
      ‘Is’,
      ‘Dataflair’.

Output (same in both cases):

Hello My Name Is Dataflair

Summary

Thus, in this tutorial, we learned about ABAP. In the following tutorials, we will go through each concept one by one and learn what exactly SAP ABAP includes.

You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *