Purpose
Demo ZCL_XTT_DEMO_051 selects different row layouts for nodes at the same hierarchy level. This is useful when one company code needs a special header, a node must disappear entirely, or the same rule must work outside Excel.
In the grouped-tree example, level=1 can already be split into:
- {R-T;level=1;top=X} upper &
- {R-T;level=1;top=} bottom
blocks ?
Conditional formatting can change appearance in Excel, but it cannot select a structurally different header, merge a different range, or provide the same behavior in Word and PDF.
Programmatic approach
The older approach handled ON_TREE_CHANGE_LEVEL and replaced level 1 with a synthetic template level such as 55, 66, or 77.

You could just create levels 55, 66 or 77 in the template (Any fairly large level that will certainly not be displayed)

and in the event handler change IV_LEVEL_INDEX->* with desired level. If you assign a value that is not in the pattern (-1), then the level would simply disappear.

This works, but the layout rules become invisible to the template designer and can only be understood by reading ABAP code.
Declarative approach
Use show_if and hide_if to keep the selection rule in the template.
The alternatives behave like a CASE statement. If no condition matches, an unqualified block for that level acts as WHEN OTHERS. If no default block exists, the level is omitted. An explicit hide_if is generally easier to understand than relying on omission.

Inside the condition, row refers to the current tree row. Conditions are case-insensitive and accept normal ABAP comparison operators, including EQ, NE, GT, LT, CP, NP, CO, CN, CA, NA, CS, and NS.
The example selects these level=1 layouts:
- C - Yellow
- B - Consisting of 2 vertically merged cells
- A - Default
- D - Hidden

Combining the directives
level, top, show_if, and hide_if can be combined independently. With level alone, the subtotal row appears below its children. show_if and hide_if also work without an explicit level: call TREE_CREATE( iv_fields = '' ) to create a level-0 tree and apply conditional output to each row.