A Crash Course in the Basics of ABAP for SAP

This article is the first of a two-part series where we delve into the basics of ABAP for SAP.

ABAP is a language used to code add-ons for SAP. The acronym stands for Advanced Business Application Programming. ABAP was developed by SAP specifically for use with its suite of products. At first glance, ABAP may look a lot like Java. Despite the resemblance, how it works is a lot different, however, understanding Java will give you an advantage in understanding how ABAP works. The current iteration of SAP NetWeaver supports both Java and ABAP. ABAP is the backbone of the SAP R/3 system, and it was used as a tool to develop the nuts and bolts of the system.

Understanding the R/3 Architecture

R/3 is the name of the platform on which SAP applications run. The R stands for real-time, and the 3 describes the three-tier structure of the platform. Depending on the perspective, the R/3 system can have one of two different views:

  • Logical View: An overhead of all the working parts of the R/3 system. It doesn’t describe applications linked to hardware or software entities.
  • Software Oriented View: This view focuses solely on how applications interact with software or hardware entities.

ABAP also has a cross-section of external communication components to interact with external entities like the internet. These are:

  • The RFC interface: Remote function calls are at the heart of most modern coding languages that deal with complex systems. The RFC interface is the traditional way for ABAP programs to interact.
  • ABAP Channels: These use events to communicate between ABAP programs and the internet. The channels can send messages between ABAP programs running on different servers.
  • Internet Communication Manager (ICM): another method for communicating with the internet, but this time, connecting web-based components of the ABAP system to resources online.

The R/3 architecture offers a robust platform for building our ABAP applications on top of. But what’s the general structure of an ABAP program?

ABAP Program Structure Basics

ABAP applications are used to process data from a variety of inputs. They can be divided into blocks, with an ABAP program requiring all of these blocks to function correctly. The general structure of an ABAP program can be broken down into three broad processing blocks:

  1. Header: The header section is a mandatory section that contains important information about the program. It usually starts with a declaration of REPORT or PROGRAM, much like highly-typed languages of the past like Pascal or Fortran used to use.
  2. Declaration: Again, like older languages like Pascal, there’s a dedicated area at the top of the program structure for data variable declaration. All declaration statements happen here, unlike in Java, where a variable can be declared right before being used.
  3. Processing Blocks: These come in several varieties and deal with the nitty-gritty of processing data sent to the ABAP program. Among the types of processing blocks you’re likely to encounter in your experiences with ABAP include:
    • Dialog Module: This module deals with screen flow and command logic. They use MODULE and END MODULE commands to define their block.
    • Event Blocks: These deal with both lists, inter-program events, and selections screens.
    • Subroutines: These are reusable bits of code that make ABAP an object-oriented language. They are defined between FORM and ENDFORM keywords. PERFORM is used to call a subroutine block.
    • Functions: Functions allow for an external interface that can be called from other ABAP programs. They are defined between FUNCTION and ENDFUNCTION keywords and are executed with a CALL FUNCTION command.
    • Methods: Methods can be thought of as classes. They are created between the METHOD and ENDMETHOD keywords and are called using the CALL METHOD command.
    • ABAP Statements: Anything that doesn’t fall into these categories can be considered ABAP statements. These statements are the basis of the processing that the application does.

Naming Conventions for ABAP Programs

ABAP has clearly defined rules for its naming conventions, such as:

  • The name of an ABAP program can be anywhere between one and thirty characters long.
  • The program name cannot contain special characters like periods, parentheses, equal signs, asterisks, percentile signs, or underscores.
  • A user-built program should start with a Y or a Z.
  • SAP-built programs should start with an A or an X as reserved characters.

What Are the Characteristics of an ABAP Program?

At a glance, a few things stand out immediately to make a program recognizable as an ABAP code block. Some of these are:

  • ABAP statements begin with a keyword and end with a period.
  • Words are separated by at least one space. While other languages might detect extra spaces as characters or indentation, ABAP condenses it into a single character.
  • Indentation is at the discretion of the programmer. There are no defined rules for indentation for an ABAP program.
  • ABAP statements CAN be more than a single line long, although this isn’t recommended and should be avoided if possible.
  • ABAP statements are not case-sensitive, and they can be written any way the user chooses to write them. The exception is in comparison since case matters when comparing program names.

Learning ABAP Takes Time

While this gives a general overview of the structure of an ABAP program and the general syntax for some of its coding conventions, it will take time to grasp how it works in practice. ABAP is different from many other languages in that the concept of memory is linked to a database. Sometimes, the database it’s using is cloud-based—all of these impacts how a programmer writes ABAP code significantly. The only way to properly appreciate ABAP is to delve into it and do some tutorials on how to build ABAP applications on top of an SAP distribution. Getting to grips with the language takes more than just theory. It requires practice and execution. If you’re new to ABAP development, you’re welcome to submit questions to the ABAP Q&A Tag to get some help when you need it. You don’t need to learn everything on your own. Use the community. They’re here to help.

In the next article, we’ll cover program types, what they’re used for, ABAP statements and keywords.