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

initial of strings

Former Member
0 Likes
1,943

variable = 'NEW YORK'.

now i want only NY into another variable.

That mean starting N and if there is a space between 2 words then i want starting of that 1.

variable = 'NEW YORK'.

now i want only NY into another variable.

That mean starting N and if there is a space between 2 words then i want starting of that 1.

11 REPLIES 11
Read only

Former Member
0 Likes
1,652

split variable at '' into v_str1 v_str2 .

concatenate v_str10(1) v_str20(1) into v_new.

Read only

0 Likes
1,652

ok that is working

what is there is no space i.e., if i get only 1 word

Case 1: 'New York'. requirement is get NY

Case 2: 'Florida' requirement is get FL

Can you please take look of it

Read only

Former Member
0 Likes
1,652

hi,

You can try that.

len = strlen(string).

do len times.
w_in = sy-index.
if string+w_in(1) = space.
w_ind = w_in.
add 1 to w_ind.
concatenate substr string+w_ind(1) into substr.
endif.
enddo.

SUBSTR will contain Initials.

Regards

Sumit Agarwal

Read only

0 Likes
1,652

ok that is working

what is there is no space i.e., if i get only 1 word

Case 1: 'New York'. requirement is get NY

Case 2: 'Florida' requirement is get FL

Can you please take look of it

Read only

Former Member
0 Likes
1,652

Hi Dear


DATA  :  V_VERIABLE  TYPE STRING.
DATA  :  V_VER_NEW   TYPE STRING.

DATA  :  ITAB TYPE TABLE OF STRING.
DATA  :  WTAB TYPE STRING.

V_VERIABLE = 'New York TEST TEXT'.

SPLIT V_VERIABLE AT SPACE INTO : TABLE ITAB.

LOOP AT ITAB INTO WTAB.

CONCATENATE V_VER_NEW WTAB(1) INTO V_VER_NEW.
ENDLOOP.


WRITE:/ V_VER_NEW.

Rewards if useful.

Read only

0 Likes
1,652

ok that is working

what is there is no space i.e., if i get only 1 word

Case 1: 'New York'. requirement is get NY

Case 2: 'Florida' requirement is get FL

Can you please take look of it

Read only

0 Likes
1,652

can you check if table T005S (with country = US) does contain what you need?

Read only

Former Member
0 Likes
1,652

hiiii

if your requirement is for getting short name from any word then only way is use OFFSET for every word..

like for florida use like w_short = 0(2).

regards

twinkal

Read only

0 Likes
1,652

wht if its Louisiana?? its LA for louisiana.

ur approach is wrong. u must search for something that is SAP-defined..

pk

Read only

Subhankar
Active Contributor
0 Likes
1,652

Please do it in this way

data: l_str1 TYPE string,

l_str2 TYPE string,

l_str3 TYPE string,

l_out TYPE char04.

l_str1 = 'ABC XYZ'.

SPLIT l_str1 at space INTO l_str2 l_str3.

if l_str3 is INITIAL.

l_out = l_str2(1).

else.

CONCATENATE l_str2(1) l_str3(1) INTO l_out.

endif.

WRITE : l_out.

Read only

Former Member
0 Likes
1,652

Dear Syed

change my previous code as bellow.


DATA  :  V_VERIABLE  TYPE STRING.
DATA  :  V_VER_NEW   TYPE STRING.
DATA  :  V_DBCNT     TYPE SY-DBCNT.

DATA  :  ITAB TYPE TABLE OF STRING.
DATA  :  WTAB TYPE STRING.

V_VERIABLE = 'Florida'.

SPLIT V_VERIABLE AT SPACE INTO : TABLE ITAB.

DESCRIBE TABLE ITAB LINES V_DBCNT.
IF V_DBCNT > 1.
LOOP AT ITAB INTO WTAB.
CONCATENATE V_VER_NEW WTAB(1) INTO V_VER_NEW.
ENDLOOP.
ELSE.
V_VER_NEW = V_VERIABLE(2).
ENDIF.

WRITE:/ V_VER_NEW.

Rewards if helpful.