Editing Your Program

To edit programs, you use the ABAP Editor tool. For more information about creating function modules, refer to the ABAP Workbench Tools documentation.

Writing programs

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 more information about designing lists, see Creating Complex Lists 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. Now declare all global data of your program. For further information, see Declaring Data.

  5. Processing logic
  6. Next comes the processing logic, which consists of a number of processing blocks (see Program Structure).

  7. Subroutines

The last unit of a program should be the list of all subroutines of the ABAP program. For more information about subroutines, see Modularizing ABAP Programs

Modularizing programs into source code modules does not change the above structure. If, for example, you follow the forward navigation of the ABAP Development 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 statement PROGRAM and the global data declaration. The subsequent include programs contain the individual dialog modules, ordered by PBO and PAI. Further include programs may contain, for example, subroutines. These include programs do not influence the functionality of the program, they only serve to enhance source code readability. See also the last two examples in the section Opening Programs by Forward Navigation.

Checking programs

After you finish editing or reach a temporary version, 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 that indicates the error and, if possible, offers a solution or correction. The system positions the cursor on the error in the coding.

Saving programs

Choose Save to save the source code.

The system stores the source code in the program library. When you execute the program for the first time outside the ABAP Editor or by choosing Generate on a screen of the ABAP Development Workbench, the system creates a runtime object for this program.

Testing programs in the ABAP Editor

You can test executable programs in the ABAP Editor. Choose Program ® Execute from within 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. If, for example, you created a report, you first see the selection screen for entering selection criteria and then the output list.

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 (for more information, see Dialog Mode).

For test purposes, you can even execute a stand-alone program without first saving it. The ABAP Editor stores a temporary version of the source code including all changes. However, after finishing the test, you must return to the editor and save the program to ensure that all changes are stored.

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 a runtime analysis, choose System ® UtilitiesRuntime ® analysis. For more information about creating function modules, refer to the ABAP Workbench Tools documentation.

For information on how to measure the runtime of program segments using ABAP statements, see Checking the Runtime of Program Segments.