Editing Programs 

programmeinleitende Anweisung

You edit programs using the ABAP Editor. For detailed information, refer to the appropriate documentation. Below are a few hints to help you to get started:

Program Structure

The following gives a short overview on how to structure a program. Apart from the first statement, the sequence of statements is not obligatory, but you should keep to it for reasons of clarity and readability.

  1. The first program statement
  2. The first statement of an ABAP program must always be the statement REPORT or PROGRAM, respectively (only exception: FUNCTION-POOL for function modules). Both statements have exactly the same function.

    The name specified in the statements REPORT and PROGRAM must not necessarily be the program name, but for documentation reasons, you should use the correct name.

    The statements REPORT or PROGRAM can have several options, such as LINE-SIZE, LINE-COUNT, or NO STANDARD PAGE HEADING. You use these options mainly in programs that which evaluate data and display the results in a list. For other options, such as the definition of a message class, see the key word documentation.

    Whenever you create a new program, the system automatically inserts the first ABAP statement, for example:

    REPORT <name>. for executable programs (reports) or

    PROGRAM <name>. for dialog programs

    As report or program name, the system enters the name you used to create the program.

  3. Data declaration
  4. Next, insert all of your delclarations. This includes the global data definitions, selection screen definitions, and the definitions of classes and interfaces in ABAP Objects.

  5. Processing logic
  6. After the declarations, write the processing logic. This consists of a series of processing blocks.

  7. Subroutines

At the end of your program, include its internal procedures (subroutines and methods).

Using includes to split up a program into a series of source code modules does not change this basic structure. If, for example, you follow the forward navigation of the ABAP Workbench when creating a dialog program, the system automatically creates a number of include programs, which contain the program parts described above in the correct sequence. The top include program usually contains the PROGRAM statement and the global data declaration. The subsequent include programs contain the individual dialog modules, ordered by PBO and PAI. There may also be further includes, for example, for subroutines. These include programs do not influence the program function, they only serve to make the program order easier to understand.

Program Layout

A high-quality ABAP program observes the following layout standards:

Comment Your Programs

Ensure that your program is correctly commented. For example, at the beginning of a subroutine, explain what it does, and provide any necessary information and references. The ABAP Editor provides predefined comment blocks. Comments within lines of code should be used sparingly, and only where they do not make the program flow more difficult to understand.

Indent Blocks of Statements

You should combine statements that belong together into a single block. Indent each block by at least two columns:

Use Modules

Make your programs easier to understand by using modules. For example, writing a large processing block as a subroutine makes the logical structure of your program easier to recognize. Subroutines may increase the overall length of programs, but you will soon find that this method greatly increases clarity, especially in the case of complex programs.

Use the Pretty Printer

If you use the Pretty Printer in the ABAP Editor, your programs will conform to the layout guidelines. To use the Pretty Printer, choose Program ® Pretty Printer from the Editor screen.

Statement Patterns

In the ABAP Editor, you can use statement patterns to help you write your program. They provide the exact syntax of a statement and follow the ABAP layout guidelines. You can insert two kinds of predefined structures into your program code when using the ABAP Editor: Keyword structures and comment lines. In the ABAP Editor, choose Edit ® Insert statement. To display a list of all predefined keyword structures, place the cursor in the Other pattern. field and click the possible entries button to the right of the input field.

Checking Programs

When you have finished editing, or reach an intermediate stage of the program, choose Check to check the syntax. The system checks the program coding for syntax errors and compatibility problems. If it finds an error, it displays a message describing it and, if possible, offers a solution or correction. The system positions the cursor on the error in the coding. Once you decide that your program is finished, run the extended program check on it by choosing Program ® Check ® Ext. program check from the Editor screen. Ensure that you correct all of the errors and warnings displayed. Although they do not prevent the program from working, they are not examples of good programming. Furthermore, some warnings might be escalated to syntax errors in future releases.

Saving and Activating Programs

Choose Save to save the source code.

The system stores the source code in the program library. Before you can execute the program from outside the ABAP Editor, you must generate an active version using the Activate function.

Testing Programs

You can test executable programs in the ABAP Editor. To do so, choose Program ® Execute. The system then creates a temporary runtime object with a name that differs from the program name. However, the system executes the program as if started outside the ABAP Editor. If you created an ABAP module pool, you cannot test the program in the ABAP Editor. You must create a transaction code and a screen flow logic before you can execute the program.

Testing a program often involves a runtime analysis, which shows you the amount of time your program consumes in the client/server environment of the R/3 system and what this time is used for. For more information, refer to the runtime analysis documentation.