Application Development and Automation 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: 
Read only

Recursive Type Definition

Former Member
0 Likes
1,586

Hello,

how do I define a structured type that has fields of tables of its own type?

I need it to build a tree-structure.

TYPES: BEGIN OF t_node,
  matid TYPE /sapapo/curtowul-matid,
  ingrediences TYPE TABLE OF t_node,
  products TYPE TABLE OF t_node,
END OF t_node.

This does not work because t_node is not known in line 2.

Thanks in advance

best regards

Stefan

5 REPLIES 5
Read only

Former Member
0 Likes
949

Hi,

u should not do like that.what is ur exact requirement.

rgds,

Bharat.

Read only

0 Likes
949

I have a table in APO (/SAPAPO/CURTOWUL) that holds ingrediences for

products that in turn can be iingrediences for other products. I want to retrieve

all products (ant the products needed to make them recursively) for a

given product. The result should be returned in a tree-like (can be a mesh

actually) data-structure. Each node represents a product.

Read only

Former Member
0 Likes
949

Hi,

Try the below code -

DATA: node_table TYPE node_table_type,

node_table1 TYPE node_table_type.

IF g_tree IS INITIAL.

CREATE OBJECT g_tree

EXPORTING

parent = splitter

node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single

EXCEPTIONS

lifetime_error = 1

cntl_system_error = 2

create_error = 3

failed = 4

illegal_node_selection_mode = 5

others = 6

.

wa_event-eventid = cl_gui_simple_tree=>eventid_node_double_click.

wa_event-appl_event = 'X'.

APPEND wa_event TO events.

CALL METHOD g_tree->set_registered_events

EXPORTING

events = events

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

illegal_event_combination = 3

OTHERS = 4

.

PERFORM build_node_table USING node_table.

CALL METHOD g_tree->add_nodes

EXPORTING

table_structure_name = 'MTREESNODE'

node_table = node_table

EXCEPTIONS

error_in_node_table = 1

failed = 2

dp_error = 3

table_structure_name_not_found = 4

OTHERS = 5

.

CALL METHOD splitter->add_control

EXPORTING

row = 1

column = 1

control = g_tree.

ENDIF.

PERFORM create_item_tree USING node_table1.

SET HANDLER g_application->handle_node_double_click FOR g_tree.

&----


*& Form build_node_table

&----


  • text

----


  • -->P_NODE_TABLE text

----


FORM build_node_table USING node_table TYPE node_table_type.

DATA: node LIKE mtreesnode.

node-node_key = 'Sales Order'.

node-isfolder = 'X'.

node-expander = 'X'.

node-text = 'Sales Order'.

APPEND node TO node_table.

LOOP AT t_salordn.

node-node_key = t_salordn-vbeln.

node-relatkey = 'Sales Order'.

node-relatship = cl_gui_simple_tree=>relat_last_child.

node-isfolder = ''.

node-n_image = '@01@'.

node-exp_image = '@01@'.

node-text = t_salordn-vbeln.

APPEND node TO node_table.

ENDLOOP.

ENDFORM. " build_node_table

&----


*& Form create_item_tree

&----


  • text

----


  • -->P_NODE_TABLE1 text

----


FORM create_item_tree USING p_node_table1.

IF g_tree1 IS INITIAL.

CREATE OBJECT g_tree1

EXPORTING

parent = splitter

node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single

.

PERFORM build_node_table1 USING p_node_table1.

CALL METHOD g_tree1->add_nodes

EXPORTING

table_structure_name = 'MTREESNODE'

node_table = p_node_table1

.

CALL METHOD splitter->add_control

EXPORTING

row = 2

column = 1

control = g_tree1.

ENDIF.

IF NOT t_itemno[] IS INITIAL.

DATA: node_item_table LIKE mtreesnode.

CLEAR: node_table1, node_table1[], node_item_table .

LOOP AT t_itemno.

node_item_table-node_key = t_itemno-posnr.

node_item_table-relatkey = 'Item Number'.

node_item_table-relatship = cl_gui_simple_tree=>relat_last_child.

node_item_table-isfolder = ''.

node_item_table-n_image = '@01@'.

node_item_table-exp_image = '@01@'.

node_item_table-text = t_itemno-posnr.

APPEND node_item_table TO node_table1.

ENDLOOP.

CALL METHOD g_tree1->add_nodes

EXPORTING

table_structure_name = 'MTREESNODE'

node_table = node_table1.

ENDIF.

ENDFORM. " create_item_tree***INCLUDE

Hope this helps.

Thanks

Read only

0 Likes
949

Thanks for the answer, but I do not want to display a tree as a control,

I just want a tree-like data-structure.

Read only

0 Likes
949

I know this question is a few years old, but as I was searching for this topic and now found the answer myself here the answer for future seekers:

You can create a deep, tree-like structure during runtime.

Example:

DATA: ls_employee TYPE ty_s_employee.
DATA: ls_component          TYPE        abap_componentdescr.
DATA: lt_components_base    TYPE        abap_component_tab.
DATA: lt_components_deep    TYPE        abap_component_tab.
DATA: lo_structure_descr    TYPE REF TO cl_abap_structdescr.

DATA: lr_data               TYPE REF TO data.

FIELD-SYMBOLS: <ls_data>    TYPE any.


ls_component-name = 'NAME'.
ls_component-type ?= cl_abap_elemdescr=>describe_by_data( ls_employee-name ).
APPEND ls_component TO lt_components_base.
ls_component-name = 'ID'.
ls_component-type ?= cl_abap_elemdescr=>describe_by_data( ls_employee-id ).
APPEND ls_component TO lt_components_base.
lo_structure_descr = cl_abap_structdescr=>create( lt_components_base ).
 
DO 4 TIMES.
   lt_components_deep = lt_components_base.
   ls_component-name = 'MY_BOSS'.
   ls_component-type ?= lo_structure_descr.
   APPEND ls_component TO lt_components_deep.
   lo_structure_descr = cl_abap_structdescr=>create( lt_components_deep ).
ENDDO.

CREATE DATA lr_data TYPE HANDLE lo_structure_descr.
ASSIGN lr_data->* TO <ls_data>.