10-10-2008 12:12 PM
Hi All,
Can you tell me how to find/ fetch number from string?
is there any function module for this.?
for example , I have string like "+++++1000000589+++"
and I need to fetch the invoice no 1000000589 from the above string..then How to do that? Letters may come first or number may come first and latter text...
Regards,
Mrunal
10-10-2008 12:14 PM
remove all '+' using
replace all occurences of '+' in var with space
var is ur string variable
10-10-2008 12:17 PM
Use REPLACE command for alloccurance of '+' , then do a condense XXXXX no-gaps will get you the value.
10-10-2008 12:20 PM
Hi,
It's not fixed that always '+' will come , it will be any letter, any text in the string.
Regards,
Mrunal
10-10-2008 12:21 PM
You can do like this.
The below mentioned is code separate material
DO 18 TIMES.
LV_C = LV_C + 1.
LV_C1 = LV_C - 1.
IF GW_MATNR-MATNR+LV_C1(1) CN '0,1,2,3,4,5,6,7,8,9' .
IF ( ( LV_MAT EQ SPACE ) ) ." and ( lv_prefix eq space ) ) .
LV_PREFIX = 'X'.
CONCATENATE GW_TEMP-PREFIX GW_MATNR-MATNR+LV_C1(1) INTO
GW_TEMP-PREFIX.
ELSE.
LV_SUFFIX = 'X'.
CONCATENATE GW_TEMP-SUFFIX GW_MATNR-MATNR+LV_C1(1) INTO
GW_TEMP-SUFFIX.
ENDIF.
ELSEIF ( ( LV_SUFFIX EQ SPACE ) ) .
LV_MAT = 'X'.
CONCATENATE GW_TEMP-MATNR1 GW_MATNR-MATNR+LV_C1(1) INTO
GW_TEMP-MATNR1.
ELSEIF ( ( LV_MAT EQ 'X' ) ) .
CONCATENATE GW_TEMP-SUFFIX GW_MATNR-MATNR+LV_C1(1) INTO
GW_TEMP-SUFFIX.
ENDIF.
ENDDO.
10-10-2008 12:23 PM
10-10-2008 12:28 PM
Hi,
It would be better if anybody knows function module for this..
Regards,
Mrunal
10-10-2008 12:33 PM
Personally, i don't know of any. That means i need to go search for it in SE37. And oh the marvel, you can search as well.
10-10-2008 12:23 PM
Hi,
You can do the folowing way.
data : w_text(40) type c value 'GIGBIBIK12434FGII', (example)
w_strlen type i,
w_off type i.
w_strlen = strlen (w_text).
Do w_strlen times.
w_off = sy-index - 1.
if w_text+w_off(1) CA '0123456789'.
else.
w_text+w_off(1) = Space.
endif.
enddo.
condense w_text no gaps.
write w_text.
Now you will have only numbers in w_text.
Regards,
Pramod
10-10-2008 1:29 PM
Hi
No need of FM. You can code like this.
REPORT ztest .
DATA: text TYPE string VALUE 'AGTH+1000000589++++',
out 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 out text+i(1) INTO out.
ENDIF.
ENDDO.
WRITE: out.
~Asik.
10-10-2008 5:52 PM
But, imagine the string is: 'Date 12-06-2008 Invoice 10002000 text and another number 123212".
After all the searches, what will be the invoice number? 1206200810002000123212?
It can only work if the only numbers in your string represent the invoice number. That is somethinh you need to be sure of.
10-10-2008 1:59 PM
Try using regular expressions
for example
DATA text TYPE string.
DATA result_tab TYPE match_result_tab.
DATA wa_result_tab LIKE LINE OF result_tab.
text = `One123!@`.
FIND ALL OCCURRENCES OF REGEX '\d'
IN text RESULTS result_tab.
LOOP AT result_tab INTO wa_result_tab.
WRITE: / wa_result_tab-offset,wa_result_tab-length.
ENDLOOP.
here result_tab will contain offset & length of any single digit
one more option you may find usefull is [ [:digit:] ] in place of "\d"