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

Dynpro field values conversion

Former Member
0 Likes
1,404

Hi,

I'm using FM DYNP_READ_VALUES to get actual values from the screen. The problem is, the fieldvalue component of the output structure is of type CHAR, but the dynpro field is of type DEC, and I'm getting exception CX_SY_CONVERSION_NO_NUMBER when I'm trying to move the dynpro value ie. '46,20' to global variable of type DEC. Any way how to solve this?

Thanks in advance,

Regards,

Tomas

1 ACCEPTED SOLUTION
Read only

venkatesan_nagiah
Active Participant
0 Likes
1,104

Hi Tomas,

you can use the following code:

-


DATA: L_FIELDFALUE(5) TYPE C VALUE '46,20',

OUTPUT(5) TYPE P DECIMALS 2,

L_DCPFM TYPE USR01-DCPFM.

*select the number notation format

SELECT SINGLE DCPFM INTO L_DCPFM FROM USR01 WHERE

BNAME = SY-UNAME.

CALL FUNCTION 'AMOUNT_STRING_CONVERT'

EXPORTING

AMOUNT_STRING = L_FIELDFALUE

DCPFM = L_DCPFM

WAERS = 'INR' " pass your countrys' currency

IMPORTING

AMOUNT = OUTPUT.

-


You can also use following function modules for different type of conversion:

AMOUNT_STRING_CONVERT

DATE_STRING_CONVERT

PERIOD_STRING_CONVERT

PRICE_STRING_CONVERT

UNITS_STRING_CONVERT

6 REPLIES 6
Read only

Former Member
0 Likes
1,104

HI,

You can do this way..

DATA l_val type i.
DATA l_fieldvalue(10) type c value '45,20'.  " values as returned from th FM

Replace ',' in l_fieldvalue with space.
Condense l_fieldvalue.

l_val = l_fieldvalue.
l_paramenter = l_val / 100.  " l_parameter is the screen field and now you have 45.20 as value
" you can change 100 as per the number of decimals

Read only

0 Likes
1,104

Hi,

thanks for fast reply.

Yes I know I could "hack" it this way, but I was thinking of a more generic way, which would be suitable for other data types as well, ie. QUAN etc, independently of my language environment (Czech in my case, that's why numeric format is like '45,20').

Thanks again.

Regards,

Tomas

Read only

0 Likes
1,104

HI,

Then check this FM HRCM_STRING_TO_AMOUNT_CONVERT this will solve the problem.

DATA: l_char TYPE char10 VALUE '10,000.54'.
DATA l_betrg TYPE betrg.

CALL FUNCTION 'HRCM_STRING_TO_AMOUNT_CONVERT'
  EXPORTING
    string              = l_char
    decimal_separator   = '.'
    thousands_separator = ','
    waers               = 'INR'
  IMPORTING
    betrg               = l_betrg
  EXCEPTIONS
    convert_error       = 1.

WRITE l_betrg.

Read only

venkatesan_nagiah
Active Participant
0 Likes
1,105

Hi Tomas,

you can use the following code:

-


DATA: L_FIELDFALUE(5) TYPE C VALUE '46,20',

OUTPUT(5) TYPE P DECIMALS 2,

L_DCPFM TYPE USR01-DCPFM.

*select the number notation format

SELECT SINGLE DCPFM INTO L_DCPFM FROM USR01 WHERE

BNAME = SY-UNAME.

CALL FUNCTION 'AMOUNT_STRING_CONVERT'

EXPORTING

AMOUNT_STRING = L_FIELDFALUE

DCPFM = L_DCPFM

WAERS = 'INR' " pass your countrys' currency

IMPORTING

AMOUNT = OUTPUT.

-


You can also use following function modules for different type of conversion:

AMOUNT_STRING_CONVERT

DATE_STRING_CONVERT

PERIOD_STRING_CONVERT

PRICE_STRING_CONVERT

UNITS_STRING_CONVERT

Read only

0 Likes
1,104

Venkatesan Nagiah,

FM you suggested are exactly what I need, thanks a lot. They work perfectly.

Thanks all others as well.

Regards,

Tomas

Read only

Former Member
0 Likes
1,104

Hi,

Try the PACK statement.

[http://help.sap.com/saphelp_47x200/helpdata/EN/87/56d00722c011d2954a0000e8353423/content.htm]

regards,

Advait