08-03-2017 9:42 AM
Hello,
I am writing a simple expression as below,
DATA lv_dis TYPE netwr.
START-OF-SELECTION.
lv_dis = '0.10'.
SELECT vbeln AS order,
audat AS date,
netwr AS price,
kunnr AS customer,
netwr - ( netwr * @lv_dis )
FROM vbak
INTO TABLE @DATA(lt_result).
cl_demo_output=>display_data(
value = lt_result
).
I am getting syntax error as "DescriptionResourcePathLocationType The maximum possible number of places in the expression starting with NETWR is 32 places with 4 decimal places. There can be, however, no more than 31 places and 14 decimal places. any subexpressions. ABAP Syntax Check Problem".
08-03-2017 10:37 AM
Hi,
Try like the below query: <removed by moderator>
DATA lv_dis TYPE netwr.
START-OF-SELECTION.
lv_dis = '0.10'.
SELECT vbeln AS order,
audat AS date,
netwr AS price,
kunnr AS customer,
cast( netwr - ( netwr * @lv_dis ) as curr( 15, 2 ) ) as net_value
FROM vbak
INTO TABLE @DATA(lt_result).
cl_demo_output=>display_data(
value = lt_result
).
08-03-2017 10:37 AM
Hi,
Try like the below query: <removed by moderator>
DATA lv_dis TYPE netwr.
START-OF-SELECTION.
lv_dis = '0.10'.
SELECT vbeln AS order,
audat AS date,
netwr AS price,
kunnr AS customer,
cast( netwr - ( netwr * @lv_dis ) as curr( 15, 2 ) ) as net_value
FROM vbak
INTO TABLE @DATA(lt_result).
cl_demo_output=>display_data(
value = lt_result
).
08-03-2017 11:30 AM
Hmm, I'd rather say, it might be a bug that CAST prevents the syntax error.
The documentation says:
If a decimal expression is specified statically, the syntax check checks that the result of each operation is in the value range of the type DEC with length 31 and a maximum of 14 decimal places. If any operands are specified that could produce other values, a syntax error occurs. If the expression is specified dynamically, an exception of the class CX_SY_DYNAMIC_OSQL_SEMANTICS is raised in this case.
Therefore:
DATA pack TYPE p LENGTH 16 DECIMALS 2.
SELECT FROM demo_expressions
FIELDS @pack * @pack AS test "<-- Syntax error
INTO TABLE @DATA(tab).
SELECT FROM demo_expressions
FIELDS CAST( @pack * @pack AS DEC( 15, 2 ) ) AS test "<-- No syntax error ???
INTO TABLE @DATA(tab).
Why should the CAST influence the above rule?
Forwarded to development ...