SAP STATEMENT - Guide
Get Example source ABAP code based on a different SAP table
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 span multiple 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 multiple 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 multiple statements in one 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 spans
ABAP_EXAMPLE_BAD
The following source code shows a program section with correct syntax but that 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 WHERE column = ' ' INTO TABLE @itab.
IF sy-subrc <> 0. RETURN. ENDIF.
LOOP AT itab INTO wa. ... ENDLOOP.
ENDMETHOD. ENDCLASS.>
ABAP_EXAMPLE_END
ABAP_EXAMPLE_GOOD
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
WHERE column = ' '
INTO TABLE @itab.
IF sy-subrc <> 0.
RETURN.
ENDIF.
LOOP AT itab INTO wa.
...
ENDLOOP.
ENDMETHOD.
ENDCLASS.>
ABAP_EXAMPLE_END