2020 Jan 10 10:23 AM
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?
2020 Jan 10 10:31 AM
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
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?
2020 Jan 10 10:28 AM
2020 Jan 10 10:31 AM
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
2020 Jan 10 10:36 AM
how come every time it overwrites the previous one at every turn of the loop?
2020 Jan 10 11:46 AM
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.
2020 Jan 10 10:32 AM
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 }|.
2020 Jan 10 11:40 AM
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.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |