SAP ABAP Overview (An Easy Introduction)

Matthew Tice
7 min readSep 9, 2018

--

SAP ABAP Explained

Introduction — What is ABAP?

ABAP is a compiled 4th generation programming language (4GL). The term ‘4th generation language’ means that ABAP is human-readable, easy to use and powerful. The ABAP acronym stands for Advanced Business Application Programming. All ABAP programs and compiled code exist in an SAP system. Contrary to programming languages like Java, you cannot execute an ABAP program outside of SAP. SAP created ABAP for the purposes of enhancing and extending the functionality of an SAP system.

4th Generation Languages: Human-readable, easy to use, efficient and powerful.

The ABAP programming language was introduced by SAP in the seventies. At that time it was used to generate primitive reports in an SAP system. In the nineties SAP released an updated version of ABAP. This update advanced the usability and power of the language.

In 1999 an object-oriented extension of the language called ABAP Objects was released. This update included support for computer science concepts like classes and polymorphism. Much of the functionality introduced by this update was modeled on aspects of 3rd generation programming languages like C, C++ and Java.

How is ABAP written?

ABAP Code is written using tools in the ABAP Workbench (transaction SE80.) The Workbench is a comprehensive suite of programs used for developing ABAP code. The Workbench is only available inside of an SAP system. Developers can access specific tools found in the Workbench through transaction codes. For example, transaction SE38 is for the creation and maintenance of reports. Transaction SE24 is for the creation and maintenance of classes and interfaces.

Additionally, third party software vendors such as Eclipse provide front end programs for writing ABAP code. These integrated development environments (IDE) still need a connection to an SAP system to check and compile code. You can learn more about Eclipse and SAP here.

What is ABAP used for?

SAP customers employ ABAP programmers to extend the functionality of their SAP system to meet specific business needs. The acronym WRICEF explains the types of objects developers create in SAP. WRICEF stands for: Workflows, Reports, Interfaces, Conversions, Enhancements and Forms.

ABAP developers leverage their skills and experience with SAP to create custom objects in an SAP system. For example, an ABAP consultant might be hired to write custom reports that are not available in an out-of-the-box SAP system. Most companies will use at least some custom ABAP code to change how their SAP system behaves. It’s not uncommon for companies that rely heavily on custom ABAP to have completely transformed their SAP system over time.

SAP provides many frameworks through which customers can enhance SAP-standard code. These include user exits, business add-ins (BAdIs), business APIs (BAPIs) and enhancement spots. Customers also have the option of modifying SAP-standard code directly (although this is very bad practice). Alternatively, an ABAPer might make a z-copy of SAP-standard code and modify it to meet the company’s requirements.

How do ABAP programs work?

ABAP is a compiled language. The role of the compiler is two-fold. First, the compiler is a gatekeeper: it submits ABAP programs to a battery of tests to ensure the code is as ‘correct’ and as safe as possible. As an example, it’s the compiler’s job to issue an error if a developer’s code is not syntactically correct. Second, the compiler translates the human-readable ABAP code into optimized byte code.

Byte code is a low-level type of code that is understood by a computer but isn’t human-readable or easy to work with. In SAP, the byte code generated by the compiler contains functions from the C and C++ programming languages. Behind the scenes the ABAP runtime environment coordinates with the SAP kernel to execute functions written in C and C++. These functions do the actual work described by the ABAP program.

When a user executes a program in SAP the corresponding byte code is loaded into the ABAP runtime environment and executed. ABAP programs cannot be executed outside of an ABAP runtime environment. The ABAP runtime environment exists inside of an ABAP Application Server.

Where are ABAP programs stored?

ABAP code is stored in database tables within an SAP system. Code is stored in two ways:

1. Human-readable source code that can be displayed or modified using the ABAP workbench tools. A compressed version of this code is stored in table REPOSRC. For example, if a developer writes code in transaction SE38 and saves it, that code would be stored in table REPOSRC.

ABAP source code is stored in table REPORSC.

2. Non-human-readable byte code that is generated by the ABAP compiler when a developer activates their code. This byte code is executed by the ABAP runtime environment. ABAP byte code is stored in table REPOLOAD.

ABAP byte code is stored in table REPOLOAD.

How is ABAP code executed?

When an ABAP program is executed by the user, the corresponding byte code is loaded into the Program Execution Area (PXA). The ABAP runtime environment then interprets the byte code and calls the appropriate C functions behind the scenes.

ABAP byte code is loaded into the PXA and executed.

Programming Paradigms — Classifying ABAP Based On Its Features

Object-Oriented ABAP is referred to as ABAP Objects and is available as of release 4.6. SAP has released official guidelines for implementing ABAP Objects the right way. While ABAP Objects shares many similarities to languages like Java and C++, there are several notable differences.

[X] ABAP Objects does not support destructors. SAP can implement a special kind of destructor that calls a function module from the C programming language. This is for internal use only and not available to SAP customers. For everything else, SAP employs a garbage collector behind the scenes to handle memory management.

[X] ABAP Objects does not allow method overloading. This means that you cannot have two methods in the same class with the same name and visibility, but different method signatures.

[X] ABAP Objects does not allow multi-class inheritance. An ABAP class can inherit functionality from exactly one superclass. A superclass can have more than one subclass. A superclass can be the subclass of another superclass, and so-on.

Describing How ABAP Gets Things Done

ABAP is a structured language. ABAP code relies on control-flow statements (IF/THEN/ELSE) and repetition statements (LOOP, WHILE, DO). The intention of structured languages is to make code more readable while also being easier to develop and maintain. This in turn reduces the costs associated with creating and maintaining custom code over time.

ABAP is an imperative language. The overarching goal of an ABAP program is to tell the SAP system what to do, not necessarily how to do it. The statements in an ABAP program are used to change a program’s state. How the system executes the underlying byte code generated by the compiler is the domain of the ABAP runtime environment and the SAP kernel.

Typing Discipline — Describing How The Compiler Enforces Rules

Typing disciplines describe how the compiler treats data declared and used in a programming language. Strongly typed languages have strict rules that are enforced when the code is being compiled. Weakly typed languages have looser rules and may produce unpredictable results.

ABAP is a strongly typed language. This means that there are strict rules governing what is allowed in ABAP and those rules are enforced by the compiler, not the ABAP runtime environment. This puts the onus of writing correct code on the developer.

The ABAP compiler uses static type checking on program source code prior to generating byte code. Static typing requires that variables be clearly defined at compile time. The benefit of static typing is that errors associated with program variables are caught by the compiler before the program can be executed.

Conclusion

ABAP is a powerful language that has evolved over time. Today it is robust and capable of supporting modern and advanced programming concepts. ABAP developers play a critical role in an SAP implementation. They use their skills to bridge the gap between SAP and a company’s business requirements.

Further Reading

Originally published at ABAP Coder.

--

--

Matthew Tice

Matthew is a senior ABAP developer with more than 13 years’ experience writing ABAP for multinational companies. He is devoted to building better ABAPers.