‎2008 Jul 01 10:32 AM
Hi...i have a string in the following form and need to addd a few characters in middle and shift the rest. Can anybody help.
Input should be
Aabcbcdefghi^^500.
Output Aabcbcdefghi ^^500. Note the space after the 4th ^ sign.
I need to traverse through the string and insert space, shift the rest of the sentence by one character. Converting this into itab n concatenating will not work..
‎2008 Jul 01 10:51 AM
Converting this into itab n concatenating will not work..if you know the point at which you want to add a space (for example after every . (period)) the you can split it at . into itab and then concatenate them with space.
to add a space you can use
` `
‎2008 Jul 01 11:07 AM
I have tried that thanks...i m looking for another logic as we write in c programs, taking the string as a character array, accessing each position, only thing that i dont know how to write tht using abap.!!
‎2008 Jul 01 11:58 AM
I have tried that thanks...i m looking for another logic as we write in c programs, taking the string as a character array, accessing each position, only thing that i dont know how to write tht using abap.!!
you mean each char in the string as record in the itab if yes try this
data: string_tab type standard table of char01 ,
input_string type string ,
tlen type i .
tlen = 1 .
input_string = `this is for testing the string split function .` .
CALL FUNCTION 'CONVERT_STRING_TO_TABLE'
EXPORTING
i_string = input_string
i_tabline_length = tlen
TABLES
et_table = string_tab .
‎2008 Jul 01 11:14 AM
hi
Please do it in this way
DATA:
l_str TYPE string,
l_str1 TYPE string,
l_str2 TYPE string,
l_str3 TYPE string.
l_str = 'Aabcbcdefghi^^500'.
l_str1 = l_str(16).
l_str2 = l_str+16(5).
CONCATENATE l_str1 l_str2 INTO l_str3 SEPARATED BY space.
WRITE: / l_str3.
‎2008 Jul 01 11:15 AM
Try this code:
REPORT zdemo LINE-SIZE 40 LINE-COUNT 10(4) no standard page
heading.
data len type i.
parameter : text type char100 lower case.
start-of-selection.
len = strlen( text ).
Say u want to insert a space after 16th position.
concatenate text0(16) text16(len) into text in character mode
separated by space.
write: text.
Regards,
Joy.
‎2008 Jul 01 11:26 AM
Hi,
You can check following piece of code
DATA: str1 TYPE string,
str2 TYPE string,
itab TYPE TABLE OF string,
text TYPE string,
v_len type i.
text = `Aabcbcdefghi^^500`.
SPLIT text AT '^' INTO: TABLE itab.
describe table itab lines v_len.
loop at itab into str1.
if sy-tabix = v_len.
concatenate str2 str1 into str2.
elseif sy-tabix <> 5.
concatenate str1 '^' into str1.
concatenate str2 str1 into str2.
else.
concatenate str1 ' ^' into str1.
concatenate str2 str1 into str2.
endif.
endloop.
write: / text.
write: / str2.