‎2015 Oct 01 5:49 PM
Hello ABAP guru's ,
I have a requirement to show Hierarchical output like below.
| LEVEL-1 | LEVEL-2 | LEVEL-3 | LEVEL-4 | LEVEL-5 | LEVEL-n | DOCUMENT |
| Asserts | ||||||
| A-Current | ||||||
| A-Current1 | ||||||
| A-current 1.1 | 1234 | |||||
| A-current 1.2 | 5678 | |||||
| A-Current2 | 8910 | |||||
| A-Current3 | 99999 | |||||
| A-Noncurrent | ||||||
| A-Noncurrent1 | ||||||
| A-Noncurrent2 | ||||||
| A-Noncurrent3 |
Requirement Details:
Note:There is some business logic behind this Internal table.
itab_input
| NODE | SBUNODE |
| Asserts | A-Current |
| A-Current | A-Current1 |
| A-Current | A-Current2 |
| A-Current | A-Current3 |
| Asserts | A-Noncurrent |
| A-Noncurrent | A-Noncurrent1 |
| A-Noncurrent | A-Noncurrent2 |
| A-Noncurrent | A-Noncurrent3 |
| A-Current1 | A-Current1.1 |
| A-Current1 | A-Current1.2 |
2.Explanation about Internal Table :
Example : NODE i have value Asserts and it's SUBNODE is A-current
Now we have to take the SUBNODE of NODE – Asserts (in our case it is A-current ) and search in internal table if any NODE name existing with name A-Current (In our case YES we have)
Again we have to take SUBNODE of that Node A-current ( in our case it is A-current1) and search in internal table if any NODE name existing with name A-Current1 (In our case NO we have) i.e we reached maximum level. if reached the maximum levels that means we have some document numbers to that node
So from the above example we have to populate like below.
| LEVEL-1 | LEVEL-2 | LEVEL-3 | LEVEL-3 | DOCUMENTNUMBER |
| Asserts | ||||
| A-Current | ||||
| A-Current1 | ||||
| A-Current1.1 | 1234 | |||
| A-Current1.2 | 5678 | |||
| A-Current2 | 8910 | |||
| A-Current3 | 99999 |
Similarly we have to do for the rest of the values also .
Please consider below points :
I have tried lot of ways to achieve the format but I still not yet resolved .
Kindly provide your Inputs .
Thanks In advance,
Kandulas.
‎2015 Oct 01 10:18 PM
See the below code. It does not give you the exact result that you are expecting but it will give you the valid result. Check the logic in the Loop, I think that is what you are looking at.
types: begin of ty_data,
node type char20,
snode type char20,
end of ty_data,
ty_t_data type standard table of ty_data,
begin of ty_fdata,
node1 type char20,
node2 type char20,
node3 type char20,
node4 type char20,
node5 type char20,
node6 type char20,
node7 type char20,
node8 type char20,
end of ty_fdata,
ty_t_fdata type standard table of ty_fdata.
data: ls_data type ty_data,
lt_data type ty_t_data,
ls_fdata type ty_fdata,
lt_fdata type ty_t_fdata.
ls_data-node = 'Asserts'.
ls_data-snode = 'A-Current'.
append ls_data to lt_data.
ls_data-node = 'A-Current'.
ls_data-snode = 'A-Current1'.
append ls_data to lt_data.
ls_data-node = 'A-Current'.
ls_data-snode = 'A-Current2'.
append ls_data to lt_data.
ls_data-node = 'A-Current'.
ls_data-snode = 'A-Current3'.
append ls_data to lt_data.
ls_data-node = 'Asserts'.
ls_data-snode = 'A-NonCurrent'.
append ls_data to lt_data.
ls_data-node = 'A-NonCurrent'.
ls_data-snode = 'A-NonCurrent1'.
append ls_data to lt_data.
ls_data-node = 'A-NonCurrent'.
ls_data-snode = 'A-NonCurrent2'.
append ls_data to lt_data.
ls_data-node = 'A-NonCurrent'.
ls_data-snode = 'A-NonCurrent3'.
append ls_data to lt_data.
ls_data-node = 'A-Current1'.
ls_data-snode = 'A-Current1.1'.
append ls_data to lt_data.
ls_data-node = 'A-Current1'.
ls_data-snode = 'A-Current1.2'.
append ls_data to lt_data.
data: lv_nname type char10,
lv_tabix type i,
lv_levels type i value 4,
lv_level type i,
lv_clevel type char2.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
loop at lt_data into ls_data.
clear: lv_level.
do lv_levels times.
lv_level = lv_level + 1.
lv_clevel = lv_level.
concatenate 'NODE' lv_clevel into lv_nname.
condense lv_nname.
read table lt_fdata transporting no fields
with key (lv_nname) = ls_data-node.
if sy-subrc = 0.
exit.
endif.
enddo.
if sy-subrc = 0.
" Node has been found
clear ls_fdata.
lv_level = lv_level + 1.
assign component lv_level of structure ls_fdata
to <dyn_field>.
<dyn_field> = ls_data-snode.
lv_tabix = sy-tabix + 1.
insert ls_fdata into lt_fdata index lv_tabix.
else.
" Node not found
clear ls_fdata.
ls_fdata-node1 = ls_data-node.
append ls_fdata to lt_fdata.
clear ls_fdata.
ls_fdata-node2 = ls_data-snode.
append ls_fdata to lt_fdata.
endif.
endloop.
‎2015 Oct 01 10:18 PM
See the below code. It does not give you the exact result that you are expecting but it will give you the valid result. Check the logic in the Loop, I think that is what you are looking at.
types: begin of ty_data,
node type char20,
snode type char20,
end of ty_data,
ty_t_data type standard table of ty_data,
begin of ty_fdata,
node1 type char20,
node2 type char20,
node3 type char20,
node4 type char20,
node5 type char20,
node6 type char20,
node7 type char20,
node8 type char20,
end of ty_fdata,
ty_t_fdata type standard table of ty_fdata.
data: ls_data type ty_data,
lt_data type ty_t_data,
ls_fdata type ty_fdata,
lt_fdata type ty_t_fdata.
ls_data-node = 'Asserts'.
ls_data-snode = 'A-Current'.
append ls_data to lt_data.
ls_data-node = 'A-Current'.
ls_data-snode = 'A-Current1'.
append ls_data to lt_data.
ls_data-node = 'A-Current'.
ls_data-snode = 'A-Current2'.
append ls_data to lt_data.
ls_data-node = 'A-Current'.
ls_data-snode = 'A-Current3'.
append ls_data to lt_data.
ls_data-node = 'Asserts'.
ls_data-snode = 'A-NonCurrent'.
append ls_data to lt_data.
ls_data-node = 'A-NonCurrent'.
ls_data-snode = 'A-NonCurrent1'.
append ls_data to lt_data.
ls_data-node = 'A-NonCurrent'.
ls_data-snode = 'A-NonCurrent2'.
append ls_data to lt_data.
ls_data-node = 'A-NonCurrent'.
ls_data-snode = 'A-NonCurrent3'.
append ls_data to lt_data.
ls_data-node = 'A-Current1'.
ls_data-snode = 'A-Current1.1'.
append ls_data to lt_data.
ls_data-node = 'A-Current1'.
ls_data-snode = 'A-Current1.2'.
append ls_data to lt_data.
data: lv_nname type char10,
lv_tabix type i,
lv_levels type i value 4,
lv_level type i,
lv_clevel type char2.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
loop at lt_data into ls_data.
clear: lv_level.
do lv_levels times.
lv_level = lv_level + 1.
lv_clevel = lv_level.
concatenate 'NODE' lv_clevel into lv_nname.
condense lv_nname.
read table lt_fdata transporting no fields
with key (lv_nname) = ls_data-node.
if sy-subrc = 0.
exit.
endif.
enddo.
if sy-subrc = 0.
" Node has been found
clear ls_fdata.
lv_level = lv_level + 1.
assign component lv_level of structure ls_fdata
to <dyn_field>.
<dyn_field> = ls_data-snode.
lv_tabix = sy-tabix + 1.
insert ls_fdata into lt_fdata index lv_tabix.
else.
" Node not found
clear ls_fdata.
ls_fdata-node1 = ls_data-node.
append ls_fdata to lt_fdata.
clear ls_fdata.
ls_fdata-node2 = ls_data-snode.
append ls_fdata to lt_fdata.
endif.
endloop.
‎2015 Oct 02 7:26 AM
Hello Chandra Thanks a lot for giving valuable logic.
I have tried and it is coming like below.
| NODE1 | NODE2 | NODE3 | NODE4 | NODE5 | NODE6 | NODE7 | NODE8 |
|---|---|---|---|---|---|---|---|
| Asserts | |||||||
| A-NonCurrent | |||||||
| A-NonCurrent3 | |||||||
| A-NonCurrent2 | |||||||
| A-NonCurrent1 | |||||||
| A-Current | |||||||
| A-Current3 | |||||||
| A-Current2 | |||||||
| A-Current1 | |||||||
| A-Current1.2 | |||||||
| A-Current1.1 |
But I am expecting format like below because here Hierarchy very very Important
| NODE1 | NODE2 | NODE3 | NODE4 | NODE5 | NODE6 | NODE7 | NODE8 |
|---|---|---|---|---|---|---|---|
| Asserts | |||||||
| A-Current | |||||||
| A-Current1 | |||||||
| A-Current1.1 | |||||||
| A-Current1.2 | |||||||
| A-Current3 | |||||||
| A-Current2 | |||||||
| A-NonCurrent | |||||||
| A-NonCurrent3 | |||||||
| A-NonCurrent2 | |||||||
| A-NonCurrent1 |
I guess we have to change the Insert in properway ... I have tried to set by indexing but not able to achieve this.
Kindly help on this.
Thanks,
Kandulas.
‎2015 Oct 02 1:04 PM
Hello Chandra Thanks a lot for giving valuable logic.
I have tried and it is coming like below.
| NODE1 | NODE2 | NODE3 | NODE4 | NODE5 | NODE6 | NODE7 | NODE8 |
|---|---|---|---|---|---|---|---|
| Asserts | |||||||
| A-NonCurrent | |||||||
| A-NonCurrent3 | |||||||
| A-NonCurrent2 | |||||||
| A-NonCurrent1 | |||||||
| A-Current | |||||||
| A-Current3 | |||||||
| A-Current2 | |||||||
| A-Current1 | |||||||
| A-Current1.2 | |||||||
| A-Current1.1 |
But I am expecting format like below because here Hierarchy very very Important
| NODE1 | NODE2 | NODE3 | NODE4 | NODE5 | NODE6 | NODE7 | NODE8 |
|---|---|---|---|---|---|---|---|
| Asserts | |||||||
| A-Current | |||||||
| A-Current1 | |||||||
| A-Current1.1 | |||||||
| A-Current1.2 | |||||||
| A-Current3 | |||||||
| A-Current2 | |||||||
| A-NonCurrent | |||||||
| A-NonCurrent3 | |||||||
| A-NonCurrent2 | |||||||
| A-NonCurrent1 |
I guess we have to change the Insert in properway ... I have tried to set by indexing but not able to achieve this.
Kindly help on this.
Thanks,
Kandulas.
‎2015 Oct 02 5:58 PM
That should not be an issue. Based on the input the result will come as you expected.
If the input as follows then the result will be as you expected.
NODE SUBNODE
Asserts A-NonCurrent
A-NonCurrent A-NonCurrent3
A-NonCurrent A-NonCurrent2
A-NonCurrent A-NonCurrent1
Asserts A-Current
A-Current A-Current3
A-Current A-Current2
A-Current A-Current1
A-Current1 A-Current1.2
A-Current1 A-Current1.1
I am sure that the above Node/Subnode sequence will change. So, based on that the result will change.
‎2015 Oct 05 2:58 PM
Thanks Chandra, your given logic perfectly working with few small modifications
I did like below for Inserting on index basis.
after RAED statement I have taken the Index and added 1 while appending.
Now My Internal Table like below as expected
| Node1 | Node2 | Node3 | Node4 |
| Asserts | |||
| A-Current | |||
| A-Current1 | |||
| A-Current1.1 | |||
| A-Current1.2 | |||
| A-Current2 | |||
| A-Current3 | |||
| A-NonCurrent | |||
| A-NonCurrent2 | |||
| A-NonCurrent3 |
But In output I have to show 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 | |
| Asserts | A-Current | A-Current3 | |
| Asserts | A-Noncurrent | A-NonCurrent2 | |
| Asserts | A-Noncurrent | A-NonCurrent3 |
Can you kindly help me on this .to frame output like above
Please note below.
1.Node1 and Node 2 ...n is coming as Dynamic Structure (There is no hard coding on fields).
2.We don't want to change the existing code (which is designed to separate the levels because it contains lot od sensitive logic )
Thanks In Advance,
Kandulas.
‎2015 Oct 05 3:00 PM
I did like below for Inserting on index basis.
after RAED statement I have taken the Index and added 1 while appending.
Now My Internal Table like below as expected
| Node1 | Node2 | Node3 | Node4 |
| Asserts | |||
| A-Current | |||
| A-Current1 | |||
| A-Current1.1 | |||
| A-Current1.2 | |||
| A-Current2 | |||
| A-Current3 | |||
| A-NonCurrent | |||
| A-NonCurrent2 | |||
| A-NonCurrent3 |
But In output I have to show 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 | |
| Asserts | A-Current | A-Current3 | |
| Asserts | A-Noncurrent | A-NonCurrent2 | |
| Asserts | A-Noncurrent | A-NonCurrent3 |
Can you kindly help me on this .to frame output like above
Please note below.
1.Node1 and Node 2 ...n is coming as Dynamic Structure (There is no hard coding on fields).
2.We don't want to change the existing code (which is designed to separate the levels because it contains lot od sensitive logic )
Thanks In Advance,
Kandulas.
‎2015 Oct 07 5:09 AM
Hi Chandra,
Is any possibility to achieve above format ?
Thanks,
Kandulas.
‎2015 Oct 07 4:12 PM
That should not be a big issue to achieve it. Just loop through the final internal table and arrange the data according to your requirement.
Please mark the posts as helpful or answered if any of the responses helps you in solving your problem.
‎2015 Oct 12 12:05 PM
Hi Chandra I have tried a lot but still I didn't find any exact logic to frame my Internal table format like above .
it is really helpful to if you provide the logic.
Thanks,
Kandulas.
‎2015 Oct 14 9:24 PM
‎2015 Oct 02 6:55 AM
Hi, Siva!
Did you try to use any alv tree? I think it will be better and easier. Or it must be a flat table?