‎2015 Oct 07 9:27 AM
Hello ABAP Guru's,
Kindly help me on formatting Dynamic Internal
I have Dynamic Internal table Like below
<lf_itab> - It is dynamic Internal Table but we know How many Nodes will come (Some times 4 or 5 or more than 10..n). Currently I have taken 4 Nodes
| 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 |
Explanation about Internal Table -
Asserts contains two Sub nodes A-Current A-Noncurrent
A-Current Again Contains A-current 1 and A-current2,A-current3 sub nodes
A-current1 Again contains A-current1.1,A-current1.2 sub nodes
So finally Under Asserts->A-current->A-current1 ->A-current1.1
According to above logic I have to achieve format of my Dynamic 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 | |
| Asserts | A-Current | A-Current3 | |
| Asserts | A-Noncurrent | A-NonCurrent2 | |
| Asserts | A-Noncurrent | A-NonCurrent3 |
Kindly help me to frame logic .
Thanks,
Kandulas.
‎2015 Oct 08 1:49 PM
‎2015 Oct 09 9:03 AM
‎2015 Oct 09 10:21 AM
Thanks Raymond for your response.
My Internal Table not a fixed structure it is dynamic one! (We can't hard code fields)
so In my Internal Table <lf_tab> contains data like above mentioned ...if have some Idea kindly give the logic pls
‎2015 Oct 09 10:43 AM
Yes you won't solve it thru AT NEW/END OF field statement.
So you will have to use some ASSIGN of component to field symbols (of the current record in the loop, and of the new record of final table being created) to perform comparison. Only one AT FIRST statement is required to create an initiam record to final table assigned to a FS.
Regards,
Raymond
‎2015 Oct 09 11:22 AM
Raymond,
Cam I have sample code pls..It would really helpful to me if you provide some sample code.
Thanks,
Kandulas.
‎2015 Oct 09 11:43 AM
Hi Kandulas,
I am not sure what your requirement exactly is, but I somehow feel that you don't require a dynamic internal table in the first case if you change the approach of logic.
Since you have this hierarchy that you need to store, you may have an internal table with just two columns PARENT NODE and CHILD NODE; in every row of this internal table just store the parent node and its child node.
You may use recursive subroutines/methods to read the data whenever it is required until you don't either find a parent node (while traversing up the line) or a child node (while searching down the line). In this way you may also avoid redundancy of date, unlike in earlier case where you are trying to repeat storing the same data for earlier columns.
I hope you understood the solution that I am suggesting and I hope that fits to your requirement.
Regards,
Kiran
‎2015 Oct 09 12:02 PM
| 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 |
| 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 |
| 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 |
This is pending (This is Normal ALV output format)
So this output we want now .
Without Dynamic Table you can't achieve this . because we don't know how many Nodes will come
‎2015 Oct 09 12:23 PM
Start with a (fast written not checked sample)
LOOP AT dyntable ASSIGNING <record>.
IF <final> IS NOT ASSIGNED.
APPEND INITIAL LINE TO finaltable ASSIGNING <final>.
<final> = <record>.
ELSE.
ASSIGN COMPONENT 'NODE1' OF STRUCTURE <record> TO <node1>.
ASSIGN COMPONENT 'NODE1' OF STRUCTURE <final> TO <final1>.
ASSIGN COMPONENT 'NODE2' OF STRUCTURE <record> TO <node2>.
ASSIGN COMPONENT 'NODE2' OF STRUCTURE <final> TO <final2>.
" etc.
IF <node1> NE <final1>.
APPEND INITIAL LINE TO finaltable ASSIGNING <final>.
<final> = <record>.
ELSE.
IF <node2> NE <final2>.
IF <final2> IS INITIAL. "same record
<final2> = <node2>.
ELSE. " build new record from previous one
APPEND <final> TO finaltable ASSIGNING <final>.
CLEAR: <final3>, <final4>.
" Adapt and add your logic, etc.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
Add also check of failed assign, optimize the code, and from level 3 start to find a solution for kind of recursive code.
Regards,
Raymond
‎2015 Oct 12 10:52 AM
Hello Raymond,
That's the issue I can't hard code the Field names (Node1,Node2..Noden).
Can you help me on this
Thanks,
Kandulas.