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

abap commands

Former Member
0 Likes
869

hi folks

i've got a text string

text = 'Steve L Tyler'.

I want first name and last name from this string. How to write this command.

i mean I want first name : Steve

last name Tyler

It could be 'John F K Anderson'.

and then I would need

first name : John

last name Anderson.

I hope i'm clear.

With regards

Mandeep

  • marks will be rewarded for helpful advice...

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
769

You can do the following:

DATA: lv_string TYPE string,

lv_firstname TYPE string,

lv_lastname TYPE string,

lv_num TYPE i,

lv_check TYPE c.

lv_string = 'Firstname h g t Lastname'.

lv_check = lv_string(1).

  • extract first name

WHILE NOT lv_check IS INITIAL.

CONCATENATE lv_firstname lv_string(1) INTO lv_firstname.

SHIFT lv_string LEFT BY 1 PLACES IN CHARACTER MODE.

lv_check = lv_string(1).

ENDWHILE.

  • extract last name

lv_num = STRLEN( lv_string ).

lv_num = lv_num - 1.

lv_check = lv_string+lv_num(1).

WHILE NOT lv_check IS INITIAL.

CONCATENATE lv_string+lv_num(1) lv_lastname INTO lv_lastname.

SHIFT lv_string RIGHT BY 1 PLACES IN CHARACTER MODE.

lv_check = lv_string+lv_num(1).

ENDWHILE.

WRITE: / lv_lastname, ',', lv_firstname.

Regards,

Michael

4 REPLIES 4
Read only

Former Member
0 Likes
769

Mandeep,

Following Code should solve your Purpose. Just paste it in your sytem and try.

**************************************************************************************************************************

DATA: itab TYPE TABLE OF string,

text TYPE string,

linno like sy-linno,

firstname(20),

lastname(20).

data ZString(25).

ZString = 'JONH F KENNEDY'.

SPLIT ZSTRING AT SPACE into TABLE itab.

describe table itab lines linno.

loop at itab into text.

if sy-tabix eq 1.

firstname = text.

elseif sy-tabix eq linno.

lastname = text.

endif.

endloop.

Firstname will have First name and Lstname will have Last name

*************************************************************************************************************************

Hope this helps.

Vinodh Balakrishnan

Read only

Former Member
0 Likes
769

REMOVED

Edited by: John Sachs on Jan 17, 2008 2:23 PM

Read only

Former Member
0 Likes
770

You can do the following:

DATA: lv_string TYPE string,

lv_firstname TYPE string,

lv_lastname TYPE string,

lv_num TYPE i,

lv_check TYPE c.

lv_string = 'Firstname h g t Lastname'.

lv_check = lv_string(1).

  • extract first name

WHILE NOT lv_check IS INITIAL.

CONCATENATE lv_firstname lv_string(1) INTO lv_firstname.

SHIFT lv_string LEFT BY 1 PLACES IN CHARACTER MODE.

lv_check = lv_string(1).

ENDWHILE.

  • extract last name

lv_num = STRLEN( lv_string ).

lv_num = lv_num - 1.

lv_check = lv_string+lv_num(1).

WHILE NOT lv_check IS INITIAL.

CONCATENATE lv_string+lv_num(1) lv_lastname INTO lv_lastname.

SHIFT lv_string RIGHT BY 1 PLACES IN CHARACTER MODE.

lv_check = lv_string+lv_num(1).

ENDWHILE.

WRITE: / lv_lastname, ',', lv_firstname.

Regards,

Michael

Read only

0 Likes
769

good man..great answer.

i appreciate your effort.