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

Decimal Notation conversion as per user setting

Former Member
0 Likes
17,614

Hi all,

The decimal point and the u2018thousand separatoru2019 must conform the convention used that is specified in the user profile of the user who is running the program.Please let me know the standard Function Module name for the same.

Example: 1,234,567.00 (for UK user) and 1.234.567,00 (for users in France, Germany, etc).

12 REPLIES 12
Read only

Former Member
0 Likes
7,239

Hello

Two ways:

1. Table USR01. Field DCPFM.

2. BAPI_USER_GET_DETAIL. Structure DEFAULTS. Field DCPFM.

DCPFM values:

space = Decimal point is comma: N.NNN,NN

'X' = Decimal point is period: N,NNN.NN

'Y' = Decimal point is N NNN NNN,NN

Read only

0 Likes
7,239

Is there any standard Function Module available for this conversion..?

Read only

0 Likes
7,239

Hello

Use FM 'C14N_NUMERIC_FORMAT'

or SET COUNTRY statement in programm.

Working code for example:


data: fff type p decimals 3.
fff = 10000 / 3.

set country 'DE'. " Germany
write fff.

new-line.

set country 'EN'. " United Kingdom
write fff.

Read only

0 Likes
7,239

I had similar requirement for Date format conversion as per user settings. We have identified standard function module for date conversion.I am looking for standard FM for this Decimal conversion also.

Read only

0 Likes
7,239

Hello

There are no exist such FM.

As I have said you earlier - use SET COUNTRY in report.

Also check this:

Read only

Former Member
0 Likes
7,239

Hi

FM susr_get_user_defaults gives user settings,give user id in baname

Read only

Former Member
0 Likes
7,239

Hi,

Use FM CLSE_SELECT_USR01 to get the user default settings for decimal point and seperator.

Regards,

Raju.

Read only

Former Member
0 Likes
7,239

Hi , please try this FM

CALL FUNCTION 'CETA_USR01_READ'

EXPORTING

bname = sy-uname

IMPORTING

usr01_exp = gw_usr01

EXCEPTIONS

no_entry = 1

OTHERS = 2.

NOW USR01-dcpfm can have three values

IF gw_usr01-dcpfm EQ ' '.

space = Decimal point is comma: N.NNN,NN

ELSEIF gw_usr01-dcpfm EQ 'X'.

'X' = Decimal point is period: N,NNN.NN

ELSEIF gw_usr01-dcpfm EQ 'Y'.

'Y' = Decimal point is N NNN NNN,NN

hope this will solve your problem.

Regards

Prashant singh

Read only

Former Member
0 Likes
7,239

Hello,

I have already search for available FM for this functionality but haven't found any. You can use the code below.

REPORT  Z_CHANGE_QTY_TO_DECMALNOTATION.
types: begin of t_tab,
         sample_value(30) type c,
       end of t_tab.

types: begin of t_number,
         text(30)        type c,
       end of t_number.
data: i_tab  type standard table of t_tab,
      wa_tab type t_tab.

data: g_dcpfm type usr01-dcpfm.
data: g_whole(30)        type c,
      g_decimal(30)      type c,
      g_strlen           type i,
      g_ndiv             type i,
      g_nmod             type i,
      g_delimiter        type c,
      g_separator        type c,
      name(30)           type c.

initialization.
clear: g_dcpfm,
       g_whole,
       g_decimal,
       g_strlen,
       g_ndiv,
       g_nmod,
       g_delimiter,
       g_separator.

selection-screen begin of block b1.
*parameter: p_value(30) type c.
select-options: s_value for name no intervals obligatory.
selection-screen end of block b1.
*At selection-screen
Start-of-selection.

select single dcpfm
into g_dcpfm
from usr01
where bname = sy-uname.
if sy-subrc ne 0.
  g_dcpfm = space. "by default
endif.



loop at s_value.
  split s_value-low at '.' into g_whole
                                   g_decimal.
  g_strlen = strlen( g_whole ).
  g_ndiv   = g_strlen div 3.
  g_nmod   = g_strlen mod 3.

  case p_dcpfm.
    when space.
      g_delimiter = '.'.
      g_separator = ','.
      perform change_quantity using g_delimiter
                                    g_separator
                          changing s_value-low.

      concatenate s_value-low
                  g_decimal
      into s_value-low
      separated by g_separator.

    when 'X'.
      g_delimiter = ','.
      g_separator = '.'.
      perform change_quantity using g_delimiter
                                    g_separator
                          changing s_value-low.
      concatenate s_value-low
                  g_decimal
      into s_value-low
      separated by g_separator.

    when 'Y'.
      g_delimiter = space.
      g_separator = ','.
      perform change_quantity using g_delimiter
                                    g_separator
                          changing s_value-low.
      concatenate s_value-low
                  g_decimal
      into s_value-low
      separated by g_separator.
    when others.
  endcase.
  modify s_value. "from wa_tab.
endloop.

end-of-selection.
WRITE: SY-UNAME.
WRITE: G_DCPFM.

loop at s_value. "into wa_tab.
  write: / s_value-low.
endloop.

form change_quantity using p_delimiter type c
                                               p_separator type c
                                      changing p_sample_value.
data: li_number  type standard table of t_number,
      lwa_number type t_number,
      l_flag     type c.
data: l_temp     type i,
      l_previous type i,
      l_previous_text(30) type c.

refresh: li_number.
clear:   lwa_number,
         l_previous,
         l_temp,
         l_flag,
         l_previous_text.

* initially *
clear: lwa_number,
       l_temp.
if not g_nmod is initial.
  lwa_number-text = g_whole(g_nmod).
  append lwa_number to li_number.
  l_temp = g_nmod.
endif.

clear: l_previous.
do g_ndiv times.
    lwa_number-text = g_whole+l_temp(3).
    l_temp = l_previous + 3.
    l_previous = l_temp.
    append lwa_number to li_number.
    clear: lwa_number.
enddo.

clear: l_flag,
       l_previous_text.
loop at li_number into lwa_number.
if l_flag is initial.
  concatenate l_previous_text
              lwa_number-text
  into g_whole
  separated by p_delimiter.

  replace first occurrence of p_delimiter in g_whole with space.
  condense g_whole no-gaps.

  l_previous_text = g_whole.
  l_flag = 'X'.
else.
  concatenate l_previous_text
              lwa_number-text
  into g_whole
  separated by p_delimiter.
  l_previous_text = g_whole.

endif.
p_sample_value = g_whole.
endloop.

endform.

regards,

massive

Edited by: massive on Aug 20, 2009 9:58 AM

Read only

0 Likes
7,239

Hi Massive,

thanks a lot for this example. It works.

BR, Eddy

Read only

0 Likes
7,239

This message was moderated.

Read only

0 Likes
3,120

There is a bug in the FORM change_quantity. 
Eg: Please refer the below test scenario.

PraharshaReddyPV_0-1753946481215.png

Results:

PraharshaReddyPV_1-1753947026747.png

Therefore, the corrected one:
The below code will work for user selected decimal format on the selection screen. 

*&---------------------------------------------------------------------*
*& Form f_change_value
*&---------------------------------------------------------------------*
*& Change values based on user selected decimal format
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM f_change_value USING u_delimiter TYPE c
                          u_separator TYPE c
                 CHANGING c_sample_value ##PERF_NO_TYPE.

  TYPES: BEGIN OF ty_number,
           text(30) TYPE c,
         END OF ty_number.

  DATA: lv_whole(30)         TYPE c,
        lv_decimal(30)       TYPE c,
        lv_strlen            TYPE i,
        lv_ndiv              TYPE i,
        lv_nmod              TYPE i,
        lv_flag              TYPE c,
        lv_temp              TYPE i,
        lv_previous_text(30) TYPE c,
        ls_number            TYPE ty_number,
        lt_number            TYPE STANDARD TABLE OF ty_number.


  CLEAR: lt_number, ls_number, lv_temp, lv_flag, lv_previous_text, lv_whole, lv_decimal, lv_strlen, lv_ndiv, lv_nmod.

  SPLIT c_sample_value AT '.' INTO lv_whole
                                   lv_decimal.
  "Get value length without decimals
  lv_strlen = strlen( lv_whole ).
  "Divide length and get quotient
  lv_ndiv   = lv_strlen DIV 3.
  "Get remainder for length
  lv_nmod   = lv_strlen MOD 3.

  "Get remainder value length of first set of digits into table.
  IF lv_nmod IS NOT INITIAL.
    ls_number-text = lv_whole(lv_nmod).
    lv_temp = lv_nmod.
    APPEND ls_number TO lt_number.
    CLEAR: ls_number.
  ENDIF.

  "Do quotient number of times and append the 3 set digits into table.
  DO lv_ndiv TIMES.
    ls_number-text = lv_whole+lv_temp(3).
    lv_temp = lv_temp + 3.
    APPEND ls_number TO lt_number.
    CLEAR: ls_number.
  ENDDO.
  CLEAR: lv_whole.

  LOOP AT lt_number ASSIGNING FIELD-SYMBOL(<fs_number>).
    IF lv_flag IS INITIAL.
      "Assign first set of digits into variable
     lv_whole = <fs_number>-text.
      "remove spaces
      CONDENSE lv_whole NO-GAPS.
      lv_previous_text = lv_whole.
      lv_flag = abap_true.
    ELSE.
      "concatenate remaining 3 set digits
      CONCATENATE lv_previous_text <fs_number>-text INTO lv_whole
                                          SEPARATED BY u_delimiter.
      lv_previous_text = lv_whole.
    ENDIF.
    c_sample_value = lv_whole.
  ENDLOOP.
  IF lv_decimal IS NOT INITIAL.
    CONCATENATE c_sample_value lv_decimal INTO c_sample_value
                                  SEPARATED BY u_separator.
  ENDIF.
ENDFORM.