12-17-2009 3:48 PM
Hi experts.
I have a following query:
IF customer_name IS NOT INITIAL.
SELECT kunnr FROM kna1 INTO lv_kunnr
FOR ALL ENTRIES IN customer_name
WHERE
name1 = customer_name-NAME1.
endselect.
ENDIF.
Now when I just give 1 customer_name say Ajay, I should ideally get just 1 KUNNR based on that (based on the data in my system).
But I am getting multiple entries. Where is the mistake?
Thanks,
Ajay.
12-17-2009 6:44 PM
Hi,
if you have multiple entries in the internal table, your statement (for all entries) will process a select for every entry in internal table customer_name.
If you only want to select one record from the database table, you have to omit the "for all entries" clause.
select single kunnr
into lv_kunnr
from kna1
where name = customer_name-name1.
BR, Helmut
12-17-2009 4:13 PM
Because you are checking the internal table header line, not the actual table.
Rob
Edited by: Rob Burbank on Dec 17, 2009 11:27 AM
12-17-2009 4:19 PM
place [] for internal table check
IF customer_name[] IS NOT INITIAL.
SELECT kunnr FROM kna1 INTO lv_kunnr
FOR ALL ENTRIES IN customer_name
WHERE
name1 = customer_name-NAME1.
endselect.
ENDIF.
or
better use thsi way..
declare an internal table
types :
begin of ty_kna1,
kunnr type kunnr,
end of ty_kna1.
data :
it_kna1 type standard table of ty_kna1.
IF customer_name[] IS NOT INITIAL.
SELECT kunnr FROM kna1 INTO table it_kna1
FOR ALL ENTRIES IN customer_name
WHERE
name1 = customer_name-NAME1
let me know if any problem further...
regards
kumar
12-17-2009 6:44 PM
Hi,
if you have multiple entries in the internal table, your statement (for all entries) will process a select for every entry in internal table customer_name.
If you only want to select one record from the database table, you have to omit the "for all entries" clause.
select single kunnr
into lv_kunnr
from kna1
where name = customer_name-name1.
BR, Helmut