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: 

Problem in select query

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

helmut_berger
Explorer
0 Kudos

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

3 REPLIES 3

Former Member
0 Kudos

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

Former Member
0 Kudos

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

helmut_berger
Explorer
0 Kudos

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