SAP USE PRETTY PRINTER - Guide
Get Example source ABAP code based on a different SAP table
Using Pretty Printer
ABAP_BACKGROUND
The alignment of ABAP statements in the source code is not defined in the syntax. There should be a
Languages with a <(>C<)>-like syntax (where statement blocks within control structures are delimited by curly brackets) provide an inexhaustible source for discussions on how to best make indentations. However, for ABAP the solution is obvious: Every initiating statement (such as
Pretty Printer can modify the indentation of control structures and the capitalization of keywords and names in the source code at any time (even in display mode).
ABAP_RULE
Use Pretty Printer to format source code consistently. If Pretty Printer cannot format the code as required, manual changes are necessary.
ABAP_DETAILS
We recommend that the use of Pretty Printer to make indentations required to make the source code easy to read. This guarantees that the indentations are consistently based on the logical control structure and that the indentation depth is identical for each program. Implementing this type of formatting by hand is prone to errors and not recommended.
Even though Pretty Printer can be used to adapt the source code to any other style (using the available settings), a consistent and universal style should be selected. The reason for this is that version management and the correction workbench are not designed to ignore purely stylistic differences between source code versions. Therefore, the following Pretty Printer settings are recommended for consistent source code formatting. These settings cover the expectations and working habits of most ABAP developers:
The code needs to be edited manually, to ensure the correct use of blank lines between related source code blocks. Syntax units, such as classes, methods, control blocks, or semantic units of a program, should be separated from one another with one or two blank lines (depending on their size and meaning). However, there should not be more than two blank lines in succession.
Note
We recommend that the use of the
from DBTAB
into corresponding fields of ITAB
where COLUMN = FIELD.>
Names in uppercase are also more suitable because many dynamic operand positions in ABAP still require uppercase. A good example is an almost static call of function modules. Using the
However, the
ABAP_EXAMPLE_BAD
The following source code shows the above example, but without indentations and only with lowercase. The highlighted ABAP words (shown in bold here and in color in the ABAP Editor) might not appear in a program printout. This would make the program even less legible.
public section.
methods meth.
endclass.
class class implementation.
method meth.
data: itab type table of dbtab,
wa type dbtab.
select *
from dbtab
into table itab
where column = ' '.
if sy-subrc <> 0.
return.
endif.
loop at itab into wa.
...
endloop.
endmethod.
endclass.>
ABAP_EXAMPLE_END