05-23-2012 6:02 AM
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
05-23-2012 6:42 AM
05-23-2012 6:11 AM
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
05-23-2012 6:28 AM
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.
05-23-2012 6:35 AM
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
05-23-2012 6:39 AM
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
05-23-2012 6:22 AM
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,
05-23-2012 6:42 AM
05-23-2012 6:55 AM
05-23-2012 6:56 AM
05-23-2012 7:33 AM
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.
05-23-2012 7:08 AM
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