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

remove comma and dots accordingly

Former Member
0 Likes
16,349

HI All,

I have a requirement to remove the commas and dots in particular string.

i hav explained like how i require the output.

note: simply if you look from last the first of special charecter is ',' then it should replace with '.' and all other ',' and '.' should be remove.

i hope this is clear.


1.200,50	should be 	1200.50
1,200.50	should be	1200.50
1200		should be	1200
1.200		should be	1.200
1,200		should be	1200
10,200.450.123	should be	10200450.123
10.200.450,123	should be	10200450.123

Can you please help me in this?

I will reward you with points.

regards

ragu.

HI All,

I have a requirement to remove the commas and dots in particular string.

i hav explained like how i require the output.

note: simply if you look from last the first of special charecter is ',' then it should replace with '.' and all other ',' and '.' should be remove.

i hope this is clear.


1.200,50	should be 	1200.50
1,200.50	should be	1200.50
1200		should be	1200
1.200		should be	1.200
1,200		should be	1200
10,200.450.123	should be	10200450.123
10.200.450,123	should be	10200450.123

Can you please help me in this?

I will reward you with points.

regards

ragu.

7 REPLIES 7
Read only

Former Member
0 Likes
5,532

Hi Raghu,

Good!

First split the string into pieces and concadinate according to ur requirments,

I hope thats the best way becasue there is no commen factors in thats strings given.

Thanks

Sunil

Read only

Former Member
0 Likes
5,532

Try:

DATA: f1(16) VALUE '10.200.450,123'.

REPLACE ALL OCCURRENCES OF '.' IN f1 WITH '~'.
REPLACE ALL OCCURRENCES OF ',' IN f1 WITH '.'.
REPLACE ALL OCCURRENCES OF '~' IN f1 WITH ','.

Rob

Read only

Former Member
0 Likes
5,532

Dear Raghu,

We can do your requirement in user level.then only apply of all functions of that perticular user level.and also this is basis people work if you have interest and knowledge you can do i will tell you how to do.

Go to SU01 and give user name and click change tab next go to defaults tab here some decimal notations availble you can choose one of from here.

Hope this will helps you

Prem.

Read only

Former Member
0 Likes
5,532

this looks like you are getting data for users with different settings for Amounts (where , space and . are used)

I have some suggestion here. Check if it helps.

Using FIND command first check if string contains both , and .

find first occurrence of '.' in l_String

results results_wa.

find first occurrence of ',' in l_String

results results_wa1.

The RESULTS_WA contains the offset of the value. Now first case is if it contains only comma, in that case first command will return zero. So your job is easy - use REPLACE command to replace ',' by space and then use COMPRESS to remove the space . This will lead to your result.

Second case where '.' is present but not ','. In this case you do not need to do anything.

Third case ',' is present first and then '.'. If you see OFFSET field of RESULT_WA. It will contain the offset value. If Offset value for second command is lesser no than that of first command result, it shows that ',' appears before '.'.In this case you can replace ',' by space and then use compress.

To get all occurrences of ',' or '.' you need to use RESULTSTAB which is an internal table, also use command

find all occurrences of ',' in l_String

results resulttab.

If you check this command in debug, you can see the appropriate results.

Put above pseudo code in program logic and it should work.

Read only

Former Member
0 Likes
5,532

Hi Raghu,

Take a character variable which can accomdate your value and do as follows.

PARAMETERS: P_INPUT(20).

DATA:
  V_OUTPUT(20),
  V_LENGTH TYPE I,
  V_LAST TYPE I.

V_LENGTH = STRLEN( P_INPUT ).
V_OUTPUT = P_INPUT.

DO V_LENGTH TIMES.
IF P_INPUT+SY-INDEX(1) = ','.
V_LAST = V_LENGTH - 1.
DO.
IF V_OUTPUT+V_LAST(1) = '.'.
V_OUTPUT+V_LAST(1) = '*'.
EXIT.
ENDIF.
V_LAST = V_LAST - 1.
IF V_LAST IS INITIAL.
TRANSLATE V_OUTPUT USING ',*'.
EXIT.
ENDIF.
ENDDO.
TRANSLATE V_OUTPUT USING ', . *.'.
CONDENSE V_OUTPUT NO-GAPS.
EXIT.
ELSEIF P_INPUT+SY-INDEX(1) = '.'.
TRANSLATE V_OUTPUT USING ',.. '.
CONDENSE V_OUTPUT NO-GAPS.
EXIT.
ENDIF.
ENDDO.

WRITE:/10 P_INPUT.
SKIP.
WRITE:/10 V_OUTPUT.

<b>Note:</b> You have many open threads. Plz close the threads if they are solved/answered. Dont put remarks as points awareded for answered questions in your post.

Thanks,

Vinay

Read only

0 Likes
5,532

HI Vinay,

Everything is working, but only 2 cases are not working.

1.200 - 1.200

1,200 - 1200

can u please let me know hwy it is happening..

Read only

0 Likes
5,532

data:
 lvr_dcpfm type xudcpfm.

  select single dcpfm
    from usr01
    into lvr_dcpfm
    where bname = sy-uname.

  case lvr_dcpfm.
    when ' '.
      replace all occurrences of '.' in my_var with space.
    when 'X'.
      replace all occurrences of ',' in my_var with space.
  endcase.
  condense my_var no-gaps.