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

Formatting Dynamic Internal table

former_member298409
Participant
0 Likes
1,792


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

Node1Node2Node3Node4
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.

Node1Node2Node3Node4
AssertsA-CurrentA-Current1A-Current1.1
AssertsA-CurrentA-Current1A-Current1.2
AssertsA-CurrentA-Current2
AssertsA-CurrentA-Current3
AssertsA-NoncurrentA-NonCurrent2
AssertsA-NoncurrentA-NonCurrent3

Kindly help me to frame logic .

Thanks,

Kandulas.

9 REPLIES 9
Read only

former_member298409
Participant
0 Likes
1,704

This message was moderated.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,704

Just loop at itab, check change of column and react accordingly inserting record in final table, just insure not to insert when column change if previous value was initial, and clear fields right after the changing column when creating new final record.

Regards,

Raymond

Read only

0 Likes
1,704

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


Read only

0 Likes
1,704

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

Read only

0 Likes
1,704

Raymond,

Cam I have sample code pls..It would really helpful to me if you provide some sample code.

Thanks,

Kandulas.

Read only

0 Likes
1,704

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

Read only

0 Likes
1,704
Kiran,
you didn't understand my question .
I am getting data like that only (which you talk about Parent and Child but That is not In sequence)  like below.
NODESBUNODE
AssertsA-Current
A-CurrentA-Current1
A-CurrentA-Current2
A-CurrentA-Current3
AssertsA-Noncurrent
A-NoncurrentA-Noncurrent1
A-NoncurrentA-Noncurrent2
A-NoncurrentA-Noncurrent3
A-Current1A-Current1.1
A-Current1A-Current1.2

Business requirement is we have to arranged them in below 2 format's (See above thread how it got arranged)
1.Hierarchal ALV  (This is already done)
Node1Node2Node3Node4
Asserts
A-Current
A-Current1
A-Current1.1
A-Current1.2
A-Current2
A-Current3
A-NonCurrent
A-NonCurrent2
A-NonCurrent3
2 . Normal ALV.
Node1Node2Node3Node4
AssertsA-CurrentA-Current1A-Current1.1
AssertsA-CurrentA-Current1A-Current1.2
AssertsA-CurrentA-Current2
AssertsA-CurrentA-Current3
AssertsA-NoncurrentA-NonCurrent2
AssertsA-NoncurrentA-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

Read only

0 Likes
1,704

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

Read only

0 Likes
1,704

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.