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

How to find the first position of number

Former Member
0 Kudos
3,446

Dear Expert,

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

string = 'abcde782ss'.

Thanks

1 ACCEPTED SOLUTION
Read only

ThangaPrakash
Active Contributor
2,092

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
Read only

ThangaPrakash
Active Contributor
2,093

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.
Read only

GK817
Active Contributor
2,092

Hi,

This should work.


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

Sandra_Rossi
Active Contributor
0 Kudos
2,092

Or even:

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

(see ABAP documentation of find* search functions)

Read only

2,092

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