2007 Oct 03 4:32 PM
Hi all,
Could you please tell me how to pick only numeric value from character string. Is any function module available?
Thanks in advance.
Regards,
Balaji Viswanath.
2007 Oct 03 5:00 PM
Hi,
I am not sure about FM but you can try this.
DATA: TEXT TYPE STRING VALUE '1ABCD2345EFGH',
AMOUNT TYPE STRING,
NUM TYPE I.
NUM = STRLEN( TEXT ).
DO NUM TIMES.
IF TEXT(1) CA '0123456789'.
CONCATENATE AMOUNT TEXT(1) INTO AMOUNT.
CONDENSE AMOUNT NO-GAPS.
ENDIF.
SHIFT TEXT LEFT CIRCULAR.
ENDDO.
WRITE AMOUNT.
Regards,
Ferry Lianto
Hi,
I am not sure about FM but you can try this.
DATA: TEXT TYPE STRING VALUE '1ABCD2345EFGH',
AMOUNT TYPE STRING,
NUM TYPE I.
NUM = STRLEN( TEXT ).
DO NUM TIMES.
IF TEXT(1) CA '0123456789'.
CONCATENATE AMOUNT TEXT(1) INTO AMOUNT.
CONDENSE AMOUNT NO-GAPS.
ENDIF.
SHIFT TEXT LEFT CIRCULAR.
ENDDO.
WRITE AMOUNT.
Regards,
Ferry Lianto
2007 Oct 03 4:39 PM
What I would do is grab the string and check is character by assign it to a type i variable. Using Try Catch you can catch the exception raised and then discard that value. If the assignment is successfully then you will be touching a number.
Hope it helps.
CL
2007 Oct 03 4:46 PM
u can assign the character variable(type c) to a numeric value(type n) this assignment ignores the non-numeric values in the character variable and only moves numeric values to the target variable.
REPORT ztest.
DATA:
w_char(10) type c value '123*4%56',
w_num(10) type n.
w_num = w_char.
write w_num.
<b>Result:0000123456</b>
2007 Oct 03 5:00 PM
Hi,
I am not sure about FM but you can try this.
DATA: TEXT TYPE STRING VALUE '1ABCD2345EFGH',
AMOUNT TYPE STRING,
NUM TYPE I.
NUM = STRLEN( TEXT ).
DO NUM TIMES.
IF TEXT(1) CA '0123456789'.
CONCATENATE AMOUNT TEXT(1) INTO AMOUNT.
CONDENSE AMOUNT NO-GAPS.
ENDIF.
SHIFT TEXT LEFT CIRCULAR.
ENDDO.
WRITE AMOUNT.
Regards,
Ferry Lianto
| User | Count |
|---|---|
| 6 | |
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |