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

Fetch number from string

Former Member
0 Likes
2,285

Hello Experts,

Can you please suggest the function module which can extract number from a string.

Eg. If I enter AB25, it returns 25.

Thanks in advance.

Ankur

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,120
10 REPLIES 10
Read only

Former Member
0 Likes
2,120

hi

if every string have same format use the offset otherwise follow the link http://scn.sap.com/thread/1680390 & for more information google it you get more help.

let me know if u have any q's.

Regards

Mahesh

Read only

0 Likes
2,120

HI

Use below code i hope it will help to you.

REPORT zmahe .

DATA: text   TYPE string VALUE 'AGTH+1000000589++++',

text1    TYPE string,

      length TYPE i,

i      TYPE i.

length = STRLEN( text ).

DO length TIMES.

  i = sy-index - 1.

  IF text+i(1) CA '0123456789'.

    CONCATENATE text1 text+i(1) INTO text1.

  ENDIF.

ENDDO.

WRITE: text1.

Regards

Mahesh.

Read only

0 Likes
2,120

Thanks Mahesh,

I am able to fetch the number from the above code. But still I would prefer if I can get some function module for this.

As I have several strings in my program and to put a loop on every string with effect the performance.

Anyway thanks a a lot for the quick help.

Ankur

Read only

0 Likes
2,120

create a zfunction module for that code whenever do u want just call it.

I hope u can understand .

<< Moderator message - point begging removed >>

Regards

Mahesh.

Message was edited by: Rob Burbank

Read only

former_member282968
Contributor
0 Likes
2,120

Dear Ankur,

Please check the below thread:

http://scn.sap.com/thread/1082034

Check the code given by Asik that would help you i guess.

With regards,

Read only

Former Member
0 Likes
2,121
Read only

0 Likes
2,120

Thanks Kartik,

This solves the purpose.

Regards

Ankur

Read only

Former Member
0 Likes
2,120

The fm is FIEB_EXTRACT_NUMBERS

Read only

0 Likes
2,120

Hi Ankur,

The FM provided by you is not working properly when string contains "^" character as shown below.

   REPORT  ZNUM_FROM_STRING_SATEESH.
types : begin of tp_tab,
        c(70) type c,
      end of tp_tab.
DATA: text   TYPE string VALUE 'AGTH1000000589hdfkl1221*!@#$34#&*123^45()',
text2    TYPE standard table of tp_tab with header line,
l_numstr type string,
CALL FUNCTION 'FIEB_EXTRACT_NUMBERS'
  EXPORTING
    i_note_to_payee       = text
  tables
    e_numbers             = text2.
If sy-subrc = 0.
  Loop at text2.
    concatenate l_numstr text2 into l_numstr.
  endloop.
  condense l_numstr.
WRITE:/ l_numstr.
endif.

It is giving output as :1000000589122134 but actual o/p should be 100000058912213412345

Use Logic given by Mahesh itself.

Read only

former_member585060
Active Contributor
0 Likes
2,120

Hi,

    You can declare a field with N type and move the string data to get the numeric data.

   DATA : v_string   TYPE string,
               v_num     TYPE n LENGTH 8.

   v_string = 'ABSCD0000123'.


v_num = v_string.

WRITE : v_num.

Thanks & Regards

Bala Krishna