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 field in select statment.

Former Member
0 Likes
1,175

Hello,

I created a report in which i have two checkboxes in the selection screen. The first checkbox is for the option to bring or not, initial purchase requisitions (BANFN) from EKPO and the second is to bring initial or not, RFQs

(ANFNR). I want the select statment to have this form:

select ...

from ekpo

into g_table

where ..

and dynamic field = " ".

Can this be done ?

i tried to put it as a string but it didnt work. (data: dynamic field type string value "EKPO-BANFN")

P.S i know that it can be by writing the same select code twice.

I just wonder if this can be done by this way

\Regards.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,139

Hey Nick,

I have more conditions than the one i said before , should all be in the lv_where_clause ?

check my code.

*************************************

DATA: G_CHBFLD type STRING.

G_CHBFLD = 'P~BANFN = '' " '.

FORM SELECT_DATA_EKPO_EKKO.

SELECT .....

FROM EKPO AS P INNER JOIN EKKO AS K

ON PEBELN = KEBELN

INTO CORRESPONDING FIELDS OF TABLE GT_EKPOEKKO

WHERE K~EBELN IN S_EBELN

AND K~AEDAT IN S_AEDAT

AND K~BSTYP IN S_BSTYP

and ( G_CHBFLD ) . -


> //DEBUGER ")" is not a valid comparison operator. comparison operator.

9 REPLIES 9
Read only

Former Member
0 Likes
1,139

Hi,

You can have a dynamic where clause for your select statement.

Do F1 on SELECT and see the documentation under "WHERE - (cond_syntax)"

Regards,

Ankur Parab

Read only

Former Member
0 Likes
1,139

Hi,

You can create the WHERE clause a a variable and construct it based on the selection criteria.

So your statement becomes;

select ...

from ekpo

into g_table

WHERE (lv_where_clause).

The variable lv_where_clause contains "FIELD1 = v_1 AND FIELD2 = v_2" etc.

Regards,

Nick

Read only

Former Member
0 Likes
1,139

This message was moderated.

Read only

Former Member
0 Likes
1,140

Hey Nick,

I have more conditions than the one i said before , should all be in the lv_where_clause ?

check my code.

*************************************

DATA: G_CHBFLD type STRING.

G_CHBFLD = 'P~BANFN = '' " '.

FORM SELECT_DATA_EKPO_EKKO.

SELECT .....

FROM EKPO AS P INNER JOIN EKKO AS K

ON PEBELN = KEBELN

INTO CORRESPONDING FIELDS OF TABLE GT_EKPOEKKO

WHERE K~EBELN IN S_EBELN

AND K~AEDAT IN S_AEDAT

AND K~BSTYP IN S_BSTYP

and ( G_CHBFLD ) . -


> //DEBUGER ")" is not a valid comparison operator. comparison operator.

Read only

0 Likes
1,139

Hi,

Try putting the whole WHERE clause in the variable,

G_CHBFLD = 'KEBELN IN S_EBELN AND KAEDAT IN S_AEDAT

AND KBSTYP IN S_BSTYPP AND 'PBANFN = '' " '.

........

FROM EKPO AS P INNER JOIN EKKO AS K

ON PEBELN = KEBELN

INTO CORRESPONDING FIELDS OF TABLE GT_EKPOEKKO

WHERE (G_CHBFLD) .

Regards,

Nick

Read only

0 Likes
1,139

WORKS for the debbuger, but it occurs a runtime error.

**************************

An exception occurred. This exception is dealt with in more detail below

. The exception, which is assigned to the class 'CX_SY_DYNAMIC_OSQL_SYNTAX',

was neither

caught nor passed along using a RAISING clause, in the procedure

"SELECT_DATA_EKPO_EKKO" "(FORM)"

.

Since the caller of the procedure could not have expected this exception

to occur, the running program was terminated.

The reason for the exception is:

The current ABAP program attempted to execute an Open SQL

statement containing a WHERE condition of the form WHERE (itab) or

WHERE ... AND (itab). The part of the WHERE condition specified at

runtime in the internal table itab contains a literal

"'" that begins with "'", but has no closing "'".

Read only

0 Likes
1,139

Hi,

Check your dynamic where clause.

Maybe you have not closed the literals with proper quotes.

Regards,

Ankur Parab

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,139

Hello,

Check if this works:

G_CHBFLD = 'K~EBELN IN S_EBELN AND K~AEDAT IN S_AEDAT
AND K~BSTYP IN S_BSTYPP AND P~BANFN = space'.

BR,

Suhas

Read only

0 Likes
1,139

Suhas

space works!

Thk you all for your replies.