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 find the first position of number

former_member193107
Participant
0 Kudos
1,795

Dear Expert,

How do you find the position of first occurrence number in a string?

string = 'abcde782ss'.

Thanks

1 ACCEPTED SOLUTION

thanga_prakash
Active Contributor
441

Sam Indra Try below REGEX, moff will return as 5, which means number starts from 6 and mlen will return as 3 as there are 3 continuous numbers.

DATA: moff TYPE i,
      mlen TYPE i.

FIND REGEX '([0-9]+)' IN 'abcde782ss'
     MATCH OFFSET moff
     MATCH LENGTH mlen.
4 REPLIES 4

thanga_prakash
Active Contributor
442

Sam Indra Try below REGEX, moff will return as 5, which means number starts from 6 and mlen will return as 3 as there are 3 continuous numbers.

DATA: moff TYPE i,
      mlen TYPE i.

FIND REGEX '([0-9]+)' IN 'abcde782ss'
     MATCH OFFSET moff
     MATCH LENGTH mlen.

GK817
Active Contributor
441

Hi,

This should work.


DATA text TYPE string.
text = 'YTD<J KHGYGJNKLJKKN777GLHGKLB'.
IF text CA '1234567890'.
  write:/ sy-fdpos.
ENDIF.

Sandra_Rossi
Active Contributor
0 Kudos
441

Or even:

ASSERT 4 = find_any_of( val = `wwxx7yy` sub = `0123456789` ).

(see ABAP documentation of find* search functions)

441

New thing learnt for today, thanks Sandra Rossi for sharing 🙂