Application Development 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: 

Converting number

Former Member
0 Kudos

Dear All,

I have to change number i.e 34567897 to 3,45,67,897 (, seperated), please help me is there any standard f.M or any way to do it.

Thanks in advance,

RRK.

1 ACCEPTED SOLUTION

franois_henrotte
Active Contributor
0 Kudos
WRITE w_value USING EDIT MASK  '_,__,__,___'.
21 REPLIES 21

franois_henrotte
Active Contributor
0 Kudos
WRITE w_value USING EDIT MASK  '_,__,__,___'.

0 Kudos

Use function module "WOSI_CONVERT_STRING_TO_NUM"

Pass values as follows

P_ACTION : 2J

P_STRING_100 : Input Value

Output value "P_SWERT" will have the value in the format required by you.

Regards

Vinod

0 Kudos

Hi François Henrotte

With your suggestion my problem resolved, thanks for the same. Points awarded.

Thanks and regards,

RRK.

arunprakash_karuppanan
Active Contributor
0 Kudos

Hi,

For fun, you can try doing it the hard way.


Data: lt_string type stringtab,
         lv_temp type string,
         lv_int type int4,
        lv_itemp type i.

*assume initial value to be converted is in lv_int.
if lv_int ge 1000.
 lv_1000 = 'X'.
endif.

while lv_int is not initial.
if lv_1000 = 'X'.
 lv_itemp = lv_int mod 1000.
 if lv_itemp is initial.
  lv_temp = '000'.
else.
lv_temp = lv_itemp.
endif.
insert lv_temp into lt_string index 1.
lv_int = lv_int div 1000.
clear lv_1000.
endif.

if lv_int ge 100.

 lv_itemp = lv_int mod 100.
 if lv_itemp is initial.
  lv_temp = '00'.
else.
lv_temp = lv_itemp.
endif.
insert lv_temp into lt_string index 1.
lv_int = lv_int div 100.
endif.

else.

lv_temp = lv_int.
insert lv_temp into lt_string index 1.
lv_int = 0. "or use exit to break loop
endif.

endwhile.

concatelate lines of lt_string into lv_string separated by ','.

*final result.

Regards,

Arun Prakash

satyajit_mohapatra
Active Contributor
0 Kudos

Is it a currency field? If yes, you can use FM HRCM_AMOUNT_TO_STRING_CONVERT.

Otherwise use the statement

WRITE WF_PRICE TO WF_PRICE_STR decimals 0 .

The target field should be of character type.

0 Kudos

Hi Satyajit,

It is a amount but type is char, now i have to display this amount with , or .

37,23,345 instead of 3723345

0 Kudos

Have you tried the function module "WOSI_CONVERT_STRING_TO_NUM"

Regards

Vinod

0 Kudos

Yes, i tried its not working when i am using it in my code.

0 Kudos

hi

Try this one,and pass currency also.

FITP_RFC_TRANSLATE_AMOUNT

0 Kudos

Hi Dharma,

This is not working.

0 Kudos

hi

Try this

ISM_CONVERT_CHAR_TO_DEC

which version you are using?

0 Kudos

Iam using SAP ECC 6.0

I tried with this ISM_CONVERT_CHAR_TO_DEC

still half problem solved. i.e if i pass 3456789123 iam getting like this 34567.89123 seperating by only one decimal.

Any clue.

Former Member
0 Kudos

hi,

write it like this.


DATA : len type i,
           num type i.  " your number 

len = strlen( num ).
num1 = num.
case len.

when 4.
num = '_,___'.
when 5.
num = '__,___'.
when 6.
num = '_,__,___'.
when 7.
num = '__,__,___'.
endcase.
write: num1 right-justified using edit mase num.

thanks and regards,

tanmaya

former_member248447
Participant
0 Kudos

Hi

Use a write statement with addition currency key,

For Example

Write amount to amount currency 'USD' where amount is of type character..you will get it the result in the desired format

Thanks

Rajesh

0 Kudos

Hi Raj,

I have written like this

DATA: MSG TYPE CHAR30.

Write MSG to MSG currency 'USD'.

still problem persists, help me out if any thing wrong here.

0 Kudos

Hi,

Move that character value into a currency field, you will get the desired format.

DATA: m type char30 VALUE '1234',

m1 TYPE dmbtr.

WRITE m to m CURRENCY 'USD'.

m1 = m.

write m1.

Thanks!!

Rajesh

0 Kudos

Hello,

How about something like this?


data: var type char30 VALUE '3456789123',
      var1 type p.

var1 = var.
write: var1.

vikranth

0 Kudos

Hi Ravi,

Plesae refer the thread [;.

0 Kudos

Hi Ravimani have u tried with François Henrotte's solution. I think it is the best solution and easy to use. You can do easily by edit mask what ever , is needed.

0 Kudos

Ravi try this,

REPORT YTEST.

data : n1 type i VALUE '34567897'.

INITIALIZATION.

AT SELECTION-SCREEN.

START-OF-SELECTION.

write : n1.

when i executed this i got result as below.

test pgm

34,567,897

Edited by: Sivaprasad ML on Apr 9, 2010 11:08 AM

Former Member
0 Kudos

Hello Ravimani,

I think you should look into the solution provided by both François Henrotte and gundapaneni raj.

If you know the exact way you want to format like in your case n,nn,nn,nnn then do what François adviced:

WRITE w_value USING EDIT MASK '_,__,__,___'.

If however you don't know the exact format and lets say that you want to convert a char field to currency then

gundapaneni raj suggestion. move your source field into a currency field. This will get you a desired format and then use the currency option while writing.

Cheers!

Neeraj