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

strings

Former Member
0 Likes
792

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..

6 REPLIES 6
Read only

athavanraja
Active Contributor
0 Likes
771
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

 ` ` 

Read only

0 Likes
771

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.!!

Read only

0 Likes
771

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 .

Read only

Subhankar
Active Contributor
0 Likes
771

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.

Read only

Former Member
0 Likes
771

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.

Read only

Former Member
0 Likes
771

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.