Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Hierarchical treeview structure in Reports

Former Member
0 Kudos

Hi,

I am working with an MNC, can anybody help me out by valuable guidelines in doing an hierarchical treeview structure in Reports.

Your early response would b helpful to me.

Bye

Pavan

2 REPLIES 2

Former Member
0 Kudos

project manager->project lead->team lead->funcational andtechnical->team member .

Former Member
0 Kudos

HI

see this site you wil find lots of examples

http://www.sapdev.co.uk/reporting/alv/alvtree.htm

The ALV tree report produces uses OBJECT METHOD functionality in-order to produce a

tree structured ALV output.

The creation of an ALVtree report first requires the creation of a simple program to build the ALV

details such as the fieldcatalog and to call a screen which will be used to display the ALVTree.

The screen should be created with a 'custom control' where you wish the ALVtree report to appear.

For the following example it will have the name 'SCREEN_CONTAINER'.

<b>Creation of Main Program code, Data declaration and screen call</b>

&----


*& Report ZDEMO_ALVTREE *

*& *

&----


*& *

*& Example of a simple ALV Grid Report *

*& ................................... *

*& *

*& The basic requirement for this demo is to display a number of *

*& fields from the EKPO and EKKO table in a tree structure. *

*& *

&----


  • Amendment History *

----


REPORT zdemo_alvgrid .

*Data Declaration

*----


TABLES: ekko.

TYPE-POOLS: slis. "ALV Declarations

TYPES: BEGIN OF t_ekko,

ebeln TYPE ekpo-ebeln,

ebelp TYPE ekpo-ebelp,

statu TYPE ekpo-statu,

aedat TYPE ekpo-aedat,

matnr TYPE ekpo-matnr,

menge TYPE ekpo-menge,

meins TYPE ekpo-meins,

netpr TYPE ekpo-netpr,

peinh TYPE ekpo-peinh,

END OF t_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,

it_ekpo TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,

it_emptytab TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,

wa_ekko TYPE t_ekko,

wa_ekpo TYPE t_ekko.

DATA: ok_code like sy-ucomm, "OK-Code

save_ok like sy-ucomm.

*ALV data declarations

DATA: fieldcatalog TYPE lvc_t_fcat WITH HEADER LINE.

DATA: gd_fieldcat TYPE lvc_t_fcat,

gd_tab_group TYPE slis_t_sp_group_alv,

gd_layout TYPE slis_layout_alv.

*ALVtree data declarations

CLASS cl_gui_column_tree DEFINITION LOAD.

CLASS cl_gui_cfw DEFINITION LOAD.

DATA: gd_tree TYPE REF TO cl_gui_alv_tree,

gd_hierarchy_header TYPE treev_hhdr,

gd_report_title TYPE slis_t_listheader,

gd_logo TYPE sdydo_value,

gd_variant TYPE disvariant.

*Create container for alv-tree

DATA: l_tree_container_name(30) TYPE c,

l_custom_container TYPE REF TO cl_gui_custom_container.

************************************************************************

*Includes

*INCLUDE ZDEMO_ALVTREEO01. "Screen PBO Modules

*INCLUDE ZDEMO_ALVTREEI01. "Screen PAI Modules

*INCLUDE ZDEMO_ALVTREEF01. "ABAP Subroutines(FORMS)

************************************************************************

*Start-of-selection.

START-OF-SELECTION.

  • ALVtree setup data

PERFORM data_retrieval.

PERFORM build_fieldcatalog.

PERFORM build_layout.

PERFORM build_hierarchy_header CHANGING gd_hierarchy_header.

PERFORM build_report_title USING gd_report_title gd_logo.

PERFORM build_variant.

  • Display ALVtree report

call screen 100.

&----


*& Form DATA_RETRIEVAL

&----


  • Retrieve data into Internal tables

----


FORM data_retrieval.

SELECT ebeln

UP TO 10 ROWS

FROM ekko

INTO corresponding fields of TABLE it_ekko.

loop at it_ekko into wa_ekko.

SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh

FROM ekpo

appending TABLE it_ekpo

where ebeln eq wa_ekko-ebeln.

endloop.

ENDFORM. " DATA_RETRIEVAL

&----


*& Form BUILD_FIELDCATALOG

&----


  • Build Fieldcatalog for ALV Report

----


FORM build_fieldcatalog.

  • Please not there are a number of differences between the structure of

  • ALVtree fieldcatalogs and ALVgrid fieldcatalogs.

  • For example the field seltext_m is replace by scrtext_m in ALVtree.

fieldcatalog-fieldname = 'EBELN'. "Field name in itab

fieldcatalog-scrtext_m = 'Purchase Order'. "Column text

fieldcatalog-col_pos = 0. "Column position

fieldcatalog-outputlen = 15. "Column width

fieldcatalog-emphasize = 'X'. "Emphasize (X or SPACE)

fieldcatalog-key = 'X'. "Key Field? (X or SPACE)

  • fieldcatalog-do_sum = 'X'. "Sum Column?

  • fieldcatalog-no_zero = 'X'. "Don't display if zero

APPEND fieldcatalog TO gd_fieldcat.

CLEAR fieldcatalog.

fieldcatalog-fieldname = 'EBELP'.

fieldcatalog-scrtext_m = 'PO Iten'.

fieldcatalog-outputlen = 15.

fieldcatalog-col_pos = 1.

APPEND fieldcatalog TO gd_fieldcat..

CLEAR fieldcatalog.

fieldcatalog-fieldname = 'STATU'.

fieldcatalog-scrtext_m = 'Status'.

fieldcatalog-outputlen = 15.

fieldcatalog-col_pos = 2.

APPEND fieldcatalog TO gd_fieldcat..

CLEAR fieldcatalog.

fieldcatalog-fieldname = 'AEDAT'.

fieldcatalog-scrtext_m = 'Item change date'.

fieldcatalog-outputlen = 15.

fieldcatalog-col_pos = 3.

APPEND fieldcatalog TO gd_fieldcat..

CLEAR fieldcatalog.

fieldcatalog-fieldname = 'MATNR'.

fieldcatalog-scrtext_m = 'Material Number'.

fieldcatalog-outputlen = 15.

fieldcatalog-col_pos = 4.

APPEND fieldcatalog TO gd_fieldcat..

CLEAR fieldcatalog.

fieldcatalog-fieldname = 'MENGE'.

fieldcatalog-scrtext_m = 'PO quantity'.

fieldcatalog-outputlen = 15.

fieldcatalog-col_pos = 5.

APPEND fieldcatalog TO gd_fieldcat..

CLEAR fieldcatalog.

fieldcatalog-fieldname = 'MEINS'.

fieldcatalog-scrtext_m = 'Order Unit'.

fieldcatalog-outputlen = 15.

fieldcatalog-col_pos = 6.

APPEND fieldcatalog TO gd_fieldcat..

CLEAR fieldcatalog.

fieldcatalog-fieldname = 'NETPR'.

fieldcatalog-scrtext_m = 'Net Price'.

fieldcatalog-outputlen = 15.

fieldcatalog-col_pos = 7.

fieldcatalog-datatype = 'CURR'.

APPEND fieldcatalog TO gd_fieldcat..

CLEAR fieldcatalog.

fieldcatalog-fieldname = 'PEINH'.

fieldcatalog-scrtext_m = 'Price Unit'.

fieldcatalog-outputlen = 15.

fieldcatalog-col_pos = 8.

APPEND fieldcatalog TO gd_fieldcat..

CLEAR fieldcatalog.

ENDFORM. " BUILD_FIELDCATALOG

&----


*& Form BUILD_LAYOUT

&----


  • Build layout for ALV grid report

----


FORM build_layout.

gd_layout-no_input = 'X'.

gd_layout-colwidth_optimize = 'X'.

gd_layout-totals_text = 'Totals'(201).

  • gd_layout-totals_only = 'X'.

  • gd_layout-f2code = 'DISP'. "Sets fcode for when double

  • "click(press f2)

  • gd_layout-zebra = 'X'.

  • gd_layout-group_change_edit = 'X'.

  • gd_layout-header_text = 'helllllo'.

ENDFORM. " BUILD_LAYOUT

&----


*& Form build_hierarchy_header

&----


  • build hierarchy-header-information

----


  • -->P_L_HIERARCHY_HEADER structure for hierarchy-header

----


FORM build_hierarchy_header CHANGING

p_hierarchy_header TYPE treev_hhdr.

p_hierarchy_header-heading = 'Hierarchy Header'(013).

p_hierarchy_header-tooltip = 'This is the Hierarchy Header !'(014).

p_hierarchy_header-width = 30.

p_hierarchy_header-width_pix = ''.

ENDFORM. " build_hierarchy_header

&----


*& Form BUILD_REPORT_TITLE

&----


  • Build table for ALVtree header

----


  • <-> p1 Header details

  • <-> p2 Logo value

----


FORM build_report_title CHANGING

pt_report_title TYPE slis_t_listheader

pa_logo TYPE sdydo_value.

DATA: ls_line TYPE slis_listheader,

ld_date(10) TYPE c.

  • List Heading Line(TYPE H)

CLEAR ls_line.

ls_line-typ = 'H'.

  • ls_line-key "Not Used For This Type(H)

ls_line-info = 'PO ALVTree Display'.

APPEND ls_line TO pt_report_title.

  • Status Line(TYPE S)

ld_date(2) = sy-datum+6(2).

ld_date+2(1) = '/'.

ld_date3(2) = sy-datum4(2).

ld_date+5(1) = '/'.

ld_date+6(4) = sy-datum(4).

ls_line-typ = 'S'.

ls_line-key = 'Date'.

ls_line-info = ld_date.

APPEND ls_line TO pt_report_title.

  • Action Line(TYPE A)

CLEAR ls_line.

ls_line-typ = 'A'.

CONCATENATE 'Report: ' sy-repid INTO ls_line-info SEPARATED BY space.

APPEND ls_line TO pt_report_title.

ENDFORM.

&----


*& Form BUILD_VARIANT

&----


  • Build variant

----


form build_variant.

  • Set repid for storing variants

gd_variant-report = sy-repid.

endform. " BUILD_VARIANT

<b>Creation of 'INCLUDES' to store ALVtree code</b>

Three includes need to be created in-order to store the ABAP code required for the ALVtree report.

Typically these will be one for the PBO modules, one for PAI modules and one for the subroutines(FORMs):

*Includes

include zdemo_alvtreeo01. "Screen PBO Modules

include zdemo_alvtreei01. "Screen PAI Modules

include zdemo_alvtreef01. "ABAP Subroutines(FORMS)

If you are using the code provide within the ALVtree section of this web site simply create the includes by

un-commenting the 'Includes' section within the code(see below) and double clicking on the name

i.e. 'zdemo_alvtreeo01'. Obviously these can be renamed.

************************************************************************

*Includes

*include zdemo_alvtreeo01. "Screen PBO Modules

*include zdemo_alvtreei01. "Screen PAI Modules

*include zdemo_alvtreef01. "ABAP Subroutines(FORMS)

************************************************************************

*Start-of-selection.

start-of-selection.

<b>Create Screen along with PBO and PAI modules for screen</b>

The next step is to create screen 100, to do this double click on the '100' within the call screen

command(Call screen 100.). Enter short description and select 'Normal' as screen type.

To create the PBO and PAI modules insert that code below into the screen's flow logic. Much of this code

should automatically have been inserted during screen creation but with the module lines commented out.

Simple remove the comments and double click the module name(STATUS_0100 and

USER_COMMAND_0100) in-order to create them, this will display the perform/module creation screen.

The MODULES are usually created within two includes one ending in 'O01' for PBO modules and

one ending in 'I01' for PAI modules(See code below).

Please note in order for these includes to be displayed on the creation screen they need to have be

created along with the following lines of code added to the main prog(see previous step):

INCLUDE ZDEMO_ALVTREEO01. "Screen PBO Modules

INCLUDE ZDEMO_ALVTREEI01. "Screen PAI Modules

Otherwise use the 'New Include' entry and SAP will add the necassary line for you.

  • Screen flow logic code

PROCESS BEFORE OUTPUT.

MODULE STATUS_0100.

*

PROCESS AFTER INPUT.

MODULE USER_COMMAND_0100.

----


***INCLUDE Z......O01 .

----


&----


*& Module STATUS_0100 OUTPUT

&----


  • PBO Module

----


module status_0100 output.

  • SET PF-STATUS 'xxxxxxxx'.

  • SET TITLEBAR 'xxx'.

endmodule. " STATUS_0100 OUTPUT

----


***INCLUDE Z......I01 .

----


&----


*& Module USER_COMMAND_0100 INPUT

&----


  • PAI Module

----


module user_command_0100 input.

endmodule. " USER_COMMAND_0100 INPUT

<b>Define OK CODE(SY-UCOMM) variable</b>

In order to define the OK CODE you must fist declare a variable of type SY-UCOM and then insert this

variable into the OK code declaration within the element list (see screen shot below). If you have used

the code contained on the iwebsite the ok code should already have been declared as OK_CODE.

i.e. OK_CODE like sy-ucom.

Note: there is also a variable called SAVE_OK, it is good practice to store the returned ok code into

a work area as soon as you enter the PAI processing.

<b>Add screen control to PAI module(INCLUDE Z......I01)</b>

The following code adds simple screen control to the report and whenever the user presses the cancel,

exit or back icon they will exit from the report. It also processes the ALVtree user interactions within the

'others' case statement

----


  • INCLUDE Z......I01 *

----


&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


module user_command_0100 input.

DATA return TYPE REF TO cl_gui_event.

save_ok = ok_code.

case ok_code.

when 'BACK' or '%EX' or 'RW'.

  • Exit program

leave to screen 0.

  • Process ALVtree user actions

when others.

call method cl_gui_cfw=>get_current_event_object

receiving

event_object = return.

call method cl_gui_cfw=>dispatch.

endcase.

endmodule. " USER_COMMAND_0100 INPUT

<b>Create pf-status</b>

In order to created the pf-status for the screen you need to un-comment '* SET PF-STATUS 'xxxxxxxx'

and give it a name.

i.e. SET PF-STATUS 'STATUS1'.

Step 1

Now double click on 'STATUS1' in-order to create the pf-status. Enter short text, select status type as

'Online status' and click save.

Step2

You should now be presented with the status creation screen. Choose 'Adjust template' from the Extras menu

(4.6 onwards only).

Step 3

Now select 'List status' and click the green tick (see below).

Step 3

All the basic menu bars/buttons should now have been entered. Now click save then activate. The

pf-status has now been completed.

Once you have the main program code in place to call the screen which will display the

ALVtree, you now need to setup the actual ALVtree and populate it. As this is screen

based(dialog) the display coding will be performed within the PBO screen module.

Therefor you need to add the following processes to the PBO(STATUS_0100) module

of the screen.

<b>Create Custom control</b>

Via screen painter insert 'custom control' on to screen and give it the name 'SCREEN_CONTAINER'. This is

the possition the ALVtree will appear so align appropriately.

http://www.sapdev.co.uk/reporting/alv/alvtree/alvtree_basic.htm

see this site you wil find lots of examples

http://www.sapdev.co.uk/reporting/alv/alvtree.htm

<b>Reward if usefull</b>