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: 

ALV tree column - code help

Former Member
0 Kudos

Hi all,

Can any suggest me a code for displaying the below program in alv tree column.

merlin

REPORT Z_MANFIELD.

DATA: d_screen TYPE REF TO cl_dynpro_info.

  • for field list of screen

DATA: ftab TYPE TABLE OF d021s,

wa_ftab TYPE d021s,

pltab TYPE TABLE OF d022s.

  • name of modulpool

DATA: mpool TYPE repid,

mpool2 type repid.

  • for screen attributes of field

DATA: es_screen TYPE screen.

DATA: back TYPE t588m-varky.

DATA: status.

DATA: pos TYPE i.

DATA: p_infty TYPE infty.

DATA: dynnr type dynnr value '2000'.

FIELD-SYMBOLS: <scf>.

TABLES: t588m, pme04,t588d.

constants: calc_molga type molga value ' '.

  • for collection of mandatory fields

DATA: BEGIN OF mf_tab OCCURS 0,

fnam TYPE d021s-fnam,

  • added for distinction of default and T588M

group TYPE char4,

END OF mf_tab.

DATA : BEGIN OF wa,

infty TYPE infty,

END OF wa.

DATA itab LIKE wa OCCURS 0 WITH HEADER LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(12) text-001.

PARAMETER action TYPE t588d-itygr.

SELECTION-SCREEN END OF LINE.

  • for field attributes

START-OF-SELECTION.

SELECT infty INTO CORRESPONDING FIELDS OF TABLE itab FROM t588d WHERE itygr = action.

IF sy-subrc EQ 0.

WRITE : / 'INFOTYPES FOR THIS ACTION TYPE ARE : '.

SORT itab BY infty.

DELETE ADJACENT DUPLICATES FROM itab COMPARING infty.

LOOP AT itab.

WRITE : / itab-infty HOTSPOT COLOR 6 INVERSE ON.

ENDLOOP.

WRITE /.

WRITE : / ' CLICK AN INFOTYPE FOR GETTING ITS MANDATORY FIELDS'.

ELSE.

WRITE : / 'SORRY,NO INFOTYPE FOR THIS ACTION TYPE'.

ENDIF.

AT LINE-SELECTION.

MOVE sy-lisel(6) TO p_infty.

WRITE: / 'INFOTYPE - '.

WRITE : p_infty.

WRITE : /'MANDATORY FIELDS ARE :'.

WRITE : / .

  • build modulpool-name

CREATE OBJECT d_screen.

CONCATENATE 'MP' p_infty '00' INTO mpool2.

CONCATENATE mpool2 '_CE' into mpool.

  • maybe, you have to determin the screen-no first

perform determin_scrno CHANGING dynnr.

SELECT SINGLE * FROM t588m WHERE repna = mpool

AND dynnr = dynnr

AND varky = calc_molga.

IF sy-subrc NE 0. "not found -> switch to default MOLGA

SELECT SINGLE * FROM t588m WHERE repna LIKE mpool

AND dynnr = dynnr

AND varky = space.

IF sy-subrc NE 0. "still not there -> fall back to dflt modulpool with MOLGA

mpool = mpool2.

SELECT SINGLE * FROM t588m WHERE repna = mpool

AND dynnr = dynnr

AND varky = calc_molga.

IF sy-subrc ne 0. "Last try -> dflt modulpool + empty MOLGA

SELECT SINGLE * FROM t588m WHERE repna LIKE mpool

AND dynnr = dynnr

AND varky = space.

IF sy-subrc ne 0. "obviously, there isn't ana entry at all

clear t588m.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

  • This part really depends on your

  • settings of feature Pnnnn

  • in your case (varkey = MOLGA) we will skip it (l.a.)

  • IF t588m-zykls NE space.

  • SELECT SINGLE bukrs werks btrtl persg persk

  • FROM pa0001

  • INTO pme04 WHERE

  • begda LE sy-datum

  • AND endda GE sy-datum

  • AND sprps EQ space.

*

  • PERFORM re549d USING t588m-zykls space back status.

*

  • IF NOT back IS INITIAL.

  • SELECT SINGLE * FROM t588m

  • WHERE repna = mpool

  • AND dynnr = '2000'

  • AND varky = back.

  • IF sy-subrc NE 0.

  • CLEAR t588m.

  • ENDIF.

  • ENDIF.

*

  • ENDIF.

  • only to ensure that these fields are filled

IF t588m IS INITIAL.

t588m-repna = mpool.

t588m-dynnr = dynnr.

ENDIF.

  • get fieldlist for screen

CALL FUNCTION 'RS_IMPORT_DYNPRO'

EXPORTING

dylang = sy-langu

dyname = t588m-repna

dynumb = t588m-dynnr

request = ' '

suppress_checks = ' '

  • IMPORTING

  • HEADER =

TABLES

ftab = ftab

pltab = pltab

EXCEPTIONS

button_error = 1

dylanguage_invalid = 2

dylanguage_not_inst = 3

dyname_invalid = 4

dynproload_not_found = 5

dynpro_old = 6

dynumb_invalid = 7

ftab_invalid = 8

gen_error = 9

gen_ok = 10

header_invalid = 11

internal_error = 12

no_dynpro = 13

no_ftab_row = 14

no_memory = 15

no_processlogic = 16

pltab_invalid = 17

request_invalid = 18

OTHERS = 19

.

IF sy-subrc EQ 0.

  • error handling

ENDIF.

  • get rid of comments, frames and the like

DELETE ftab WHERE aglt IS INITIAL.

LOOP AT ftab INTO wa_ftab.

  • Screen-Grp3 is the key to T588M-DBILD

IF wa_ftab-grp3 NE space.

pos = wa_ftab-grp3 - 1.

ASSIGN t588m-dbild+pos(1) TO <scf>.

  • mandatory fields are marked '+'

IF <scf> EQ '+'.

  • APPEND wa_ftab-grp3 to mf_tab.

  • changed to

MOVE wa_ftab-fnam TO mf_tab-fnam.

MOVE wa_ftab-grp3 TO mf_tab-group.

APPEND mf_tab.

CONTINUE.

ENDIF.

ENDIF.

  • maybe the field is mandatory by default

CALL METHOD d_screen->get_screen_field_attr

EXPORTING

iv_repid = t588m-repna

iv_dynnr = t588m-dynnr

iv_field = wa_ftab-fnam

IMPORTING

es_screen = es_screen

EXCEPTIONS

exc_insufficient_parameters = 1

exc_no_attributes = 2

OTHERS = 3.

IF sy-subrc EQ 0.

  • error handling

ENDIF.

IF es_screen-required NE space.

  • append wa_ftab-grp3 to mf_tab.

  • changed to

MOVE wa_ftab-fnam TO mf_tab-fnam.

MOVE 'Dflt' TO mf_tab-group.

APPEND mf_tab.

ENDIF.

ENDLOOP.

  • simple output

LOOP AT mf_tab.

WRITE: / mf_tab-fnam,

  • added

mf_tab-group.

ENDLOOP.

  • added

CLEAR: mf_tab, mf_tab[].

END-OF-SELECTION.

  • INCLUDE rpumkc00. "without evaluation of feature, it's not necessary

&----


*& Form determin_scrno

&----


  • do some terribly tricky stuff to get to know the screen no

----


  • <--P_DYNNR text

----


form determin_scrno changing p_dynnr.

  • do, what ever has to be done here

endform. " determin_scrno

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

I have displayed my ALV Tree using OOPS

PFB The code Proceed step by step , Firstly pull all your data in one internal table

form alv_hierarchy_display .

try.

cl_salv_tree=>factory(

importing

r_salv_tree = ob_tree

changing

t_table = pass ur internal table ).

catch cx_salv_error.

message e003.

endtry.

  • Build the Tree structure for display in Hierarchial List.

perform supply_data using( pass ur internal table ).

*

  • include own functions by setting own status

ob_tree->set_screen_status(

pfstatus = '100'

report = sy-repid

set_functions = ob_tree->c_functions_all ).

*

  • set the columns technical

ob_columns = ob_tree->get_columns( ).

ob_columns->set_optimize( abap_true ).

*

  • Setting the Columns Technical and Using in ALV Columns

perform set_columns_technical using ob_columns.

*

  • display the table

ob_tree->display( ).

endform. " alv_hierarchy_display

&----


*& Form supply_data

&----


  • text

----


  • -->P_IT_FT_LIST text

----


form supply_data using p_it_ft_list type standard table.

  • SORT p_itab_empdetails by oprtuntdesc deptuntdesc orgunit.

loop at p_it_ft_list into wa_ft_list.

on change of wa_ft_list-oprtunit.

perform add_optunit_line using wa_ft_list

''

changing v_optunit_key.

endon.

on change of wa_ft_list-deptunit.

perform add_deptunit_line using wa_ft_list

v_optunit_key

changing v_deptunit_key.

endon.

on change of wa_ft_list-orgeh.

perform add_orgeh_line using wa_ft_list

v_deptunit_key

changing v_orgunit.

endon.

perform add_last_line using wa_ft_list

v_orgunit

changing v_last_key.

endloop.

endform. " supply_data

&----


*& Form add_optunit_line

&----


  • text

----


  • -->P_WA_FT_LIST text

  • -->P_1165 text

  • <--P_V_OPTUNIT_KEY text

----


form add_optunit_line using p_wa_ft_list type ty_ft_list

p_key type lvc_nkey

changing p_l_optunit_key type lvc_nkey.

data : wa_ft_list1 type ty_ft_list.

  • working with nodes

ob_nodes = ob_tree->get_nodes( ).

  • Moving the Emp Details of the Operating Unit Desc to the WorkArea

move p_wa_ft_list-oprtunit to wa_ft_list1-oprtunit.

move p_wa_ft_list-oprtuntdesc to wa_ft_list1-oprtuntdesc.

try.

  • add a new node

  • set the data for the nes node

ob_node = ob_nodes->add_node( related_node = p_key

data_row = wa_ft_list1

relationship =

cl_gui_column_tree=>relat_last_child ).

ob_node->set_text( text-018 ).

p_l_optunit_key = ob_node->get_key( ).

catch cx_salv_msg.

message e003.

endtry.

endform. " add_optunit_line

&----


*& Form add_deptunit_line

&----


  • text

----


  • -->P_WA_FT_LIST text

  • -->P_V_OPTUNIT_KEY text

  • <--P_V_DEPTUNIT_KEY text

----


form add_deptunit_line using p_wa_ft_list type ty_ft_list

p_l_orgeh type lvc_nkey

changing p_l_deptunit_key type lvc_nkey.

data : wa_ft_list2 type ty_ft_list.

  • working with nodes

ob_nodes = ob_tree->get_nodes( ).

  • Moving the Emp Details of the Dept Unit Desc to the WorkArea

move p_wa_ft_list-deptunit to wa_ft_list2-deptunit.

move p_wa_ft_list-deptuntdesc to wa_ft_list2-deptuntdesc.

try.

ob_node = ob_nodes->add_node( related_node = p_l_orgeh

data_row = wa_ft_list2

relationship =

cl_gui_column_tree=>relat_last_child ).

ob_node->set_text( text-005 ).

p_l_deptunit_key = ob_node->get_key( ).

catch cx_salv_msg.

message e003.

endtry.

endform. " add_deptunit_line

&----


*& Form add_orgeh_line

&----


  • text

----


  • -->P_WA_FT_LIST text

  • -->P_V_DEPTUNIT_KEY text

  • <--P_V_ORGUNIT text

----


form add_orgeh_line using p_wa_ft_list type ty_ft_list

p_key type lvc_nkey

changing p_l_orgeh type lvc_nkey.

data : wa_ft_list3 type ty_ft_list.

  • working with nodes

ob_nodes = ob_tree->get_nodes( ).

  • Moving the Work Area Details to Local WorkArea3

move p_wa_ft_list-orgeh to wa_ft_list3-orgeh.

move p_wa_ft_list-orgindeptdesc to wa_ft_list3-orgindeptdesc.

try.

  • add a new node

  • set the data for the nes node

ob_node = ob_nodes->add_node( related_node = p_key

data_row = wa_ft_list3

relationship =

cl_gui_column_tree=>relat_last_child ).

ob_node->set_text( text-004 ).

p_l_orgeh = ob_node->get_key( ).

catch cx_salv_msg.

message e003.

endtry.

endform. " add_orgeh_line

&----


*& Form add_last_line

&----


  • text

----


  • -->P_WA_FT_LIST text

  • -->P_V_ORGUNIT text

  • <--P_V_LAST_KEY text

----


form add_last_line using value(p_wa_ft_list) type ty_ft_list

value(p_l_optunit_key) type lvc_nkey

changing p_l_last_key type lvc_nkey.

  • working with nodes

ob_nodes = ob_tree->get_nodes( ).

clear: p_wa_ft_list-orgeh, " Clearing WorkArea

p_wa_ft_list-orgindeptdesc,

p_wa_ft_list-deptuntdesc,

p_wa_ft_list-oprtuntdesc,

p_wa_ft_list-deptunit,

p_wa_ft_list-oprtunit.

try.

ob_node = ob_nodes->add_node( related_node = p_l_optunit_key

data_row = p_wa_ft_list

relationship =

cl_gui_column_tree=>relat_last_child

).

p_l_last_key = ob_node->get_key( ).

catch cx_salv_msg.

message e003.

endtry.

endform.

Reward Points if helpful

Hitesh

2 REPLIES 2

Former Member
0 Kudos

Hi

I have displayed my ALV Tree using OOPS

PFB The code Proceed step by step , Firstly pull all your data in one internal table

form alv_hierarchy_display .

try.

cl_salv_tree=>factory(

importing

r_salv_tree = ob_tree

changing

t_table = pass ur internal table ).

catch cx_salv_error.

message e003.

endtry.

  • Build the Tree structure for display in Hierarchial List.

perform supply_data using( pass ur internal table ).

*

  • include own functions by setting own status

ob_tree->set_screen_status(

pfstatus = '100'

report = sy-repid

set_functions = ob_tree->c_functions_all ).

*

  • set the columns technical

ob_columns = ob_tree->get_columns( ).

ob_columns->set_optimize( abap_true ).

*

  • Setting the Columns Technical and Using in ALV Columns

perform set_columns_technical using ob_columns.

*

  • display the table

ob_tree->display( ).

endform. " alv_hierarchy_display

&----


*& Form supply_data

&----


  • text

----


  • -->P_IT_FT_LIST text

----


form supply_data using p_it_ft_list type standard table.

  • SORT p_itab_empdetails by oprtuntdesc deptuntdesc orgunit.

loop at p_it_ft_list into wa_ft_list.

on change of wa_ft_list-oprtunit.

perform add_optunit_line using wa_ft_list

''

changing v_optunit_key.

endon.

on change of wa_ft_list-deptunit.

perform add_deptunit_line using wa_ft_list

v_optunit_key

changing v_deptunit_key.

endon.

on change of wa_ft_list-orgeh.

perform add_orgeh_line using wa_ft_list

v_deptunit_key

changing v_orgunit.

endon.

perform add_last_line using wa_ft_list

v_orgunit

changing v_last_key.

endloop.

endform. " supply_data

&----


*& Form add_optunit_line

&----


  • text

----


  • -->P_WA_FT_LIST text

  • -->P_1165 text

  • <--P_V_OPTUNIT_KEY text

----


form add_optunit_line using p_wa_ft_list type ty_ft_list

p_key type lvc_nkey

changing p_l_optunit_key type lvc_nkey.

data : wa_ft_list1 type ty_ft_list.

  • working with nodes

ob_nodes = ob_tree->get_nodes( ).

  • Moving the Emp Details of the Operating Unit Desc to the WorkArea

move p_wa_ft_list-oprtunit to wa_ft_list1-oprtunit.

move p_wa_ft_list-oprtuntdesc to wa_ft_list1-oprtuntdesc.

try.

  • add a new node

  • set the data for the nes node

ob_node = ob_nodes->add_node( related_node = p_key

data_row = wa_ft_list1

relationship =

cl_gui_column_tree=>relat_last_child ).

ob_node->set_text( text-018 ).

p_l_optunit_key = ob_node->get_key( ).

catch cx_salv_msg.

message e003.

endtry.

endform. " add_optunit_line

&----


*& Form add_deptunit_line

&----


  • text

----


  • -->P_WA_FT_LIST text

  • -->P_V_OPTUNIT_KEY text

  • <--P_V_DEPTUNIT_KEY text

----


form add_deptunit_line using p_wa_ft_list type ty_ft_list

p_l_orgeh type lvc_nkey

changing p_l_deptunit_key type lvc_nkey.

data : wa_ft_list2 type ty_ft_list.

  • working with nodes

ob_nodes = ob_tree->get_nodes( ).

  • Moving the Emp Details of the Dept Unit Desc to the WorkArea

move p_wa_ft_list-deptunit to wa_ft_list2-deptunit.

move p_wa_ft_list-deptuntdesc to wa_ft_list2-deptuntdesc.

try.

ob_node = ob_nodes->add_node( related_node = p_l_orgeh

data_row = wa_ft_list2

relationship =

cl_gui_column_tree=>relat_last_child ).

ob_node->set_text( text-005 ).

p_l_deptunit_key = ob_node->get_key( ).

catch cx_salv_msg.

message e003.

endtry.

endform. " add_deptunit_line

&----


*& Form add_orgeh_line

&----


  • text

----


  • -->P_WA_FT_LIST text

  • -->P_V_DEPTUNIT_KEY text

  • <--P_V_ORGUNIT text

----


form add_orgeh_line using p_wa_ft_list type ty_ft_list

p_key type lvc_nkey

changing p_l_orgeh type lvc_nkey.

data : wa_ft_list3 type ty_ft_list.

  • working with nodes

ob_nodes = ob_tree->get_nodes( ).

  • Moving the Work Area Details to Local WorkArea3

move p_wa_ft_list-orgeh to wa_ft_list3-orgeh.

move p_wa_ft_list-orgindeptdesc to wa_ft_list3-orgindeptdesc.

try.

  • add a new node

  • set the data for the nes node

ob_node = ob_nodes->add_node( related_node = p_key

data_row = wa_ft_list3

relationship =

cl_gui_column_tree=>relat_last_child ).

ob_node->set_text( text-004 ).

p_l_orgeh = ob_node->get_key( ).

catch cx_salv_msg.

message e003.

endtry.

endform. " add_orgeh_line

&----


*& Form add_last_line

&----


  • text

----


  • -->P_WA_FT_LIST text

  • -->P_V_ORGUNIT text

  • <--P_V_LAST_KEY text

----


form add_last_line using value(p_wa_ft_list) type ty_ft_list

value(p_l_optunit_key) type lvc_nkey

changing p_l_last_key type lvc_nkey.

  • working with nodes

ob_nodes = ob_tree->get_nodes( ).

clear: p_wa_ft_list-orgeh, " Clearing WorkArea

p_wa_ft_list-orgindeptdesc,

p_wa_ft_list-deptuntdesc,

p_wa_ft_list-oprtuntdesc,

p_wa_ft_list-deptunit,

p_wa_ft_list-oprtunit.

try.

ob_node = ob_nodes->add_node( related_node = p_l_optunit_key

data_row = p_wa_ft_list

relationship =

cl_gui_column_tree=>relat_last_child

).

p_l_last_key = ob_node->get_key( ).

catch cx_salv_msg.

message e003.

endtry.

endform.

Reward Points if helpful

Hitesh

mnicolai_77
Active Participant
0 Kudos

hi,

to convert your program into an alv tree take a look to BCALV_TREE_DEMO program.

In the form create_hierarchy insert the code that you have in the start-of-selection event and then register the event EXPAND_NO_CHILDREN. in the implement this method with the code that you have in the AT Line-Selection EVENT.

Bye.

Marco