Application Development 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: 

how to trim a string

Former Member
0 Kudos

Hi,

I have a problem where in I have to trim the characters from the second name.e.g.Manish Kumar should be trimmed to Manish K.

Regards,

Manish

1 ACCEPTED SOLUTION

Mohamed_Mukhtar
Active Contributor
0 Kudos

hi Manish ,

See pseudo code

DATA name(50) TYPE c VALUE 'manish kumar'.

DATA : BEGIN OF itab OCCURS 0,
       a(50),
       b(50),
       END OF itab.

SPLIT name AT space INTO itab-a
                         itab-b.

CONCATENATE itab-a itab-b+0(1) INTO name separated by space.

write name.

Regards

7 REPLIES 7

kiran_k8
Active Contributor
0 Kudos

Manish,

Use the Offset Concept.Check the field length and use it accordingly.

ex:-syntax WA_EMP-JOBTI+27(56) where u want to access starting from the 27th character to 56th character.

K.Kiran.

JozsefSzikszai
Active Contributor
0 Kudos

hi Manish,

you can do something like this:

SPLIT name AT space INTO itab.
gv_lines = lines( itab ). "in case there are more first names
READ TABLE itab INTO wa INDEX gv_lines. "this will be the last name
wa = wa(1).
MODIFY itab FROM wa INDEX gv_lines.
CONCATENATE itab INTO name.

hope this helps

ec

Former Member
0 Kudos

Hi,

Try this.

data: off type i.

c1='Manish kumar'.

find ' ' in c match offset off.

c2 = c1+0(off + 1).

Sharin.

Mohamed_Mukhtar
Active Contributor
0 Kudos

hi Manish ,

See pseudo code

DATA name(50) TYPE c VALUE 'manish kumar'.

DATA : BEGIN OF itab OCCURS 0,
       a(50),
       b(50),
       END OF itab.

SPLIT name AT space INTO itab-a
                         itab-b.

CONCATENATE itab-a itab-b+0(1) INTO name separated by space.

write name.

Regards

Subhankar
Active Contributor
0 Kudos

HI...

Please see this example...

data: l_str1 TYPE string,

l_str2 TYPE string,

l_str3 TYPE string.

l_str1 = 'Subhankar Garani'.

SPLIT l_str1 at space INTO l_str2 l_str3.

CLEAR: l_str1.

CONCATENATE l_str2 l_str3(1) INTO l_str1 SEPARATED BY space.

WRITE: l_str1.

Former Member
0 Kudos

Hi,

Check this code:

LOOP AT itab INTO wa_itab.

SPLIT wa_itab-name AT space INTO name1 name2.

CONCATENATE name1 name2(1) INTO wa_itab-name separated by space.

MODIFY itab FROM wa_itab.

ENDLOOP.

Regards,

Amit

Former Member
0 Kudos

Try to get the length of string of second name by some coding say it is n

now

shift <name> by n-1 places right

condense <name>