2020 Sep 10 1:48 PM
Hi Experts,
I have requirement to convert from char field value to decimal.
Example -
char type field value = 314500
i want to convert it to decimal with 2 mean my expected result should - 3145.00
I tried to use pack syntax but in side class method pack will not work, anyone can suggest.
Thanks
2020 Sep 11 7:19 AM
see whether it makes sense to your scenario? attached image has output in console.
data: lv_value_char type char10 value '314500',
lv_value_dec type p DECIMALS 2,
clear: lv_value_dec.
lv_value_dec = lv_value_char / 100.
2020 Sep 10 2:06 PM
Hi,
Try with FM - WSAF_CONV_STRING_TO_DECIMAL this will solve the requirement...
2020 Sep 10 3:07 PM
Hi Abinath,
I tried FM- WSAF_CONV_STRING_TO_DECIMAL but confused with parameter values. Can you please help on this.
Thanks
2020 Sep 10 9:40 PM
PACK was useful for handling currency amounts, because SAP stores the currency amounts in the database with a floating decimal point (i.e. it ignores the number of decimals of the column).
If you want to interpret 314500 (database value) as an amount in a currency with 2 decimals like EUR or USD (and many others), you may use CL_ABAP_DECFLOAT:
DATA: curr TYPE p LENGTH 9 DECIMALS 2,
decfloat34 TYPE decfloat34.
decfloat34 = 314500.
cl_abap_decfloat=>convert_decfloat_to_curr(
EXPORTING
amount_decfloat = decfloat34
cuky = 'EUR'
IMPORTING
amount_curr = curr ).
ASSERT curr = 3145.
2020 Sep 11 7:19 AM
see whether it makes sense to your scenario? attached image has output in console.
data: lv_value_char type char10 value '314500',
lv_value_dec type p DECIMALS 2,
clear: lv_value_dec.
lv_value_dec = lv_value_char / 100.
2022 Jan 19 3:01 PM
if you set the value of lv_value_char to 17886200 ,
then you will face the error
can you check.