10-30-2008 3:24 PM
Hi ,
i have a internal table when looped will print the records as follows .
ramu raju kumar anil
ramu raju swetha anil
ramu raju ranjith anil
now i want the internal table to print as follows
ramu raju kumar,swetha,ranjith anil
the 3rd field which is different should be seperated by comma .
how do i write the code .
10-30-2008 3:48 PM
Imagining that your table fields can not be moved around then this is how
you can get the work done
* Imagin the table ITAB has the following fields and values
* FD1 FD2 FD3 FD4
* ramu raju kumar anil
* ramu raju swetha anil
* ramu raju ranjith anil
ITAB1[] = ITAB2[] = ITAB3[] = ITAB4[] = ITAB[].
sort ITAB1 by FD1.
DELETE ADJACENT DUPLICATES FROM ITAB1 comparing FD1.
sort ITAB2 by FD2.
DELETE ADJACENT DUPLICATES FROM ITAB2 comparing FD2.
sort ITAB3 by FD3.
DELETE ADJACENT DUPLICATES FROM ITAB3 comparing FD3.
sort ITAB4 by FD4.
DELETE ADJACENT DUPLICATES FROM ITAB4 comparing FD4.
loop at itab1.
write itab1-fd1.
endloop.
loop at itab2.
write itab1-fd2.
endloop.
loop at itab3.
write : ',' , itab1-fd3.
endloop.
loop at itab4.
write : ',' ,itab1-fd4.
endloop.
Hope this will work, out of curiosity what is the business case for this anyway?
Franc
10-30-2008 4:01 PM
Hello, try this:
DATA: BEGIN OF itab OCCURS 0,
fld1(50),
fld2(50),
fld3(50),
fld4(50),
END OF itab.
DATA: itab2 LIKE TABLE OF itab,
gs_itab2 LIKE LINE OF itab2.
* Appear internal table itab*
FIELD-SYMBOLS: <fs_itab> LIKE LINE OF itab,
<fs_itab2> LIKE LINE OF itab.
LOOP AT itab ASSIGNING <fs_itab>.
READ TABLE itab2 ASSIGNIGN <fs_itab2>
WITH KEY fld1 = <fs_itab>-fld1
fld2 = <fs_itab>-fld2
fld4 = <fs_itab>-fld4.
IF sy-subrc = 0.
CONCATENATE <fs_itab2>-fld3 ',' <fs_itab>-fld3 INTO <fs_itab2>-fld3.
ELSE.
gs_itab2 = <fs_itab>.
APPEND gs_itab2 TO itab2.
ENDIF.
ENDLOOP.
Thanks and Regards.
David Carballido
10-30-2008 4:16 PM
Hi Pradeep,
Do it in this way.
create another table with the same structure named it_tab2.
IT_TAB2[] = IT_TAB[].
Loop at itab.
READ TABLE IT_TAB WITH KEY FIELD1 = IT_TAB-FIELD1
FIELD2 = IT_TAB-FIELD2
FIELD3 = IT_TAB-FIELD3.
IF SY-SUBRC = 0.
WRITE:/ IT_TAB2-FIELD
ELSE.
WRITE:/.
ENDIF.
Endloop.
Thanks,
Chidanand
07-19-2011 7:00 PM