07-10-2013 1:15 PM
Hi Experts,
I have a requirement to set decimal places dynamically based on value in a variable in sap script.
For example 1 : we have decimal variable &Dec& = 2 (Value in Dec will change dynamically)
display value &Value& = 10.255.
Output should be 10.25 based on decimal value.
For example 2 : we have decimal variable &Dec& = 3 (Value in Dec will change dynamically)
display value &Value& = 10.255.
Output should be 10.255 based on decimal value.
Thanks & Regards,
Sivaji Kankanala.
07-10-2013 2:07 PM
Hi Naidu,
A better solution would be to have additional text field in the internal table.
Use the write statement to put the value in the text field with the desired number of decimals
and output the text field instead of the numeric cheers
Regards
07-11-2013 12:13 AM
Hi, you can build a text variable, for example
PARAMETERS: p_dec TYP i.
DATA: g_num TYPE REF TO data,
g_text TYPE char15.
FIELD-SYMBOLS: <fs> TYPE any.
START-OF-SELECTION.
* Build variable
CREATE DATA g_num TYPE p DECIMALS p_dec.
* Assign variable
ASSIGN g_num->* TO <fs>.
<fs> = 10 / 3.
* Assign dynamic variable to text variable
g_text = <fs>.
CONDENSE g_text NO-GAPS.
* Check result
WRITE <fs>.
You might use this example to create a dynamic variable to pass to your sapscript, I hope help you
Regards.
DCC
10-01-2013 7:15 AM
04-07-2016 11:50 AM
Hi David,
Thanks a lot!!!
It helped me in solving an issue.
BR,
Prathyusha
07-11-2013 12:43 AM
Hi,
Have a CODE node before display and say you have the value in 10.2556 then pass the value to a global variable using you precision value in another variable using WRITE.. TO with formatting options DECIMALS. Something like
WRITE <var1> TO <var2> DECIMALS <var_dec_presion>.
Then display in node value in <var2>.
Cheers,
Arindam
07-16-2013 6:41 AM
Hi,
Have you consider FM FLTP_CHAR_CONVERSION .
Format conversion: Floating point --> Character
This is very useful in QM applications.
Regards.
07-16-2013 7:16 AM
Hi
If it you require the dynamic option between 2 decimals or 3 decimals only then do as follows. (Though I feel this may not be good solution 🙂 )
1. Create three variables l_val3 type MENGE ( quantity type with 3 decimals )
l_val2 type DMBTR ( amount type with 2 decimals )
l_val type C length 15.
2. Based on your value &DEC&
assign the value to either of the above to final value l_val and print l_val.
😕 IF &DEC& = 2
l_val2 = &your variable&
l_val = l_val2
😕 ELSE
l_val3 = &your variable&
😕 l_val = l_val3
😕 ENDIF.
😕 &l_val(RC)&
OR You have to use the format statement as &VALUE(R8.x)& where x is your dynamic positions.
Regards,
Venkat