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

dynamic SQL

Former Member
0 Likes
580

hello Gurus,

i am working on dynamic sql and somehow i am not able to understand where my sqk is going wrong. please help

here is the scenario

query is

select ( v_list ) from ( v_from ) into table <table> where <v_where> group by <gb_where>

v_list = min( marcmatnr) marcwerks

v_from = marc

v_where = marc~matnr > '1001

gb_where = marc~werks

i have checked these values in Debug which looks correct to me but it is throwing me

CX_SY_DYNAMIC_OSQL_SEMANTICS this error

i have executed this sql without dynamic query and with actual value its going fine but not with dynamic

please help!!!!

regards,

Khushy

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
522

Hi,

Try with the following piece of code.


TYPES : BEGIN OF ty_marc,
          matnr  TYPE  mara-matnr,
          werks  TYPE  marc-matnr,
        END OF ty_marc.

DATA : v_list   TYPE char40,
       v_from   TYPE char20,
       v_where  TYPE char20,
       gb_where TYPE char20.

DATA : t_marc TYPE TABLE OF ty_marc.
FIELD-SYMBOLS : <table> TYPE ANY TABLE  .

v_list   = 'MIN( marc~matnr ) marc~werks'.
v_from   = 'marc'.
v_where  = text-001.      "marc~matnr > '1001'
gb_where = 'marc~werks'.

ASSIGN t_marc TO <table>.
IF sy-subrc = 0.
  SELECT (v_list)
         FROM (v_from)
         INTO TABLE <table>
         WHERE (v_where)
         GROUP BY (gb_where).
  IF sy-subrc NE 0.
    MESSAGE i899(v1) WITH 'Error or No data found !!'
                          space
                          space
                          space.
  ENDIF.
ENDIF.

Thanks.

3 REPLIES 3
Read only

Former Member
0 Likes
522

hello,

you can not use aggregations within dynamic sql statement.

br,

dez_

Read only

Former Member
0 Likes
523

Hi,

Try with the following piece of code.


TYPES : BEGIN OF ty_marc,
          matnr  TYPE  mara-matnr,
          werks  TYPE  marc-matnr,
        END OF ty_marc.

DATA : v_list   TYPE char40,
       v_from   TYPE char20,
       v_where  TYPE char20,
       gb_where TYPE char20.

DATA : t_marc TYPE TABLE OF ty_marc.
FIELD-SYMBOLS : <table> TYPE ANY TABLE  .

v_list   = 'MIN( marc~matnr ) marc~werks'.
v_from   = 'marc'.
v_where  = text-001.      "marc~matnr > '1001'
gb_where = 'marc~werks'.

ASSIGN t_marc TO <table>.
IF sy-subrc = 0.
  SELECT (v_list)
         FROM (v_from)
         INTO TABLE <table>
         WHERE (v_where)
         GROUP BY (gb_where).
  IF sy-subrc NE 0.
    MESSAGE i899(v1) WITH 'Error or No data found !!'
                          space
                          space
                          space.
  ENDIF.
ENDIF.

Thanks.

Read only

Former Member
0 Likes
522

answers were bit helpful