‎2008 Sep 26 10:25 AM
I have created a internal table of one field to contain a list of text message.
I want to concatenate all the entries in the internal table into single variable separated by ','.
How can I do this?
‎2008 Sep 26 10:27 AM
Concatenating Character Strings
The CONCATENATE statement combines two or more separate strings into one.
CONCATENATE c1 ... cn INTO c [SEPARATED BY s].
This statement concatenates the character fields c1 to cn and assigns the result to c. The system ignores spaces at the end of the individual source strings.
The addition SEPARATED BY s allows you to specify a character field s which is placed in its defined length between the individual fields.
If the result fits into c, sy-subrc is set to 0. However, if the result has to be truncated, sy-subrc is set to 4.
DATA: c1(10) TYPE c VALUE 'Sum',
c2(3) TYPE c VALUE 'mer',
c3(5) TYPE c VALUE 'holi ',
c4(10) TYPE c VALUE 'day',
c1 (30) TYPE c,
sep(3) TYPE c VALUE ' - '.
CONCATENATE c1 c2 c3 c4 INTO c5.
WRITE c5.
CONCATENATE c1 c2 c3 c4 INTO c5 SEPARATED BY sep.
WRITE / c5.
The output looks like this:
Summerholiday
Sum - mer - holi - day
In c1 to c5, the trailing blanks are ignored. The separator sep retains them.
‎2008 Sep 26 10:30 AM
Some function modules for string manipulation have become obsolete and should be replaced by ABAP/4 statements or functions:
STRING_CONCATENATE...->CONCATENATE
STRING_SPLIT...->SPLIT
STRING_LENGTH...->strlen()
STRING_CENTER...->WRITE...TO...CENTERED
STRING_MOVE_RIGHT...->WRITE...TO...RIGHT-JUSTIFIED
‎2008 Sep 26 10:30 AM
Hi,
Loop at itab into wa.
Cnactenate wa INTO variable SEPERATED by '.'.
ENDLOOP.
‎2008 Sep 26 10:31 AM
Hi,
DATA:final_string type string,
char(1) type c value ','.
Loop at itab into wa.
concatenate final_string wa-message into final_string separated by char.
Endloop.
now the final value is final_string.
‎2008 Sep 26 10:37 AM
Hi ..
Please check the code
DATA: i_data TYPE STANDARD TABLE OF marc INITIAL SIZE 0,
l_str TYPE string,
wa_data TYPE marc.
SELECT * FROM marc
UP TO 5 ROWS
INTO TABLE i_data.
LOOP AT i_data INTO wa_data.
CONCATENATE wa_data-matnr wa_data-werks INTO l_str SEPARATED BY ','.
WRITE:/ l_str.
ENDLOOP.
‎2008 Sep 26 10:42 AM
Hi,
Declare a variable string in which u want to save ur concatenated string.
string = ' '.
Loop at internal table.
Concatenate string itab-field into string seperated by ','.
endloop.
Regards,
Surinder
Edited by: SURINDER SINGH OBEROI on Sep 26, 2008 3:25 PM
‎2008 Sep 26 10:43 AM
Hi,
Check this sample code
REPORT z_sdn.
DATA:
BEGIN OF fs_tab,
txt(4),
END OF fs_tab.
DATA:
t_tab LIKE
TABLE OF
fs_tab.
DATA:
w_txt TYPE string.
fs_tab-txt = 'ABC'.
APPEND fs_tab-txt TO t_tab.
fs_tab-txt = 'DEF'.
APPEND fs_tab-txt TO t_tab.
fs_tab-txt = 'GHI'.
APPEND fs_tab-txt TO t_tab.
LOOP AT t_tab INTO fs_tab.
CONCATENATE fs_tab-txt w_txt INTO w_txt SEPARATED BY ','.
ENDLOOP.
WRITE: / w_txt.
Regards
Abhijeet
‎2008 Sep 26 10:46 AM
hi,
just go through this program.
REPORT ZSHAN_MESG.
Data: begin of istring,
mesg type string,
end of istring.
data: it_string like table of istring with header line.
data: totstring type string.
*appending SOME messages to IT_STRING TABLE
move 'ALV' to it_string-mesg.
append it_string.
move 'BDC method' to it_string-mesg.
append it_string.
move 'LSMW method' to it_string-mesg.
append it_string.
move 'BSP applicaitons' to it_string-mesg.
append it_string.
move 'string operations' to it_string-mesg.
append it_string.
loop at it_string.
write: / it_string-mesg.
endloop.
skip 2.
uline at 1(35).
write:/ 'Total itab CONCATENATED string', /.
uline at 1(35).
skip 1.
*CONCATENATING ALL MESSAGES TO ONE STRING
loop at it_string.
Concatenate totstring it_string-mesg into totstring separated by SPACE.
endloop.
write:/ totstring.
Regards,
Shankar.
‎2013 Dec 10 11:17 AM
‎2008 Sep 26 10:47 AM
Hi Vimala,
try it this way:
loop at itab into wa.
concatenate t_string wa-field into t_string separated by ','.
endloop.
write t_string.With luck,
Pritam.
‎2008 Sep 26 10:50 AM
Hi,
Here is the sample code for your solution.
REPORT ZAM_CONCATENATE.
tables: spfli.
types: begin of itabtype1,
carrid type sflight-carrid,
end of itabtype1.
data: itab1 type standard table of itabtype1,
wa1 like line of itab1.
data: output1(500) type c,
sep(3) value ' , '.
select carrid from spfli into table itab1.
loop at itab1 into wa1.
if sy-tabix EQ 1.
concatenate output1 wa1-carrid into output1.
else.
concatenate output1 wa1-carrid into output1 separated by SEP.
endif.
endloop.
write : / output1.
thanks
nikita mishra
‎2008 Sep 26 10:57 AM
Thank you for you help.
I solved this problem using the logic below.
data : str(80).
str = ' '.
loop at itab.
concatenate str itab-stext into str separated by ','.
endloop.
move str+1(79) to text.
‎2014 May 31 4:44 AM
You can allways do this:
DATA:it_line LIKE tline OCCURS 1 WITH HEADER LINE.
LOOP AT it_line.
if sy-tabix = 1.
gw_final-xtline = it_line-tdline.
else.
CONCATENATE gw_final-xtline it_line-tdline into gw_final-xtline.
endif.
ENDLOOP.
Simple