Video 9: ABAP for ALL - OO ALV Tree Structure

preview_player
Показать описание
Explained the way to understand the ALV tree structure design.

Program Code: (Angle brackets removed, please add it after copy paste the code)

TYPES: BEGIN OF stu_porders,
aufnr TYPE aufnr,
aufpl TYPE co_aufpl,
vornr TYPE vornr,
END OF stu_porders.

DATA: it_data TYPE TABLE OF stu_porders,
it_data_tree type TABLE OF stu_porders.

DATA: obj_tree TYPE REF TO cl_salv_tree,
obj_nodes TYPE REF TO cl_salv_nodes,
obj_node TYPE REF TO cl_salv_node,
obj_settings TYPE REF TO cl_salv_tree_settings.

* Step 1 - get ref. obj_tree

TRY.
CALL METHOD cl_salv_tree=factory
IMPORTING
r_salv_tree = obj_tree
CHANGING
t_table = it_data.
CATCH cx_salv_error .
ENDTRY.

*Step 2 - Header Settings
obj_settings = obj_tree-get_tree_settings( ).

obj_settings-set_header( 'ALV Tree Samples' ).
obj_settings-set_hierarchy_header( 'Order Hir' ).
obj_settings-set_hierarchy_tooltip( 'Test' ).
obj_settings-set_hierarchy_size( 20 ).

* Step 3 - read the nodes
obj_nodes = obj_tree-get_nodes( ).
if 1 = 2.

* Step 4 - data to ALV trees
DO 5 TIMES.

obj_node = obj_nodes-add_node( related_node = ' '
text = 'Parent 1'
relationship = ' ' ).

data(lv_parent_key) = obj_node-get_key( ).

obj_node = obj_nodes-add_node( related_node = lv_parent_key
text = 'Child 1'
relationship = cl_gui_column_tree=relat_first_child ).

data(lv_child_key) = obj_node-get_key( ).

obj_node = obj_nodes-add_node( related_node = lv_child_key
text = 'Child 1A'
relationship = cl_gui_column_tree=relat_first_sibling ).

ENDDO.
ENDIF.

Select aufnr afko~aufpl vornr from afko INNER JOIN afvc
on afko~aufpl = afvc~aufpl
into table it_data_tree UP TO 100 rows.

data lv_text type lvc_value.

LOOP AT it_data_tree into data(wa_data).

CONCATENATE 'Order Number' wa_data-aufnr into lv_text SEPARATED BY space.

on CHANGE OF wa_data-aufnr.
obj_node = obj_nodes-add_node( related_node = ' '
text = lv_text
* data_row = wa_data
relationship = ' ' ).

data(lv_order_key) = obj_node-get_key( ).
endon.

on CHANGE OF wa_data-aufpl.
CONCATENATE 'Activity' wa_data-aufpl into lv_text SEPARATED BY space.
obj_node = obj_nodes-add_node( related_node = lv_order_key
text = lv_text
data_row = wa_data
relationship = cl_gui_column_tree=relat_first_child ).
data(lv_activity_key) = obj_node-get_key( ).
endon.

CONCATENATE 'Operations' wa_data-vornr into lv_text SEPARATED BY space.
obj_node = obj_nodes-add_node( related_node = lv_activity_key
text = lv_text
data_row = wa_data
relationship = cl_gui_column_tree=relat_first_child ).

ENDLOOP.

* Step 5 - display the tree
obj_tree-display( ).
Рекомендации по теме
Комментарии
Автор

Very helpful and hands on training, keep it up for RAP Model CAP Model as well

SNSBackup
Автор

This was simple program but explains concept perfectly.

nehadelphin
Автор

Hi Sir, for example if we have multiple parent node, for each parent node can we have different field. Please help to provide any reference for the same if we can have this type of data. need your help to understand this

thanks

poojabenakatti
Автор

Hi sir, can you provide me to add functionality to download the data to execl

shanthkumarc.h
Автор

we are using get tree list to get detail list when we click tree list first then data is getting into the display properly and node_key also clearing properly, but when we click on tree again again at that time node_key is not clearing properley please help me clear the existing node_key...

sivasai
Автор

Hello sir, can you please upload an video on dynamic alv noboday has done that. Maybe I am using the term dynamic alv is wrong so telling you what I am expecting and please correct me.

I have requirement where I want to show the data based on month of fiscal year. When the user enter the Month July 2020 it should show the data from month July to next fiscal year so here the month is not fixed at all the user can enter any month as per his/her choice. I just wanted to understand how to make field catalogue or alv in for such requirement. Please try to upload it as soon as possible.
Thank you very much for all of you hard work that you doing for all of us.

GauravSingh-lzmb
Автор

Do you have any video related to the Dockig Container ??

pushpajha
Автор

Hi, Thanks for the wonderful session. Can you please tell me how we can add the top of page in cl_salv_tree class

ronarona
Автор

Hi can you explain in module pool
Tabstrip-> select all, select block and deselect all
How it is work
Please

naveenrock
Автор

Hey, can you help me. I followed your steps and wanted to try something myself:
DATA: it_data2 TYPE TABLE OF mara.
DATA: it_data_tree2 TYPE TABLE OF mara.
....
.... kinda your code, but without stu_porders
....
SELECT * FROM mara INTO TABLE it_data_tree2.
LOOP AT it_data_tree2 INTO DATA(wa_data).
TRY.
obj_node = obj_nodes->add_node(
related_node = ' '
relationship = ' '
data_row = wa_data
).
CATCH cx_salv_msg.
ENDTRY.
ENDLOOP.

After executing, I am getting an exception dump: "COLUMN_NOT_FOUND"

METHOD COLUMN_SET_WIDTH .

DATA: COLUMN TYPE TREEV_CINF,
HEADER_NAME TYPE TV_HDRNA

* check if control is alive
if h_control is initial.
message A003(TREE_CONTROL_MSG
endif.

READ TABLE COLUMNS
WITH KEY
NAME = COLUMN_NAME
INTO COLUMN
BINARY SEARCH.
IF SY-SUBRC <> 0.
RAISE COLUMN_NOT_FOUND.
ENDIF.
IF NOT COLUMN-H_COL IS INITIAL.
RAISE HIERARCHY_COLUMN.
ENDIF.

HEADER_NAME = COLUMN_NAME.

Do I get it, because I didn't define my structure?
Thank you in advance.

jinzala