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

Number formatting

Former Member
0 Likes
1,104

Hi,

I want to convert numbers like 12-34*56.78/90(248) into 1234567890248

I just want to remove all the other characters/special charaters out of a number. I just want to have only the digits 0-9.

Can anyone let me know whether there is any easy way to do or function modules available for taking special characters out of a number.

Thanks.

Uma.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,073

Hi Uma,

Please try this.


REPORT ZTEST.
                                                                        
DATA: FIELD1(20) TYPE C VALUE '12-34*56.78/90(248)',
      LENGTH TYPE I.
                                                                        
LENGTH = STRLEN( FIELD1 ).
                                                                        
DO LENGTH TIMES.
  IF FIELD1(1) NA '1234567890'.
    MOVE SPACE TO FIELD1(1).
    SHIFT FIELD1 LEFT CIRCULAR.
  ELSE.
    SHIFT FIELD1 LEFT CIRCULAR.
  ENDIF.
ENDDO.
                                                                        
CONDENSE FIELD1 NO-GAPS.
WRITE FIELD1.

Regards,

Ferry Lianto

Hi,

I want to convert numbers like 12-34*56.78/90(248) into 1234567890248

I just want to remove all the other characters/special charaters out of a number. I just want to have only the digits 0-9.

Can anyone let me know whether there is any easy way to do or function modules available for taking special characters out of a number.

Thanks.

Uma.

9 REPLIES 9
Read only

Former Member
0 Likes
1,073

Use this FM:

TELNUMBER_REMOVE_SPECIAL_CHAR

Thanks,

Santosh

Read only

Former Member
0 Likes
1,073

Hi Uma,

Check the follwoing function modules:

TELNUMBER_REMOVE_SPECIAL_CHAR

SX_NUMBER_REMOVE_CHAR

Ashven

Read only

Former Member
0 Likes
1,073

data: v_number type SP_TELNO.

v_number = '12-34*56.78/90(248)'.

CALL FUNCTION 'TELNUMBER_REMOVE_SPECIAL_CHAR'

CHANGING

telnumber = v_number

.

Output = '1234567890248'.

Thanks,

Santosh

Read only

0 Likes
1,073

Hi Santosh,

Thanks for the help. I tried the function module with your code example also, it is not taking out the character '*' alone.

It's giving output as '1234*567890248'.

Thanks.

Read only

0 Likes
1,073

Hi Uma,

Of it is not working for it then to remove * you can use REPLACE satement.

REPLACE ALL OCCURRENCES OF '*' IN v_number WITH ''.

CONDENSE v_number NO-GAPS.

WRITE / v_number.

Asvhen

Read only

0 Likes
1,073

It works for me. Are you declaring the variable as data: v_number type SP_TELNO.

You can just try executing the FM 'TELNUMBER_REMOVE_SPECIAL_CHAR' in SE37 also by giving the value '12-34*56.78/90(248)'.

The output it gives is 1234567890248.

Thanks,

Santosh

Thanks,

Santosh

Message was edited by:

SKJ

Read only

0 Likes
1,073

Why don't you try Ferry's solution?

Read only

Former Member
0 Likes
1,074

Hi Uma,

Please try this.


REPORT ZTEST.
                                                                        
DATA: FIELD1(20) TYPE C VALUE '12-34*56.78/90(248)',
      LENGTH TYPE I.
                                                                        
LENGTH = STRLEN( FIELD1 ).
                                                                        
DO LENGTH TIMES.
  IF FIELD1(1) NA '1234567890'.
    MOVE SPACE TO FIELD1(1).
    SHIFT FIELD1 LEFT CIRCULAR.
  ELSE.
    SHIFT FIELD1 LEFT CIRCULAR.
  ENDIF.
ENDDO.
                                                                        
CONDENSE FIELD1 NO-GAPS.
WRITE FIELD1.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
1,073

Thanks Ferry Lianto , Asvhen, Santosh!

Uma.