2009 Jun 19 11:56 AM
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
2009 Jun 19 12:04 PM
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
2009 Jun 19 12:02 PM
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.
2009 Jun 19 12:04 PM
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
2009 Jun 19 12:04 PM
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.
2009 Jun 19 12:04 PM
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
2009 Jun 19 12:52 PM
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.
2009 Jun 19 1:44 PM
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.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |