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 Where clause in 4.6C [Literals allowed but not variables]

Former Member
0 Kudos

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

6 REPLIES 6

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Hi Andrew, it is specific says in the ABAP short dump.......

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

then I would have to say that variables in a dynamic WHERE clause are not allowed in 4.6c. You may have to find another way to accomplish this.

Regards,

Rich Heilman

0 Kudos

If this simple program dumps in my 46c system.



report zrich_0001.

data: it001 type table of t001 with header line.
data: where(72) type c occurs 0 with header line.

parameters: p_bukrs type t001-bukrs.


where = 'BUKRS = P_BUKRS'.
append where.


select * into table it001 from t001 where (where).

loop at it001.
write:/ it001-bukrs.
endloop.



Regards,

Rich Heilman

0 Kudos

Rich-

Thank you for your quick response. I will have to try to find another way to get those variables to become literals, or maybe I just have to break out my code so that I don't use the dynamic where clauses. It's unfortunate, but it will work.

I knew what the dump meant, but was hoping someone else had found a way to accomplish this without having to write a ton of queries without dynamic references.

Thanks,

Andy

0 Kudos

Well, in this case, unless I'm missing something, you do not requre a dynamic WHERE clause. You can use RANGES instead.



report zrich_0001.

*DATA: BEGIN OF L_WHERE_CLAUSE OCCURS 0,
*TEXT_LINE(60) TYPE C,
*END OF L_WHERE_CLAUSE.

ranges: r_bukrs for t001-bukrs.
ranges: r_ktopl for t001-ktopl.


*CLEAR L_WHERE_CLAUSE.

IF NOT HDR_COMP_CODE IS INITIAL.

clear r_bukrs. refresh r_bukrs.
r_bukrs-sign = 'I'.
r_bukrs-option = 'EQ'.
r_bukrs-low = hdr_comp_code.
append r_bukrs.


SELECT SINGLE KTOPL
INTO LV_KTOPL
FROM T001
WHERE BUKRS = HDR_COMP_CODE.

clear r_ktopl. refresh r_ktopl.
r_ktopl-sign = 'I'.
r_ktopl-option = 'EQ'.
r_ktopl-low = lv_ktopl.
append r_ktopl.


*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 B~SAKNR T~TXT50
INTO (LT_GL_ACCOUNT_DATA-GL_ACCOUNT, LT_GL_ACCOUNT_DATA-DESCRIPTION)
FROM SKB1 AS B INNER JOIN SKAT AS T
ON T~SAKNR = B~SAKNR
WHERE  b~bukrs in r_bukrs
  and  t~ktopl in r_ktopl.

APPEND LT_GL_ACCOUNT_DATA.
CLEAR LT_GL_ACCOUNT_DATA.

ENDSELECT.


Regards,

Rich Heilman

0 Kudos

In this particular instance, you are correct, I don't need it. I only gave you a small enough section of the code though to show what was going on, the dynamic portion is still useful to us in other arenas.

Thank you for the help, I appreciate it.

0 Kudos

Rich-

Your sample program helped me come up with a viable solution in 4.6C.

If I add the line:

concatenate 'BUKRS = ''' P_BUKRS '''' INTO where.

To replace:

where = 'BUKRS = P_BUKRS'.

The query works and is as dynamic as intended. Thanks for getting me on the right track.

Regards,

Andy