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: 

Dynamic Select Statement

siongchao_ng
Contributor
0 Kudos

HI al,

I have a problem with my dynamic select statement here.

DATA lt_custom_rpt TYPE STANDARD TABLE OF yxapy_custom_rpt.

DATA a_name TYPE char40.

DATA lv_cond type char40.

CONSTANTS lv_mark TYPE c VALUE 'X'.

a_name = 'reporting'.

CONCATENATE a_name '=' lv_mark INTO lv_cond SEPARATED BY space.

SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_custom_rpt

FROM yxapy_custom_rpt

WHERE (lv_cond).

I run it from my webdynpro page and it retun error "A conditio specified at runtime has an unexected format".

However, when I revert it to the static code below, it runs fine.

SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_custom_rpt

FROM yxapy_custom_rpt

WHERE reporting = 'X'.

Anyone have any idea on how to change it to dynamic condition?

1 ACCEPTED SOLUTION

gerd_rother
Active Participant
0 Kudos

Hi,

In dynamic selects you have to put constants into apostrophes:

CONCATENATE a_name '= ''' INTO lv_cond SEPARATED BY space.
CONCATENATE lv_cond lv_mark '''' INTO lv_cond.

Regards, Gerd Rother

2 REPLIES 2

gerd_rother
Active Participant
0 Kudos

Hi,

In dynamic selects you have to put constants into apostrophes:

CONCATENATE a_name '= ''' INTO lv_cond SEPARATED BY space.
CONCATENATE lv_cond lv_mark '''' INTO lv_cond.

Regards, Gerd Rother

Former Member
0 Kudos

Hi Siong

Right now in your code : the where condition you are building is reporting = X and not reporting = 'X'.

Declare

CONSTANTS lv_mark(3) TYPE c VALUE '''X'''.

instead of

CONSTANTS lv_mark TYPE c VALUE 'X'.

Regards

Deepa