An Introduction to ABAP Coding
ABAP is SAP’s programming language and one of the most widely used languages for developing apps to support business operations. ABAP is a high-level programming language that allows developers to create functionally rich software applications for businesses. ABAP programs run in the ABAP runtime environment, part of the SAP kernel. This environment handles the processing of statements and the flow logic of screens.
Function modules are a significant part of SAP systems because they allow you to encapsulate and reuse global functions. They are also essential in database updates and remote communications between R/3 and non-SAP systems. They are stored in a central library and can be called from any SAP ABAP coding. Reports are another type of function module, which follow a relatively simple programming model where you enter a set of parameters, and the program produces a report. The data entered by the user is known as import parameters, and the data returned from the module is known as export parameters. You can also define a function module as an update module, where you register it to be executed later with a commit command or after the main program has been committed. However, this is only a rare exception and should only be used for some things. Unlike subroutines, function modules are defined in the same ABAP/4 program being called. All data objects declared in the main program are automatically available to the function module.
Object-Oriented Programming (OOP) is a method of programming that allows you to create different kinds of objects in memory. These objects are created through a process known as instantiation. When you start making a class, you describe the data you want the course to hold. This description also includes any logic sequences that can manipulate the data. In OOP, this information is then passed down through inheritance, preventing the need for duplication of data or functions in the same class.
This also allows for more efficient coding since it saves time on repetitive code. Another advantage of OOP is the ability to encapsulate data and services. This enables you to separate the state of an application from its internal data. In classic procedural ABAP, the form of an application is determined by its global variables. This can lead to unreliable, error-prone code.
Data structures logically organize data so that it can be used efficiently. For example, you might have folders with logical department names and individual files named descriptively on a computer, often in date or version format. ABAP program data is organized similarly by storing it in structures and tables. Structures, in turn, contain components of any data type. A data element can be a single unit of values or a collection of units, such as a list of prices. It can also be a field in a table or structure.
In addition to structures, ABAP programs can use other data objects such as arrays, stacks, and queues. Collections store items at adjoining memory locations, while stacks and queues can expand or contract as needed during program execution. ABAP program types define the essential technical attributes of an ABAP program, which processing blocks it may contain, how it is handled and executed by the ABAP runtime environment, and whether it can work with its screens. The ABAP runtime system is responsible for processing ABAP statements, controlling the flow logic of screens, and responding to events.
Variables are data objects to that you can assign values in ABAP programs. Each variable has a specific type that determines its size and layout, its range of values, and the set of operations that can be applied to it. ABAP also provides a set of predefined types that you can use to define a new variable. These can include character variables, packed number variables with up to two decimal places, and data types for dates and times. A good rule of thumb is to choose a meaningful name for a variable that explains its purpose. This can make the code more readable, reduce documentation costs, and make it easier to maintain. The ABAP language has a long tradition of using cryptic technical and abbreviated names for variable definitions, but this needs to be updated. The clean code philosophy recommends using more expressive and meaningful words in ABAP code.
Statements are an essential part of ABAP programming. They allow you to manipulate the program flow and control the execution of your programs’ logical expressions and conditional loops. Many statements include declarative statements, defining messages, call reports, and operational statements. Declarative statements use the declarative keywords to define data objects another ABAP statement uses, such as constants, tables, and views. Defining statements uses the defining keywords to define subroutines, dialog modules, functional modules, and methods. Defining words end with the END keyword. Call statements allow you to call processing blocks you have already defined using modularization statements. These calling blocks can be in the same ABAP program or a different program. ABAP supports using type declarations for data elements, tables, views, and structures passed into subroutines and functions. Whenever you pass values into a subroutine, assigning them to a specific type is best. This improves the performance of your programs. For this reason, ABAP recommends that you use type declarations in all your code.