Application Development 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: 

Syntax issue in advacne SQL

former_member189779
Active Contributor

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".

1 ACCEPTED SOLUTION

Former Member

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
         ).
2 REPLIES 2

Former Member

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
         ).

horst_keller
Product and Topic Expert
Product and Topic Expert

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 ...