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 SQL troubles (help is very URGENT!!)

Former Member
0 Kudos
131

Hallo, SAPers!

I've met a very interesting and incomprehensible problem:

please, have a look at the code given below:

REPORT ZTMP .

tables anla.

TYPES: BEGIN OF LINE,

invnr TYPE ANLA-INVNR,

sernr TYPE ANLA-SERNR,

anlkl TYPE ANLA-ANLKL,

herst TYPE ANLA-HERST,

typbz TYPE ANLA-TYPBZ,

urwrt LIKE ANLA-URWRT,

erlbt LIKE ANEA-ERLBT,

END OF LINE.

data: ireport_data type standard table of line,

lin type line,

str(8) type c value '00000600'.

data: condition(100) type c occurs 0 with header line.

condition = 'ANLKL = str'.

select AnlaINVNR AnlaSERNR Anla~ANLKL

AnlaHERST AnlaTYPBZ Anla~URWRT from anla

into corresponding fields of table ireport_data

where <b>"ANLKL = str. *1

"(condition). *2</b>

loop at ireport_data into lin.

write lin.

endloop.

the problem is: when I use <b>1</b> variant of code I got one result - it's a correct result, but when I use <b>2</b> variant of code I get another result - incorrect, as if in this case dynamic SQL condition is not used, i.e. I get all the lines from the ANLA. What the problem can be? Probably there are any options that allow dynamic expressions?

Thanks! I'll be very grateful for the answers!

1 ACCEPTED SOLUTION

Former Member
0 Kudos
101

CONDITION is an internal table.

After setting the value in your code, add an "APPEND CONDITION." line.

Andrew

10 REPLIES 10

JozsefSzikszai
Active Contributor
0 Kudos
101

hi Drabkov,

I checked your code, it should be OK. Pls. check during debugging, what is the value of cond.

ec

0 Kudos
101

Hi,

What you can do may be is Run the SQL trace for both the conditions and check what exactly is the query that is getting executed in both the cases.

Goto ST05

Active SQL trace.

Run the program.

Deactivate the SQL Trace

Display trace.

Do this and copy the query in both cases and check the difference.

Regards,

Sesh

0 Kudos
101

I've so as you said.

sql trace in case of dynamic expression does not contain dynamic condition in the <b>where</b> clause.

Probably there are options that switch off dynamic expressions in ABAP?

Former Member
0 Kudos
101

just change this part

data: condition(100) type c occurs 0 with header line.

condition = 'ANLKL = str'.

change like this

<b>data: condition(100) type c.</b>

concatenate <b>'ANLKL' ' =' str</b> into condition separated by space.

it may work

regards

shiba dutta

Former Member
0 Kudos
101

sorry for the wrong input


data: condition(100) type c.
concatenate '''' str '''' into condition.
concatenate 'ANLKL' '=' condition into condition separated by space.
it may work


regards

shiba dutta

0 Kudos
101

<b>condition </b> should be an internal table and the program does not run.

Former Member
0 Kudos
102

CONDITION is an internal table.

After setting the value in your code, add an "APPEND CONDITION." line.

Andrew

Former Member
0 Kudos
101

Thanks guys for your help!!!

The problem is solved, but there were nuances.

Probably anyone can explain: if I append a string after every adding a condition (i.e. I append more than once) the program falls down on the <b>where</b> clause but if I make one long string with all the conditions and then append it once the program runs without problems?

0 Kudos
101

If you are going to append multiple lines, I believe the IT lines have to be defined as 72 characters long. This was the pre WAS 6.10 syntax.

New syntax is to accept a string - which is what you found to work.

Andrew

0 Kudos
101

Thanks!

I'll check it later and if so, I'll reward again!