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

FM to pick only numeric value from char string

Former Member
0 Likes
4,938

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,618

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

3 REPLIES 3
Read only

Former Member
0 Likes
1,618

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

Read only

Former Member
0 Likes
1,618

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>

Read only

Former Member
0 Likes
1,619

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