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

concatenate!

Former Member
0 Likes
921

Hi Guys,

I hv code like,

data str type string.

(I guess that the str field do not hv any value, bfore executing the following statement very first time.)

concatenate str itab-posnr into str separated by ','.

at end of vbeln.

write str.

endat.

I am getting the output like,

<u><b>,10,20,30</b></u>

So, I dont understand that, Why I am getting the ',' as the first character? I want to not get it!

Any clues

ThanQ.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
880

Hi..just write these..

it'll solve your prob...

shift str left .

write str.

Ram

Hi..just write these..

it'll solve your prob...

shift str left .

write str.

Ram

7 REPLIES 7
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
880

Do this instead.



loop at itab.

....


if sy-tabix = 1
str = itab-posnr.
else.
concatenate str itab-posnr into str separated by ','.
endif.


...

Endloop.

Regards,

Rich Heilman

Read only

0 Likes
880

Hi Rich,

ThanQ to all.

Every ones logic is worked out except SKJ, but I used the Rammohan idea.

But, I dont understand that Why its displaying like that i.e. 1st character as ',', Is it property of CONCATENATE statement from SAP? or I am doing some thing wrong in the earlier statements?

ThanQ.

Read only

0 Likes
880

The reason is that you are saying that you want to concatenate str and itab-posnr into the str, separated by a comma. So lets, say that str contains "X" right now. the output would be....

X,00001

but what if there was no value in str, like it will be the first time thru the loop, then there would be space in front of the ',' followed by the item number. Since the concatenate statement will not see that space, it is simply not there, which is why you see.....

,00001

Usually the fix when doing this concatenate in a loop is to be proactive instead of reactive. For example, don't put the comma there in the first pass of the loop, simply move the value to the str field, then the next times thru the loop, you can concatenante.

The suggestion of shifting the field left to get rid of it, or simply removing after the fact is more reactivate than proactive, which in my opinion is a bad programming practice. Just my 2 cents.

Regards,

Rich Heilman

Read only

0 Likes
880

ThanQ Rich.

Read only

Former Member
0 Likes
880

Try :

concatenate itab-posnr str into str separated by ','.

Thanks,

SKJ

Read only

Former Member
0 Likes
881

Hi..just write these..

it'll solve your prob...

shift str left .

write str.

Ram

Read only

Former Member
0 Likes
880

Hi,

You can also do this.


...

at end of vbeln.
  if str(1) = ','.
    move space to str(1).
    concatenate str no-gaps. 
  endif.
  write str.
endat.

...