Entering content frame

Editing Programs Locate the document in its SAP Library structure

You edit programs using the Structure linkABAP 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

The first statement in any ABAP Program is always an introductory program statement, often REPORTor PROGRAM. Both statements have exactly the same function.

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

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

REPORT name. for executable programs, or

PROGRAM name. for module pools or subroutine pools

The system enters the name you used to create the program as the report or program name.

       2.      Data declaration

Next, insert all of your declarations. These include selection screen definitions, the declarations of local classes and interfaces and global data declarations.

       3.      Processing logic

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

       4.      Subroutines

At the end of your program, include its internal procedures (such as subroutines).

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 declarations. 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: Note the following suggestions.

Add Comments to 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. Pre-defined comment blocks are provided in the Structure linkABAP Editor to help you comment your programs. 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:

This graphic is explained in the accompanying text

Use Modules

Make your programs easier to understand by using modules. For example, writing a large processing block as a method makes the logical structure of your program easier to recognize. Programs with classes and methods may be longer, but you will soon find that this approach greatly increases clarity, especially in the case of complex programs.

Pretty Printer

If you use the Pretty Printer in the Structure linkABAP Editor, your programs will conform to the layout guidelines.

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 Pattern. 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   Extended Program Check from the Editor screen. Ensure that you correct all of the errors and warnings displayed. Many of the errors found during the extended program check indicate that program cannot run properly. Others, although they do not prevent the program from working, are examples of poor 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 in the ABAP Editor. 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. For example, if you have 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 Structure linkruntime analysis, which shows you the amount of time your program consumes in the client/server environment of the SAP System and what this time is used for. For more information, refer to the runtime analysis documentation.

 

 

 

Leaving content frame