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: 

fetch first letter ex : 101th avenue.

Former Member
0 Kudos

hi Expertes,

i have high priority issue where i have vendor name where it can be like below names:

101 Computers

12th Ave Bearings

10-K Laser Printing

10 2nd Avenue Houghton Estate

if it is a number as we see above it should ignore and take the first character of the name.

ex : name : 101 computers - first letter should be 'C'.

name : 12th Ave bearings - first letter should be 'A'.

name : 10-k Laser printing - first letter should be 'L'.

so if this is the case how can i get the first letter.

if it where to be number and number i would have ignored the number but this scenario has both number and character.

how can i determine the first letter of the character in above case.

your valuble contribution is really highly appriciated.

thank you,

pasala.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello

Try like this:


data: begin of itab occurs 0,
      str(10),
      end of itab.
data: str(20),
      letter(1).
str = '10 2nd Avenue Houghton Estate'.
split str at space into table itab.
loop at itab.
  if itab-str(1) CN '01234567890'.
    letter = itab-str(1).
    exit.
  endif.
endloop.

write letter.

7 REPLIES 7

Former Member
0 Kudos

Hi Pasala

Well the way i look at it you might need to write some code to do the searching for particular text formats like if there is no space between a number and a letter then skip that string until you come across a space then you can read the 1st character. The thing is if there are mistypes you are likely to have errors, I could help you with some code but tell me what is the purpose of this?

Regards

Tatenda

0 Kudos

hi tatenda,

thank you for the reply,

the purpose of it is based on the first letter of the character... i fetch all the users from other tables.

so inorder to fetch proper users i need the first letter of the character.

thank you,

pasala.

Former Member
0 Kudos

Hello

Try like this:


data: begin of itab occurs 0,
      str(10),
      end of itab.
data: str(20),
      letter(1).
str = '10 2nd Avenue Houghton Estate'.
split str at space into table itab.
loop at itab.
  if itab-str(1) CN '01234567890'.
    letter = itab-str(1).
    exit.
  endif.
endloop.

write letter.

0 Kudos

Good one!

That should work!

SuhaSaha
Advisor
Advisor
0 Kudos

Hello Pasala,

If i understand correctly you need to pick the first alphabet after the space.

Suppose your string contains:

1st 2nd 3rd GOK Appliances

, then the output should be 'G'. Right ??

If so, you can try something like this:

DATA:
V_STR TYPE STRING,
ITAB TYPE STANDARD TABLE OF STRING,
WA TYPE STRING.

MOVE <vendor_name> TO V_STR.

SPLIT V_STR AT ` ` INTO TABLE ITAB.

LOOP AT ITAB INTO WA.
  IF WA+0(1) CO SY-ABCDE.
    WRITE: WA+0(1).
    EXIT.
  ENDIF.
ENDLOOP.

Hope this helps.

BR,

Suhas

dev_parbutteea
Active Contributor
0 Kudos

DATA :lv_var(30) TYPE c VALUE '12th Ave Bearings',

lv_len TYPE i,

lv_index TYPE sy-tabix.

lv_len = STRLEN( lv_var ) .

DO lv_len TIMES.

lv_index = sy-index - 1.

IF lv_var+lv_index(1) CA sy-abcde.

WRITE : / lv_var+lv_index(1).

EXIT.

ENDIF.

ENDDO.

kesavadas_thekkillath
Active Contributor
0 Kudos

DATA:lv_str TYPE string.

TYPES:BEGIN OF ty,
      f1 TYPE char255,
      END OF ty.
DATA:it TYPE TABLE OF ty,
     wa TYPE ty.

lv_str = '10 2nd Avenue Houghton Estate'.
SPLIT lv_str AT space INTO TABLE it.

LOOP AT it INTO wa.
  IF wa-f1 CA '1234567890'.
    CONTINUE.
  ELSE.
    WRITE wa-f1(1).
    EXIT.
  ENDIF.
ENDLOOP.