SAP STATEMENT - Guide
Get Example source ABAP code based on a different SAP table
GUIDELINE 4.2
Statements per Program Line
ABAP_BACKGROUND
An ABAP statement (declaration or executable statement) is closed with a period. This statement can be followed by further statements in the same line. Statements can also be split over several lines.
ABAP_RULE
Write a maximum of one statement in every source code line. Long statements can and should be split at suitable places. This means the statements can be divided up across consecutive lines.
ABAP_DETAILS
Using several statements in one line makes the source code harder to read. If a line contains an entire control structure, the lack of indentations makes it especially difficult to identify the logical structure. Therefore you should try to avoid using more than one statement in a program line.
Besides reduced readability, using several statements in a line can also make the code more difficult to debug. Even in single steps, ABAP Debugger stops a maximum of once per executable program line. This makes it impractical for the debugging process if there is more than one statement in a line.
If a statement is split over
Bad example
The following source code shows a syntactically correct program section which is poorly laid out and difficult to understand. Even the
PUBLIC SECTION. METHODS meth. ENDCLASS.
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.
Good example
The following source code shows the same code as above but with the recommended limit of one statement per line. The complex
PUBLIC SECTION.
METHODS meth.
ENDCLASS.
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.