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 in append

Former Member
0 Likes
3,647

how do I concatenate in a loop but in append the data and not removing.

why using: loop .. concatenate lv_string lv_string2 into lv_stirng3 .. endloop

it overwrites the data with the last data of the loopp,

how can I append the data in the lv_string3 without deleting the previous ones?

1 ACCEPTED SOLUTION
Read only

geert-janklaps
SAP Mentor
SAP Mentor
2,728

Hi,

That's quite easy to with following (pseudo) code (lv_string will contain the full concatenated data):

DATA: lv_string TYPE string.

LOOP AT <your_table> INTO <your_structure>.
CONCATENATE lv_string <your_second_second_string> <your_third_string> INTO lv_string.
ENDLOOP. 

Best regards,

Geert-Jan Klaps

6 REPLIES 6
Read only

FredericGirod
Active Contributor
0 Likes
2,728

Sorry, could you clarify your requirement ?

Read only

geert-janklaps
SAP Mentor
SAP Mentor
2,729

Hi,

That's quite easy to with following (pseudo) code (lv_string will contain the full concatenated data):

DATA: lv_string TYPE string.

LOOP AT <your_table> INTO <your_structure>.
CONCATENATE lv_string <your_second_second_string> <your_third_string> INTO lv_string.
ENDLOOP. 

Best regards,

Geert-Jan Klaps

Read only

0 Likes
2,728

how come every time it overwrites the previous one at every turn of the loop?

Read only

2,728

Because with the into statement you move the value of the concatenation to your variable.

Basically your doing: lv_string = 'value 1' + 'value 2' + 'value 3'.

By adding your variable in the concatenation you ensure your previous value is concatenated with the new additional values.

Read only

2,728

Hi Nick,

write as below

loop.... concatenate lv_string3 lv_string lv_string2 into lv_string3... endloop.

Or

use ABAP 7.4 syntax in the same way.

lv_string3 = |{ lv_string3 }{ lv_string }{ lv_string2 }|.
Read only

Former Member
0 Likes
2,728

for example if they are in a cycle:

loop at <my_table> into <my_structure>.

CONCATENATE my_structure-string1 my_structure-string2 INTO stringtot SEPARATED BY ','.

* here stringtot will contain the values of the first lap of the loop, on the second lap

* I want you to add me the data of the second lap and not overwrite the previous ones

* if, for example, on the first round stringtot is equal to 'hello', the second round must contain 'hello' 'world'.

endloop.