Program Structure
Concept
Each standalone ABAP program consists of an introductory program statement and a global declaration part. Depending on the program type, various types of processing blocks can then follow. Screens for SAP GUI (known as dynpros in the SAP system) can be created for certain types of ABAP program.
-
Different types of ABAP program require a different type of introductory program statement. This statement is defined in the editor when a program is created.
-
Below the program introduction, each program contains a global declaration part for the definition of data types, data objects, and local classes and interfaces present at program runtime and which are visible across the entire program. The definitions that can be made here depend on the program type in question.
-
Each imperative statement of an ABAP program is implemented in a processing block. Processing blocks cannot be nested. The processing blocks are specified (in any order) below the global declaration part. The following categories of processing block exist, each of which can be exited prematurely using RETURN:
-
Procedures (methods, function modules, subroutines) called from the same program or a different program.
-
Dialog modules called from the dynpro flow logic.
-
Event blocks triggered by events in the ABAP runtime environment.
-
Example
The program starts with an introductory program statement REPORT that defines the type of the program (in this case, an executable program). Next, a data object with the name num and type Integer is declared. In the third line, the standard event block START-OF-SELECTION is defined. The following operative lines are part of this block. The program lines 58 produce, in succession, the lines 'Hello ABAP/1' to 'Hello ABAP/4', plus a line break. When the program is executed, the ABAP runtime environment triggers the event START-OF-SELECTION, which starts the corresponding event block in the program. The statement WRITE is then used to pass the character strings to the list processor, which in turn forwards them to be displayed on the associated GUI window.
REPORT hello_world.
DATA num TYPE i.
START-OF-SELECTION.
num = 1.
DO 4 TIMES.
WRITE: /, 'Hello ABAP/', 12(1) num.
num = num + 1.
ENDDO.