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

Convert packed decimal to char/string

rainer_hbenthal
Active Contributor
0 Likes
3,988

Hi,

i would like to convert a packed decimal to character variable, but i dont want to use the users profil defaults, i would like to choose whether i'm getting

1.234,56

or

1,234.56

so WRITE TO is not an option (or i missed a parameter somewhere) and i'm unable to find a function module/method where the decimal notation is X or Y.

11 REPLIES 11
Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
2,750

have you already tried this FM : /OSP/GET_DECIMAL_NOTATION

Read only

0 Likes
2,750

You misunderstood me, i dont wanna know the users defaults, i want to convert indepent from those values.

Read only

Former Member
0 Likes
2,750

Hi ,

Try the following FM;

CALL FUNCTION '/OSP/GET_DECIMAL_NOTATION'

EXPORTING

i_uname = 'SAPUSER'

IMPORTING

  • ET_RETURN =

EV_DECIMAL_NOTATION = lv_dec_not

EV_TEXT = lv_text .

When i executed;

lv_dec_not returned 'X' and

lv_text returned 1,234,567.89

Regards,

Vijay

Read only

Former Member
0 Likes
2,750

I had a bit like requirement, and I dealt with ABAP code. Even I wasnu2019t able to find a right FM for that, thus Iu2019ve done with a bit mixture of ABAP code and FM

Below is the code snippet,Please Have a look.

SELECT SINGLE * FROM usr01 WHERE bname = sy-uname.
  IF sy-subrc = 0.
    CASE usr01-dcpfm.
      WHEN ' '.
        FIND ',' IN in_par-value.
        IF sy-subrc = 0.
          REPLACE ',' WITH '.' INTO in_par-value.
        ENDIF.

        MOVE in_par-value TO i_kurrf.

      WHEN 'X'.
        FIND ',' IN in_par-value.
        IF sy-subrc = 0.
          REPLACE ',' WITH '.' INTO in_par-value.
        ENDIF.
        CALL FUNCTION 'MOVE_CHAR_TO_NUM'
          EXPORTING
            chr             = in_par-value
          IMPORTING
            num             = i_kurrf
          EXCEPTIONS
            convt_no_number = 1
            convt_overflow  = 2
            OTHERS          = 3.

      WHEN OTHERS.
        FIND ',' IN in_par-value.
        IF sy-subrc = 0.
          REPLACE ',' WITH '.' INTO in_par-value.
        ENDIF.

        MOVE in_par-value TO i_kurrf.

You may alter this code according to you.

Cheers

Read only

Former Member
0 Likes
2,750

Hi Rainer

Did you try USING EDIT MASK ?

Pushpraj

Read only

0 Likes
2,750

Where in the edit mask can i put the notation i would like to be used? Besides that, i was unable to find a edit mask which will work for every p typed varaible.

Read only

rainer_hbenthal
Active Contributor
0 Likes
2,750

data num type p decimals 2.
data str type string.

num = '3141.59'.

call some_function_module exporting notation = 'X' num = num importing str.

Depending on the notation X or Y or blank i would like to get

3.141,59 or 3,141.59. I'm searching for such a function module.

Read only

0 Likes
2,750

> Depending on the notation X or Y or blank i would like to get

> 3.141,59 or 3,141.59. I'm searching for such a function module.

That's the same thing I have done in my code above.

Why not you go with ABAP code instead of FM(Since yet we donu2019t able to find the exact FM)? Or is there any chance to create your own Z Function module which consist the above code inside the FM?

Cheers

Read only

0 Likes
2,750

Sorry our postings did overlap so i wasnt aware of yours...

i guess in_par-value is c based variable? Where did you find that snippet? SAP Standard?

Read only

0 Likes
2,750

Yep, In_par-value is C based.

And itu2019s not an SAP standard Snippet. I wrote this code from my left hand in one of the Subroutines of SAP Script.

Cheers

Read only

Former Member
0 Likes
2,750

Did you try Function C14N_NUMERIC_FORMAT ?