2015 Oct 12 9:17 AM
Hello ABAP Guru's,
I need One logic to delete entries from the dynamic Internal Table .
<fl_tab> is my Internal table - It is Dynamic Internal Table (This Example I have taken 4 Nodes but it may come more than 99 ...n )
Note:Node1,Node2......Node n (It may come any number od nodes)
| Node1 | Node2 | Node3 | Node4 |
|---|---|---|---|
| Asserts | |||
| Asserts | A-Current | ||
| Asserts | A-Current | A-Current1 | |
| Asserts | A-Current | A-Current1 | A-Current1.1 |
| Asserts | A-Current | A-Current1 | A-Current1.2 |
| Asserts | A-Current | A-Current2 | |
| Asserts | A-Current | A-Current2 | A-Current2.1 |
| Asserts | A-Current | A-Current2 | A-Current2.2 |
| Asserts | A-Noncurrent | ||
| Asserts | A-Noncurrent | A-NonCurrent1 | |
| Asserts | A-Noncurrent | A-NonCurrent1 | A-NonCurrent1.1 |
| Asserts | A-Noncurrent | A-NonCurrent1 | A-NonCurrent1.2 |
| Asserts | A-Noncurrent | A-NonCurrent3 |
Finally I want My Internal Table like below.
| Node1 | Node2 | Node3 | Node4 |
|---|---|---|---|
| Asserts | A-Current | A-Current1 | A-Current1.1 |
| Asserts | A-Current | A-Current1 | A-Current1.2 |
| Asserts | A-Current | A-Current2 | A-Current2.1 |
| Asserts | A-Current | A-Current2 | A-Current2.2 |
| Asserts | A-Noncurrent | A-NonCurrent1 | A-NonCurrent1.1 |
| Asserts | A-Noncurrent | A-NonCurrent1 | A-NonCurrent1.2 |
| Asserts | A-Noncurrent | A-NonCurrent3 |
Explanation - Asserts is Main node Under there will be n number of sub nodes.
In our case Asserts ----------------------- is Leve1
A-current ,A-Non Current is Level2 (Under Asserts)
A-Current 1.1,Acurrent1.2 is Level 3(Under A-current)
etc for other records as well
Finally I want to see all the Levels in one row ---Like below (From above explanation - I have to dig for till last Level of the Node) .
| Node1 | Node2 | Node3 | Node4 |
|---|---|---|---|
| Asserts | A-Current | A-Current1 | A-Current1.1 |
| Asserts | A-Current | A-Current1 | A-Current1.2 |
Kindly consider below -
1. Don't Apply Sort technique - If apply All the Index will done.
2.This is dynamic Internal table so we can't hard code any thing ( only filed symbols will work) .
3.I know how many Nodes will come from the another FM (Here it came 4Nodes (again this is dynamic it may come 99..n))
I am trying from past 3 days to frame the logic.
Thanks In advance,
Kandulas.
Hello ABAP Guru's,
I need One logic to delete entries from the dynamic Internal Table .
<fl_tab> is my Internal table - It is Dynamic Internal Table (This Example I have taken 4 Nodes but it may come more than 99 ...n )
Note:Node1,Node2......Node n (It may come any number od nodes)
| Node1 | Node2 | Node3 | Node4 |
|---|---|---|---|
| Asserts | |||
| Asserts | A-Current | ||
| Asserts | A-Current | A-Current1 | |
| Asserts | A-Current | A-Current1 | A-Current1.1 |
| Asserts | A-Current | A-Current1 | A-Current1.2 |
| Asserts | A-Current | A-Current2 | |
| Asserts | A-Current | A-Current2 | A-Current2.1 |
| Asserts | A-Current | A-Current2 | A-Current2.2 |
| Asserts | A-Noncurrent | ||
| Asserts | A-Noncurrent | A-NonCurrent1 | |
| Asserts | A-Noncurrent | A-NonCurrent1 | A-NonCurrent1.1 |
| Asserts | A-Noncurrent | A-NonCurrent1 | A-NonCurrent1.2 |
| Asserts | A-Noncurrent | A-NonCurrent3 |
Finally I want My Internal Table like below.
| Node1 | Node2 | Node3 | Node4 |
|---|---|---|---|
| Asserts | A-Current | A-Current1 | A-Current1.1 |
| Asserts | A-Current | A-Current1 | A-Current1.2 |
| Asserts | A-Current | A-Current2 | A-Current2.1 |
| Asserts | A-Current | A-Current2 | A-Current2.2 |
| Asserts | A-Noncurrent | A-NonCurrent1 | A-NonCurrent1.1 |
| Asserts | A-Noncurrent | A-NonCurrent1 | A-NonCurrent1.2 |
| Asserts | A-Noncurrent | A-NonCurrent3 |
Explanation - Asserts is Main node Under there will be n number of sub nodes.
In our case Asserts ----------------------- is Leve1
A-current ,A-Non Current is Level2 (Under Asserts)
A-Current 1.1,Acurrent1.2 is Level 3(Under A-current)
etc for other records as well
Finally I want to see all the Levels in one row ---Like below (From above explanation - I have to dig for till last Level of the Node) .
| Node1 | Node2 | Node3 | Node4 |
|---|---|---|---|
| Asserts | A-Current | A-Current1 | A-Current1.1 |
| Asserts | A-Current | A-Current1 | A-Current1.2 |
Kindly consider below -
1. Don't Apply Sort technique - If apply All the Index will done.
2.This is dynamic Internal table so we can't hard code any thing ( only filed symbols will work) .
3.I know how many Nodes will come from the another FM (Here it came 4Nodes (again this is dynamic it may come 99..n))
I am trying from past 3 days to frame the logic.
Thanks In advance,
Kandulas.
2015 Oct 12 10:02 AM
Hi.
This is a recursive issue.
Try to think something like this. I didn't test the solution But I think this could be a road to walk in.
At each loop in your dynamic table you should call a FORM N times until you'll find the lowest level and put a "delete flag" in a column you'll create in fl_tab.
I mean.
g_tabix = 0.
LOOP AT <fl_tab> ASSIGNING <fh_line>.
loc_tabix = sy-tabix.
CHECK ( g_tabix - loc_tabix ) LT 0. "G_tabix will be indexed on the Father Node always and " will Jump through record
g_tabix = loc_tabix + 1. "Increase INDEX to go deeper
node = 1
CLEAR del_flag.
PERFORM search_fltab_index_delete USING <fh_line> node
g_tabix del_flag.
IF del_flag EQ 'X'.
<fh_line>-del_flag = 'X'.
MODIFY TABLE <fl_tab> FROM <fh_line> INDEX loc_tabix.
ENDIF.
ENDLOOP.
"At end DELETE ALL OCCURENCES in <fl_tab> with DEL_FLAG set.
FORM search_fltab_index_delete USING <ph_line> f_node f_tabix f_del_flag.
FIELD-SYMBOLS: <ffh_line> TYPE LINE OF <fl_tab>.
DATA: l_tabix TYPE sy-tabix,
l_node TYPE node,
l_del_flag TYPE del_flag.
l_tabix = f_tabix.
l_node = f_node.
READ TABLE <fl_tab> INTO <ffh_line> INDEX f_tabix.
IF sy-subrc EQ 0.
IF ph_line-f_node EQ <ffh_line>-f_node. "Father node EQ son node
"Same level => GO DEEPER
del_flag = 'X'. "Delete upper level
ADD 1 TO l_tabix
ADD 1 TO l_node
CLEAR l_del_flag.
PERFORM search_fltab_index_delete USING <ffh_line> l_node
l_tabix l_del_flag.
IF l_del_flag EQ 'X'.
<ffh_line>-del_flag = 'X'.
MODIFY TABLE <fl_tab> FROM <ffh_line> INDEX f_tabix.
ENDIF.
ELSE.
"New level
ENDIF.
ENDIF.
f_tabix = l_tabix.
ENDFORM.
Hope to help
Bye
2015 Oct 12 10:39 AM
Hi Roberto Thanks for reply ,
Can you kindly put more details . (I didn't get the why 'CHECK' is required ).
Really helpful to me if you give more details about the code because I tried a lot as per my knowledge but still no luck .
Thanks,
Kandulas.
2015 Oct 12 10:57 AM
Hi.
I repeat I've only put a kind of solution. I didn't test it but CHECK is to jump from example
1record TO 4 record..
LOOP will process 1st record... and will output only 4th record
.. To go from 1st to 5th you'll need to put this CHECK . At each recursive call g_tabix will increase from 1 to 4.. and LOOP will do:
4 - 2 , 4 -3 , 4 - 4 , 4 - 5 ...and jump to 5th record to process the next level 2 ...
But this depends on how you mean to process your records if I understood well your needs.
| Node1 | Node2 | Node3 | Node4 | Header 5 | |
|---|---|---|---|---|---|
| Asserts | 1 | ||||
| Asserts | A-Current | 2 | |||
| Asserts | A-Current | A-Current1 | 3 | ||
| Asserts | A-Current | A-Current1 | A-Current1.1 | 4 | |
| Asserts |
|
Hope to help,
bye
2015 Oct 12 11:49 AM
Hello Roberto ,
I got your point but here lot of challenging's .
1.I can't hard code like Node1
2.I can't check directly ( ph_line-f_node EQ <ffh_line>-f_node. "Father node EQ son node) those never same since f_node is never static filed
is it possible to you to write full logic ...really hep full to me is you provide entire logic (Because all the ways it dynamic )
Thanks,
Kandula.
2015 Oct 12 12:43 PM
Hi.
You can build node name with field symbols and a DO.ENDDO cycle
nodenum(2) TYPE n.
namefield(30) TYPE c.
field-symbols <f_field_value> TYPE any.
DO.
ADD 1 TO nodenum
CONCATENATE '<ffh_line>-node' nodenum INTO name_field.
ASSIGN (name_field) TO <f_field_value>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
"In f_field_value you got your value
ENDDO.
If you give some of your code I could have a look..
Hope to help.
2015 Oct 12 1:13 PM
Hi ,
Yes you are correct now, This difficulty I am facing ...How ever I am sharing some of my code below.
(It may help)
*---Note gv_count is 4 so maximum levels will come 4
loop at <lf_struct> assigning <lf_field>.
lv_ind = 0.
do gv_count times.
lv_fname = 'NODE-'.
concatenate lv_fname lv_ind into lv_fname.
condense lv_fname.
assign component lv_fname of structure <lf_field> to <lf_where>. "Current Record
* assign component lv_fname of structure <lf_value> to <lf_where_prev> "Next Record.
if <lf_where> = <lf_where_prev> .
endif.
enddo.
endloop.
awaiting for your reply
Thanks,
Kandula.
2015 Oct 12 2:34 PM
Hi.
I put a correction:
loop at <lf_struct> assigning <lf_field>.
lv_ind = 0.
level_index_row = sy-tabix.
ADD 1 TO level_index_row.
do gv_count times.
ADD 1 TO lv_ind. "<== correct index
lv_fname = 'NODE-'.
concatenate lv_fname lv_ind into lv_fname.
condense lv_fname.
assign component lv_fname of structure <lf_field> to <lf_where>. "Current Record
"Now that you have in lf_where your value... you need to test the same value of the next record
"If equal, go deeper -> Next record
"If not, stop and go to the first occurence after last record read
PERFORM search_value_next USING <lf_where> "You value to check
lv_fname " Fieldname to check
found_flag "If found equal, go deeper
level_index_row.
IF found_flag EQ 'X'.
" set delete flag on current record
ELSE.
"Record Ok "Do not delete and EXIT DO.ENDDO.
ENDIF.
CLEAR found_flag.
enddo.
endloop.
In search_value_next do the same thing before excep for "loop at <lf_struct> assigning <lf_field>."
Instead you should READ TABLE <lf_struct> INTO <another_headline> INDEX LEVEL_INDEX_ROW.
If record found then check LV_FNAME VALUE and if equal
set FOUND_FLAG = 'X'.
Try this.
Hope to help
2015 Oct 12 4:07 PM
loop at <lf_struct> assigning <lf_field>.
*---Clear Index Value
lv_ind = 0.
do gv_count times.
lv_fname = 'NODE-'.
concatenate lv_fname lv_ind into lv_fname.
condense lv_fname.
assign component lv_fname of structure <lf_field> to <lf_where>.
if <lf_where> is not initial.
at end of (lv_fname).
append <lf_field> to <gf_dyntab>.
endat.
endif.
add 1 to lv_ind .
enddo.
endloop.
Now My Internal table loos like below as expected.
| Node1 | Node2 | Node3 | Node4 |
|---|---|---|---|
| Asserts | A-Current | A-Current1 | A-Current1.1 |
| Asserts | A-Current | A-Current1 | A-Current1.2 |
| Asserts | A-Current | A-Current2 | A-Current2.1 |
| Asserts | A-Current | A-Current2 | A-Current2.2 |
| Asserts | A-Noncurrent | A-NonCurrent1 | A-NonCurrent1.1 |
| Asserts | A-Noncurrent | A-NonCurrent1 | A-NonCurrent1.2 |
| Asserts | A-Noncurrent | A-NonCurrent3 |
Now Is The final task .
All my Data In table <fl_final>. Now I have create node for this .
*---Sample code whicj I did
call method go_alv_tree->set_table_for_first_display
loop at <fl_final>.
call method go_alv_tree->add_node
endloop.
Can you kindly let me k now how can I achieve? (Parent/Child/Sub.....) Using above methods?
How to pass the key's based on my requirement?
Thanks In Advance ,
Kandula
2015 Oct 12 4:49 PM
Hi.
You need to Scan Hierarchy with a kind of recursive.
I suggest to have a look here:
http://www.kerum.pl/infodepot/00001
If you need any help ask.
Bye
2015 Oct 13 10:22 AM
Hi Roberto,
I am not getting how to pass the key (I got totally confused ) kindly help me to achieve this final task .
Finally my Dynamic Internal table looks like below (Addition of Account number )
| Node1 | Node2 | Node3 | Node4 | Account Number |
|---|---|---|---|---|
| Asserts | A-Current | A-Current1 | A-Current1.1 | 00002569 |
| Asserts | A-Current | A-Current1 | A-Current1.1 | 00002570 |
| Asserts | A-Current | A-Current1 | A-Current1.2 | 00002571 |
| Asserts | A-Current | A-Current1 | A-Current1.2 | 00002572 |
| Asserts | A-Current | A-Current2 | A-Current2.1 | 00002573 |
| Asserts | A-Current | A-Current2 | A-Current2.2 | 00002574 |
| Asserts | A-Current | A-Current2 | A-Current2.2 | 00002575 |
| Asserts | A-Noncurrent | A-NonCurrent1 | A-NonCurrent1.1 | 00002576 |
| Asserts | A-Noncurrent | A-NonCurrent1 | A-NonCurrent1.1 | 00002577 |
| Asserts | A-Noncurrent | A-NonCurrent1 | A-NonCurrent1.2 | 00002578 |
| Asserts | A-Noncurrent | A-NonCurrent1 | A-NonCurrent1.2 | 00002579 |
Now I want to display this as Hierarchical node format ( looks exact same as in you given link ,Only difference is it is dynamic )
Hierarchy looks like below (For first 7 records )
1. Asserts
2. A-Current
3.A-Current1.1
4.00002569
4.00002570
3 A-Current 1.2
4.00002571
4.00002572
2.A-current2
3.A-Current2.1
4.00002573
3 A-Current 2.2
4.00002574
4.00002575
I hope you understand rest of records how it has to come.
Kindly give valuable logic to achieve this.
Note : I am using class cl_gui_alv_tree
Thanks in Advance,
Kandulas.
2015 Oct 13 12:56 PM
Hi.
As your request is dynamic I suggest you to create a logic like that, allined with given link:
- one internal table with all the names of your nodes to be shown (Asserts, A-Current, etc..);
- one internal table with all relations( Asserts related to A-Current1 and A-Current2, A-Current1 related to A-Current1.1. A-Current1.2, etc.
To achieve your second internal table you should (recursive way), Loop in your internal table with Node2 and find all occurences in Node 3, loop with Node 3 and find all occurences in Node4, etc.. Until you reach last Column.
Once you have defined your second internal table, you should reach your goal easily.
Hope to help.
2015 Oct 13 1:33 PM
Can I have sample code pls because I can't arrange my data as like given link
2015 Oct 12 12:19 PM
Hi Siva,
***************
Finally I want to see all the Levels in one row ---Like below (From above explanation - I have to dig for till last Level of the Node) .
| Node1 | Node2 | Node3 | Node4 |
|---|---|---|---|
| Asserts | A-Current | A-Current1 | A-Current1.1 |
| Asserts | A-Current | A-Current1 | A-Current1.2 |
******************
As per you explanation, you want to see the above output in this case..?
If yes, what about the rest
A-Current2
A-Current2.1
A-Current2.2
A-Noncurrent
A-NonCurrent1
A-NonCurrent1.1
A-NonCurrent1.2
A-NonCurrent3
Thanks & Regards,
B Raghu Prasad
2015 Oct 12 1:06 PM
Hi Raghu Prasad,
I have to show those as well (I have given explanation for 2 rows only That's why I had 2 rows for output).
Finally I want My Internal Table like below.
| Node1 | Node2 | Node3 | Node4 |
|---|---|---|---|
| Asserts | A-Current | A-Current1 | A-Current1.1 |
| Asserts | A-Current | A-Current1 | A-Current1.2 |
| Asserts | A-Current | A-Current2 | A-Current2.1 |
| Asserts | A-Current | A-Current2 | A-Current2.2 |
| Asserts | A-Noncurrent | A-NonCurrent1 | A-NonCurrent1.1 |
| Asserts | A-Noncurrent | A-NonCurrent1 | A-NonCurrent1.2 |
| Asserts | A-Noncurrent | A-NonCurrent3 |
2015 Oct 12 7:00 PM
Here you go:
REPORT z_leafs_in_dynamic_tab.
TYPES: BEGIN OF ts_node,
node1 TYPE string,
node2 TYPE string,
node3 TYPE string,
node4 TYPE string,
END OF ts_node.
DATA: nodes TYPE STANDARD TABLE OF ts_node,
node TYPE ts_node.
START-OF-SELECTION.
node-node1 = 'Asserts'. APPEND node TO nodes.
node-node2 = 'A-Current'. APPEND node TO nodes.
node-node3 = 'A-Current1'. APPEND node TO nodes.
node-node4 = 'A-Current1.1'. APPEND node TO nodes.
node-node4 = 'A-Current1.2'. APPEND node TO nodes.
CLEAR node-node4.
node-node3 = 'A-Current2'. APPEND node TO nodes.
node-node4 = 'A-Current2.1'. APPEND node TO nodes.
node-node4 = 'A-Current2.2'. APPEND node TO nodes.
CLEAR node-node4.
CLEAR node-node3.
node-node2 = 'A-Noncurrent'. APPEND node TO nodes.
node-node3 = 'A-Noncurrent1'. APPEND node TO nodes.
node-node4 = 'A-Noncurrent1.1'. APPEND node TO nodes.
node-node4 = 'A-Noncurrent1.2'. APPEND node TO nodes.
CLEAR node-node4.
node-node3 = 'A-Noncurrent3'. APPEND node TO nodes.
PERFORM find_leafs TABLES nodes.
BREAK-POINT. " Too lazy to write code to write out the table
FORM find_leafs TABLES tab_nodes.
DATA: leaf_ix TYPE i,
non_leafs TYPE STANDARD TABLE OF i,
ix TYPE i.
FIELD-SYMBOLS: <node> TYPE any,
<leaf> TYPE any,
<leaf_noden> TYPE any,
<node_noden> TYPE any.
LOOP AT tab_nodes ASSIGNING <node>.
ix = sy-tabix.
IF <leaf> IS NOT ASSIGNED.
ASSIGN <node> TO <leaf>.
leaf_ix = ix.
ELSE.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <leaf> TO <leaf_noden>.
IF sy-subrc EQ 0.
ASSIGN COMPONENT sy-index OF STRUCTURE <node> TO <node_noden>.
IF <node_noden> EQ <leaf_noden>.
" Partial match on hierarchy, check next noden
CONTINUE.
ELSEIF <leaf_noden> IS INITIAL.
" Found a child => leaf is not a leaf
APPEND leaf_ix TO non_leafs.
ENDIF.
ASSIGN <node> TO <leaf>.
leaf_ix = ix.
ENDIF.
EXIT. " DO
ENDDO. " Process node-1 .. node-N
ENDIF. " <leaf> not assigned
ENDLOOP.
SORT non_leafs DESCENDING.
LOOP AT non_leafs INTO ix.
DELETE tab_nodes INDEX ix.
ENDLOOP.
ENDFORM.
Note that the subroutine expects the data to be sorted the way you have in your example and makes no assumptions about the structure of the table, it should also work with elements of different types.