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

Combin more than one Rows in Internal table

Former Member
0 Likes
922

Dear Friends,

I am facing one problem but i do not how to solve the problem.

My data stored in ITAB for this format

Col1 Col2 Col3 Col4 Col5

========================================

1 AAA 10 0 0

1 AAA 0 20 0

1 AAA 0 0 30

But i want all the data displayed single row i.e

Col1 Col2 Col3 Col4 Col5

========================================

1 AAA 10 20 30

I try to resolve the modify internal command , but does not work. Please tell me how to solve the issue.

Thanks

Saravanan R

1 ACCEPTED SOLUTION
Read only

former_member229729
Active Participant
0 Likes
890

Hi Saravanan,

If the COL3,COL4,COL5 are of type N or I, then you can use the COLLECT Syntax.

That will add all the Numeric columns into one for every distinct other Columns.

For example, look at the URL:

http://help.sap.com/saphelp_nw04/Helpdata/EN/fc/eb36d5358411d1829f0000e829fbfe/content.htm

Rgds,

Ramani N

Dear Friends,

I am facing one problem but i do not how to solve the problem.

My data stored in ITAB for this format

Col1 Col2 Col3 Col4 Col5

========================================

1 AAA 10 0 0

1 AAA 0 20 0

1 AAA 0 0 30

But i want all the data displayed single row i.e

Col1 Col2 Col3 Col4 Col5

========================================

1 AAA 10 20 30

I try to resolve the modify internal command , but does not work. Please tell me how to solve the issue.

Thanks

Saravanan R

6 REPLIES 6
Read only

Former Member
0 Likes
890

Try this. After loop ends, itabnew will contain output you want to display.


DATA itabnew LIKE itab.

LOOP AT itab INTO wa.
  COLLECT wa INTO itabnew.
ENDLOOP.

Read only

ThomasZloch
Active Contributor
0 Likes
890

See if you can use the COLLECT statement, however your first column should be a character field, or you might end up with value 3 and not 1.

Thomas

Read only

Former Member
0 Likes
890

Hi,

You can try this way..

LOOP AT ITAB,
You can modularize the below logic using field symbols.

IF NOT COL3 IS INITIAL.
MODIFY ITAB TRANSPORTING ITAB-COL3  
                  WHERE COL1 = ITAB-COL1 AND 
                               COL2 = ITAB-COL2 AND
                               COL3 IS INITIAL. 

ENDIF.
IF NOT COL4 IS INITIAL.
MODIFY ITAB TRANSPORTING ITAB-COL4  
                  WHERE COL1 = ITAB-COL1 AND 
                               COL2 = ITAB-COL2 AND
                               COL4 IS INITIAL. 


ENDIF.
IF NOT COL5 IS INITIAL.
MODIFY ITAB TRANSPORTING ITAB-COL5  
                  WHERE COL1 = ITAB-COL1 AND 
                               COL2 = ITAB-COL2 AND
                               COL5 IS INITIAL. 


ENDIF.
ENDLOOP.

SORT ITAB.
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING ALL FIELDS.

Read only

former_member229729
Active Participant
0 Likes
891

Hi Saravanan,

If the COL3,COL4,COL5 are of type N or I, then you can use the COLLECT Syntax.

That will add all the Numeric columns into one for every distinct other Columns.

For example, look at the URL:

http://help.sap.com/saphelp_nw04/Helpdata/EN/fc/eb36d5358411d1829f0000e829fbfe/content.htm

Rgds,

Ramani N

Read only

Former Member
0 Likes
890

Hi,

try out this code

declare one more internal tabe (itab_new ) of type itab

loop at itab.

itab_new-col1 = itab-col1.

itab_new-col2 = itab-col2.

g_col3 = g_col3 + itab-Col3. ---adding col3 values for those entries whose col1 are same

g_col4 = g_col4 + itab-Col4.---adding col4 values for those entries whose col1 are same

g_col5 = g_col5 + itab-Col5.---adding col5 values for those entries whose col1 are same

at end of col1. -


the code below is executed at the end of col1 entry in the itab

itab_new-col3 = g_col3.

itab_new-col4 = g_col4.

itab_new-col5 = g_col5.

append itab_new.

endloop.

Hope this helps.

Let me know if the problem still persist.

Regards,

Janaki.

Read only

Former Member
0 Likes
890

Hi,

It seems your problem is with the placement of 'APPEND' statement.

I guess APPEND statement is written after moving data into each column ( i.e after col3, col4 & col5 ).

If so, remove APPEND statement after moving data to fields col3 & col4 and only one APPEND statement after moving data into field col5 is sufficient.

This is what i assume from your problem and if this is not the situation, COLLECT statement will help you as suggested by others.

regards

Sreenivas.