Ansicht
Dokumentation

ABENNESTING_DEPTH_GUIDL - NESTING DEPTH GUIDL

ABENNESTING_DEPTH_GUIDL - NESTING DEPTH GUIDL

Fill RESBD Structure from EBP Component Structure   SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up  
This documentation is copyright by SAP AG.
SAP E-Book

Nesting Depth

The nesting depth is the number of statement blocks that are nested due to the use of control structures (branches, loops). We will discuss the nesting depth at the level of a procedure (method). Implementations must not occur at other points.

The maximum nesting depth is restricted to 256 by ABAP Compiler.

Restrict the nesting depth of control structures

Restrict the maximum nesting depth within a procedure (method) to five levels.

In addition to the number of executable statements, the control structures of a procedure (method) are also important for their clarity and traceability. Each new nesting level makes nested branches and loops (such as in the statements IF, CASE, DO, WHILE, and LOOP) increasingly complicated and difficult to interpret. For this reason, the nesting depth must be restricted within a procedure, for example by moving functions to other procedures.

A maximum nesting depth of five levels is considered tolerable. A deeper nesting requires a great deal of effort to trace the program flow based on the source code. This would considerably constrain maintenance and further development.

Note

The use of modern language elements can help to restrict the maximum nesting depth. This is the case if a statement or a built-in function replaces an entire control structure, for instance, for REPLACE with the addition ALL OCCURRENCES or for the numeric extremum functions, nmax( ) and nmin( ), to determine the maximum or minimum value. The former replaces a loop, the latter an IF control structure.

Example

The transition from the bad to the good example in the rule for modern ABAP shows how you can reduce the nesting depth by using modern language elements.






RFUMSV00 - Advance Return for Tax on Sales/Purchases   TXBHW - Original Tax Base Amount in Local Currency  
This documentation is copyright by SAP AG.

Length: 2444 Date: 20240424 Time: 184856     sap01-206 ( 47 ms )