xtt->MERGE( IV_BLOCK_NAME = ‘R’ IS_BLOCK =
{"TITLE"=>"Title", "T"=>[{"GROUP"=>"GRP A", "CAPTION"=>"<Caption 1 />", "DATE"=>"2020-10-21", "SUM1"=>5971.44, "SUM2"=>5021.46}, {"GROUP"=>"GRP C", "CAPTION"=>"<Caption 2 />", "DATE"=>"2020-10-19", "SUM1"=>2276.75, "SUM2"=>7717.2}, {"GROUP"=>"GRP B", "CAPTION"=>"<Caption 3 />", "DATE"=>"2020-10-20", "SUM1"=>3031.38, "SUM2"=>445.22}, {"GROUP"=>"GRP A", "CAPTION"=>"<Caption 4 />", "DATE"=>"2020-10-21", "SUM1"=>9476.79, "SUM2"=>3683.27}, {"GROUP"=>"GRP A", "CAPTION"=>"<Caption 5 />", "DATE"=>"2020-10-21", "SUM1"=>4604.0, "SUM2"=>5525.85}, {"GROUP"=>"GRP C", "CAPTION"=>"<Caption 6 />", "DATE"=>"2020-10-19", "SUM1"=>2159.71, "SUM2"=>2260.94}, {"GROUP"=>"GRP B", "CAPTION"=>"<Caption 7 />", "DATE"=>"2020-10-20", "SUM1"=>2490.3, "SUM2"=>6388.81}, {"GROUP"=>"GRP A", "CAPTION"=>"<Caption 8 />", "DATE"=>"2020-10-21", "SUM1"=>5476.81, "SUM2"=>406.18}, {"GROUP"=>"GRP D", "CAPTION"=>"<Caption 9 />", "DATE"=>"2020-10-18", "SUM1"=>689.66, "SUM2"=>518.6}, {"GROUP"=>"GRP C", "CAPTION"=>"<Caption 10 />", "DATE"=>"2020-10-19", "SUM1"=>5451.87, "SUM2"=>4061.85}, {"GROUP"=>"GRP D", "CAPTION"=>"<Caption 11 />", "DATE"=>"2020-10-18", "SUM1"=>4573.55, "SUM2"=>5436.0}, {"GROUP"=>"GRP C", "CAPTION"=>"<Caption 12 />", "DATE"=>"2020-10-19", "SUM1"=>1196.35, "SUM2"=>522.46}, {"GROUP"=>"GRP C", "CAPTION"=>"<Caption 13 />", "DATE"=>"2020-10-19", "SUM1"=>7686.95, "SUM2"=>2727.98}, {"GROUP"=>"GRP D", "CAPTION"=>"<Caption 14 />", "DATE"=>"2020-10-18", "SUM1"=>978.18, "SUM2"=>295.55}, {"GROUP"=>"GRP D", "CAPTION"=>"<Caption 15 />", "DATE"=>"2020-10-18", "SUM1"=>71.12, "SUM2"=>8878.56}]}
).
What if in the previous example at the level {R-T;level=1} it would not be enough to divide the tree by:
- {R-T;level=1;top=X} upper &
- {R-T;level=1;top=} bottom
blocks ?
Sometimes it is necessary to show special HEADER for a certain BUKRS. In Excel, you can use conditional formatting.
But what if you need to merge several cells in the header or hide the header completely or do it in Word or Pdf?
ABAP approach
Previously, this could be achieved using the special method ZCL_XTT_REPLACE_BLOCK=
>ON_TREE_CHANGE_LEVEL in which it was possible to replace level 1 with another one.
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.
But this approach has a significant drawback. In order to understand how the final template will look like, you need to go to the ABAP code editor and see these conditions.
Declarative approach
For the readability of the template 2 additions:
- show_if &
- hide_if
was introduced.
They work like the CASE statement.
If all conditions are false, the default block WHEN OTHERS will work for the given level. Which could be omitted and would not be displayed in the final report (But explicitly stated hide_if is preferable)
In the example below, line 6 works like WHEN OTHERS
To indicate the current level the row keyword has been introduced(Case insensitive, like any ABAP code). You can write any ABAP condition. For example, except for mathematical conditions like =, <>,> =, <= their analogues EQ, NE, GT, LT can be used. (CP, NP, CO, CN, CA, NA, CS, NS are also acceptable)
As a result, each level {R-T;level=1} has its own title:
- C - Yellow
- B - Consisting of 2 vertically merged cells
- A - Default
- D - Hidden
Combining level, top, show_if, hide_if
Any combination is permissible. Conditions can be set or omitted at any level.
If you use only level (without top, show_if, hide_if) the subtotals will be displayed below each level (top=abap_false and no conditions for output).
show_if and hide_if additions can be used without any level or top. You can call zcl_xtt_replace_block=>tree_create(iv_fields = ‘’). The table is converted to a tree with levels=0, and for each level you can set your conditional output