Application Development 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: 

syntax help

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

former_member181962
Active Contributor
0 Kudos

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

12 REPLIES 12

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

suresh_datti
Active Contributor
0 Kudos

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

former_member181962
Active Contributor
0 Kudos

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

0 Kudos

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

0 Kudos

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

0 Kudos

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

0 Kudos

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.

0 Kudos

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.

0 Kudos

Excellent Amit. It works

Can only award 2 points..

Thank you

Pavan

rahulkavuri
Active Contributor
0 Kudos

<b>SORT T_BOM BY VBELN POSNR.

DELETE ADJACENT DUPLICATES FROM T_BOM COMPARING VBELN</b>

PLEASE AWARD POINTS IF SOUNF HELPFUL

Former Member
0 Kudos

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.