2007 Aug 24 7:54 AM
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!
2007 Aug 24 9:26 AM
CONDITION is an internal table.
After setting the value in your code, add an "APPEND CONDITION." line.
Andrew
2007 Aug 24 8:44 AM
hi Drabkov,
I checked your code, it should be OK. Pls. check during debugging, what is the value of cond.
ec
2007 Aug 24 8:50 AM
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
2007 Aug 24 9:16 AM
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?
2007 Aug 24 8:53 AM
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
2007 Aug 24 9:02 AM
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
2007 Aug 24 9:06 AM
<b>condition </b> should be an internal table and the program does not run.
2007 Aug 24 9:26 AM
CONDITION is an internal table.
After setting the value in your code, add an "APPEND CONDITION." line.
Andrew
2007 Aug 24 10:24 AM
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?
2007 Aug 24 10:38 AM
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
2007 Aug 24 10:48 AM