05-29-2006 1:27 PM
Hi All!
I have a dynamic internal table and in a field called status.The IT is having several line items retrieved dynamically.For example the line item display of status field is as below.
01
02
01
03
05
02
05
.....
Now i want a consolidated field which gives the result like this
status_field = 01,02,03,05...
Its means each staus value should be displayed once in this field.
Any code help please..
Regards
Pavan
05-29-2006 1:31 PM
loop at itab.
move itab-status to itab_new-status.
append itab_new.
clear itab_new.
endloop.
sort itab_new by status.
loop at itab_new.
at new status.
concatenate v_stat itab_new-status into v_stat
separated by ','.
endat.
endloop.
write:/ v_stat.
Regards,
Ravi
05-29-2006 1:29 PM
Hello Kumar,
You could collect all values in another table using COLLECT, thus having each value only once in the new table. Then sort this new table, read it and CONCATENATE all values in the status_field.
Regards,
John.
05-29-2006 1:29 PM
sort itab by status,
delete adjacent duplicate from itab.
first it will sort the table and then it will remove the duplicate entries.
this is what u want.
Mark helpfull answers
Message was edited by: Manoj Gupta
05-29-2006 1:31 PM
try this..
data status_field type string.
loop at it.
concatenate status_field it-lfd into status_field
separated by ','.
endloop.
Regards,
Suresh Datti
P.S. sorry..Didn't read your post completely.. ignore my reply & use the code posted by Ravi below..
Message was edited by: Suresh Datti
05-29-2006 1:31 PM
loop at itab.
move itab-status to itab_new-status.
append itab_new.
clear itab_new.
endloop.
sort itab_new by status.
loop at itab_new.
at new status.
concatenate v_stat itab_new-status into v_stat
separated by ','.
endat.
endloop.
write:/ v_stat.
Regards,
Ravi
05-29-2006 2:22 PM
Hi Ravi
Excellent its working.
But i am getting an extra comma(,) in front of v_stat field.I think i am getting it because of the header any idea how to remove it..
Regards
Pavan
Awarded maximum points
05-29-2006 2:27 PM
Do this way:
loop at itab_new.
at new status.
concatenate itab_new-status v_stat into v_stat
separated by ','.
endat.
endloop.
NOte that i have Changed the order of the arguments passed to the concatenate statement.
Regards,
Ravi
05-29-2006 2:32 PM
Hi !
I made the changes but now i am getting the comma at the end.Also when there is only one status i want only value to be displaced without the comma.Please advise.
Regards
Pavan
05-29-2006 2:36 PM
HI Kumar,
Instead of using the APPEND statement use the COLLECT statement. You then don't need any AT NEW.. statement when looping over the table as there are only unique values in the table.
Then check if the table holds more than one line. If not just read the first value and assign it to status_field, otherwise loop over the table and CONCATENATE each value seperated by ','.
Regards,
John.
05-29-2006 2:39 PM
Hi again,
1. To remove the comma at the end of the string,
2. use this logic (just 4 lines)
3.
<b>data : l type i.
l = strlen( allstat ).
l = l - 1.
allstat = allstat(l).</b>
write 😕 allstat.
regards,
amit m.
05-29-2006 2:44 PM
05-29-2006 1:33 PM
<b>SORT T_BOM BY VBELN POSNR.
DELETE ADJACENT DUPLICATES FROM T_BOM COMPARING VBELN</b>
PLEASE AWARD POINTS IF SOUNF HELPFUL
05-29-2006 1:34 PM
Hi kumar,
1. just copy paste in new program.
2. it will print
01,02,03,05,
3. report abc.
data : begin of itab occurs 0,
status(2) type c,
end of itab.
data : allstat(100) type c.
*----
itab-status = '01'.
append itab.
itab-status = '02'.
append itab.
itab-status = '01'.
append itab.
itab-status = '03'.
append itab.
itab-status = '05'.
append itab.
itab-status = '02'.
append itab.
itab-status = '05'.
append itab.
*----
loop at itab.
if not allstat cs itab-status.
concatenate allstat itab-status ',' into allstat.
endif.
endloop.
*----
write allstat.
regards,
amit m.