Skip to Content
avatar image
Former Member

Converting number

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.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

6 Answers

  • Best Answer
    Apr 08, 2010 at 09:42 AM
    WRITE w_value USING EDIT MASK  '_,__,__,___'.
    Add comment
    10|10000 characters needed characters exceeded

  • Apr 08, 2010 at 10:03 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 08, 2010 at 10:09 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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.

  • avatar image
    Former Member
    Apr 08, 2010 at 10:39 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 08, 2010 at 12:56 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

  • avatar image
    Former Member
    Apr 08, 2010 at 03:25 PM

    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

    Add comment
    10|10000 characters needed characters exceeded