2013 Jul 09 1:06 PM
Hi Experts,
I am having issue while concatenating string inside loop.
Below is the scenario,
Inside loop w_string is getting appended,like
loop on it_line.
append it_line-v_str to w_string.
endlloop.
Now w_string will have sequence of values like for e.g. in first iteration w_stinrg = 'hello ' , 2nd interation " w_string = 'hello how', 3rd iteration : w_string = 'hello how are', 4th iteration of loop w_string = 'hello how are you' ...likeways.
This w_string is getting appended with new value depending upon offset and length,
Now I need to write concatenate inside this loop , to concatenatenate this w_string value into another string w_string1 considering offset without repeating same values. so my w_string1 will have same content.... 'hello how are you'. I am not able to do this as everytime it is concatenating same repeated values into string and I need this concatenate here inside loop only.
Please let me know if somebody came accross similar issue before.
Thanks,
Sanjana
2013 Jul 09 8:16 PM
SO show us the code that you are using and perhaps we will see what is amiss.
Neal
2013 Jul 09 8:19 PM
2013 Jul 09 9:39 PM
Hi Sanjana,
I didn't get what actually is w_string. Is it string or string table?
If its just concatenate table values into a string,inside a loop, you can use below sample code.
LOOP AT lt_string INTO ls_string.
CONCATENATE string ls_string INTO string SEPARATED BY space.
CLEAR ls_string.
ENDLOOP.
If you are looking for something else, please post your code so that the requirement could be better understood and if there is anything missing can be looked into.
Shanmukh Srinivas
2013 Jul 09 11:52 PM
your requirement is not clear, why are doing the same thing in two different string variables? what are you trying to achive with this. Also paste your code so that we can see what is going wrong.
regards
swanand
2013 Jul 10 1:09 AM
Hi,
The code can be like:
clear: w_string.
loop on it_line.
CONCATENATE w_string it_line-v_str into w_string SEPARATED BY space.
CONDENSE w_string.
endlloop.
In 1st iteration
Before concatenation:
w_string = ' '
it_line-v_str = Hello
After concatenation:
w_string = ' Hello'
After condense:
w_string = 'Hello' (leading space removed)
In 2nd iteration
Before concatenation:
w_string = 'Hello' (Value after 1st iteration)
it_line-v_str = How
After concatenation:
w_string = ' Hello How'
After condense:
w_string = 'Hello How' (leading space and redundant spaces in between if any removed)
and so on...
Assuming that's what you asked for..
Cheers,
Arindam
2013 Jul 10 2:28 AM
Hi, sanjana lingras
LOOP AT itab INTO wa_string.
CONCATENATE itab-ztext wa_string INTO itab-ztext SEPERATE BY SPACE.
ENDLOOP.
2013 Jul 10 3:08 AM
Hi,
The APPEND statement used to append the records not for CONCATENATION.
You have to use CONCATENATE statement inside the loop to get string string values concatenated.
The code part given by Arindam Mondal is the correct one.
Regards,
Anil.
2013 Jul 10 4:51 AM
Hi Sanjana,
For your requirement , to get the unique string inside the loop. you can try like this.
TYPES : BEGIN OF ty_line,
text TYPE char10,
END OF ty_line.
DATA : it_line TYPE STANDARD TABLE OF ty_line,
lw_line LIKE LINE OF it_line.
DATA : w_string TYPE string.
lw_line-text = 'hello' .
APPEND lw_line TO it_line.
lw_line-text = 'how' .
APPEND lw_line TO it_line.
lw_line-text = 'are' .
APPEND lw_line TO it_line.
lw_line-text = 'how' .
APPEND lw_line TO it_line.
lw_line-text = 'you' .
APPEND lw_line TO it_line.
lw_line-text = 'hello' .
APPEND lw_line TO it_line.
LOOP AT it_line INTO lw_line .
FIND lw_line-text IN w_string. " If same word is NOT found , then combine it
IF sy-subrc NE 0.
CONCATENATE w_string lw_line-text INTO w_string SEPARATED BY space.
ENDIF.
endloop.
WRITE : / 'String without repeated words', w_string.
2013 Jul 10 5:33 AM
Go to abap help documentation and understand the functionality of append and concatenate statements.
2013 Jul 10 5:39 AM
Hi Sanjana,
Try like this..
TYPES : BEGIN OF ty_itab,
line1(20) TYPE c,
END OF ty_itab.
DATA : it_itab TYPE TABLE OF ty_itab,
wa_itab type ty_itab,
w_var type string.
wa_itab-line1 = 'hello'.
APPEND wa_itab TO it_itab.
wa_itab-line1 = 'how'.
APPEND wa_itab TO it_itab.
wa_itab-line1 = 'are'.
APPEND wa_itab TO it_itab.
wa_itab-line1 = 'you'.
APPEND wa_itab TO it_itab.
clear : wa_itab, w_var.
LOOP AT it_itab INTO wa_itab.
CONCATENATE w_var wa_itab-line1 INTO w_var SEPARATED BY space.
ENDLOOP.
WRITE : / w_var.
Output:
TYPES : BEGIN OF ty_itab,
line1 TYPE string,
END OF ty_itab.
TYPES : BEGIN OF ty_itab1,
sno(4) type c,
line1 TYPE string,
END OF ty_itab1.
DATA : it_itab TYPE TABLE OF ty_itab,
wa_itab type ty_itab,
w_var type string.
data : it_itab1 TYPE TABLE OF ty_itab1,
wa_itab1 type ty_itab1.
do 10 times.
wa_itab1-sno = wa_itab1-sno + 1.
append wa_itab1 to it_itab1.
enddo.
wa_itab-line1 = 'hello'.
APPEND wa_itab TO it_itab.
wa_itab-line1 = 'how'.
APPEND wa_itab TO it_itab.
wa_itab-line1 = 'are'.
APPEND wa_itab TO it_itab.
wa_itab-line1 = 'you'.
APPEND wa_itab TO it_itab.
clear : wa_itab, w_var.
LOOP AT it_itab INTO wa_itab.
CONCATENATE w_var wa_itab-line1 INTO w_var SEPARATED BY space.
ENDLOOP.
Loop at it_itab1 into wa_itab1.
wa_itab1-line1 = w_var.
modify it_itab1 from wa_itab1 TRANSPORTING line1.
clear wa_itab1.
endloop.
Loop at it_itab1 into wa_itab1.
WRITE : / wa_itab1-sno, wa_itab1-line1.
endloop.
Output:
2013 Jul 10 6:30 AM
Try this code :
REPORT YTEST.
data gt_tab type table of string.
data gs_tab type string.
data result type string.
data length type i.
gs_tab = 'Hello'. append gs_tab to gt_tab.
gs_tab = 'Hello How'. append gs_tab to gt_tab.
gs_tab = 'Hello How Are'. append gs_tab to gt_tab.
gs_tab = 'Hello How Are You'. append gs_tab to gt_tab.
loop at gt_tab into gs_tab.
if result is INITIAL.
result = gs_tab.
else.
length = strlen( result ).
CONCATENATE result gs_tab+length into result.
endif.
clear gs_tab.
endloop.
write : / result.
Regards,
Gagan
2013 Jul 10 2:41 PM
Hi All,
Thanks for the quick help, this is no more required. This is solved using offset and length.
thanks,
Sanjana