Skip to Content
0
Former Member
Feb 09, 2007 at 08:02 PM

Dynamic Where clause in 4.6C [Literals allowed but not variables]

164 Views

Good afternoon-

We have a dynamic select statement that works perfectly in 4.7 ext 2, but is causing a short dump in 4.6C. The error in the short dump says:

The current ABAP/4 program attempted to execute an ABAP/4 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 an invalid

value "HDR_COMP_CODE". Literals are allowed as values, but not variables.

HDR_COMP_CODE is in incoming parameter to the function module that is calling this code. It is of type BKPF-BUKRS.

Here is the code:

DATA: BEGIN OF L_WHERE_CLAUSE OCCURS 0,

TEXT_LINE(60) TYPE C,

END OF L_WHERE_CLAUSE.

CLEAR L_WHERE_CLAUSE.

IF NOT HDR_COMP_CODE IS INITIAL.

SELECT SINGLE KTOPL

INTO LV_KTOPL

FROM T001

WHERE BUKRS = HDR_COMP_CODE.

L_WHERE_CLAUSE = 'B~BUKRS = HDR_COMP_CODE'.

APPEND L_WHERE_CLAUSE.

CLEAR L_WHERE_CLAUSE.

L_WHERE_CLAUSE = 'AND'.

APPEND L_WHERE_CLAUSE.

CLEAR L_WHERE_CLAUSE.

L_WHERE_CLAUSE = 'T~KTOPL = LV_KTOPL'.

APPEND L_WHERE_CLAUSE.

CLEAR L_WHERE_CLAUSE.

L_WHERE_CLAUSE = 'AND'.

APPEND L_WHERE_CLAUSE.

CLEAR L_WHERE_CLAUSE.

ENDIF.

L_WHERE_CLAUSE = 'T~SPRAS = SY-LANGU'.

APPEND L_WHERE_CLAUSE.

CLEAR L_WHERE_CLAUSE.

SELECT BSAKNR TTXT50

INTO (LT_GL_ACCOUNT_DATA-GL_ACCOUNT, LT_GL_ACCOUNT_DATA-DESCRIPTION)

FROM SKB1 AS B INNER JOIN SKAT AS T

ON TSAKNR = BSAKNR

WHERE (L_WHERE_CLAUSE).

APPEND LT_GL_ACCOUNT_DATA.

CLEAR LT_GL_ACCOUNT_DATA.

ENDSELECT.

This EXACT query works in 4.7, has anyone run into this, or can they tell me why I might be getting the error?

Thanks,

Andy