61 Flares Twitter 0 Facebook 61 Google+ 0 LinkedIn 0 Email -- Pin It Share 0 61 Flares ×

ALV Tree Report without using OO-ABAP:

Contributed by Garapati Surendra

We can generate the ALV tree  report using Function modules.

Steps to Generate ALV tree using Function Modules

1. Extract requried data that you want to display.

2. Generate the nodes of ALV Tree

3. Call ‘RS_TREE_CONSTRUCT’ Function Module to construct the tree.

4.Call FM ‘RS_TREE_LIST_DISPLAY’

Sample Source Code:

Step 1: Go to SE38 create a program (Program name starts must with Z or Y).

Step 2: Copy and paste the below code in your program.

*&———————————————————————*
*& Report  ZALV_TREE_DISPLAY
*&
*&———————————————————————*
*&
*&
*&———————————————————————*

REPORT ZALV_TREE_DISPLAY.
*//Type Pool declaration
type-POOLS: slis.
*//Types Declaration for VBAK
types:BEGIN OF ty_vbak,
vbeln type vbak-vbeln,
END OF ty_vbak.

*//Types Declaration for VBAP
types:BEGIN OF ty_vbap,
vbeln type vbap-vbeln,
posnr type vbap-posnr,
end of ty_vbap.

*//Types Declaration for VBEP
types:BEGIN OF ty_vbep,
vbeln type vbep-vbeln,
posnr type vbep-posnr,
ETENR type vbep-etenr,
end of ty_vbep.

*//Internal Table and Work Area Declaration
data : it_vbak type table of ty_vbak,
wa_vbak type ty_vbak,
it_vbap type table of ty_vbap,
wa_vbap type ty_vbap,
it_vbep type TABLE OF ty_vbep,
wa_vbep type ty_vbep,
it_node type table of snodetext,
wa_node type snodetext .

START-OF-SELECTION.

select vbeln
from vbak
into table it_vbak
UP TO 50 ROWS.
*//it_vbak is not initial
if it_vbak is NOT INITIAL.
*//Retrive Data from VBAP
select vbeln posnr
from vbap
INTO TABLE it_vbap
FOR ALL ENTRIES IN it_vbak
where vbeln = it_vbak-vbeln.
sort it_vbap by vbeln posnr.
*//If LT_VBAP is not initial
if it_vbap is NOT INITIAL.
*//Retrive Data from VBEP
select vbeln posnr etenr
from vbep
INTO TABLE it_vbep
FOR ALL ENTRIES IN it_vbap
where vbeln = it_vbap-vbeln.
sort it_vbep by vbeln posnr etenr.
endif.
endif.

perform build_tree.
perform display_tree.

*&———————————————————————*
*&      Form  BUILD_TREE
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
form BUILD_TREE .

clear : wa_node, it_node.

wa_node-type = ‘T’.
wa_node-name = ‘SalesData’.
wa_node-tlevel = ’01’.
wa_node-nlength = ’09’.
wa_node-color = ’05’.
wa_node-text = ‘HEADER’.
wa_node-tlength = ’06’.
wa_node-tcolor = ’05’.
append wa_node to it_node.
clear wa_node.

loop at it_vbak into wa_vbak.
wa_node-type = ‘P’.
wa_node-name = ‘VBELN’.
wa_node-tlevel = ’02’.
wa_node-nlength = ’08’.
wa_node-color = ’06’.
wa_node-text = wa_vbak-vbeln.
wa_node-tlength = ’10’.
wa_node-tcolor = ’06’.
append wa_node to it_node.
clear wa_node.

loop at it_vbap into wa_vbap.
if wa_vbak-vbeln = wa_vbap-vbeln.
wa_node-type = ‘P’.
wa_node-name = ‘POSNR’.
wa_node-tlevel = ’03’.
wa_node-nlength = ’08’.
wa_node-color = ’04’.
wa_node-text = wa_vbap-posnr.
wa_node-tlength = ’05’.
wa_node-tcolor = ’04’.
append wa_node to it_node.
clear wa_node.
loop at it_vbep into wa_vbep.
if wa_vbap-vbeln = wa_vbep-vbeln and wa_vbap-posnr = wa_vbep-posnr.
wa_node-type = ‘P’.
wa_node-name = ‘ETENR’.
wa_node-tlevel = ’04’.
wa_node-nlength = ’08’.
wa_node-color = ’04’.
wa_node-text = wa_vbep-etenr.
wa_node-tlength = ’05’.
wa_node-tcolor = ’04’.
append wa_node to it_node.
clear wa_node.
endif.
endloop.
endif.
endloop.
endloop.
endform.                    ” BUILD_TREE
*&———————————————————————*
*&      Form  DISPLAY_TREE
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
form DISPLAY_TREE .
call function ‘RS_TREE_CONSTRUCT’
* EXPORTING
*   INSERT_ID                = ‘000000’
*   RELATIONSHIP             = ‘ ‘
*   LOG                      =
tables
nodetab                  = it_node.
call function ‘RS_TREE_LIST_DISPLAY’
exporting
callback_program                = sy-cprog.
endform.                    ” DISPLAY_TREE

Output:

Save and activate your object and click on execute(F8).

ALV TREE REPORT

 

Click on + symbol to expand the tree structure.

ALV TREE REPORT1

 

That’s it.

Enjoy 🙂

Also Read:

Blocked ALV in SAP ABAP.

Converting and downloading Internal Table data into HTML format.

Dynamic selection screen in SAP ABAP.

61 Flares Twitter 0 Facebook 61 Google+ 0 LinkedIn 0 Email -- Pin It Share 0 61 Flares ×