Few distinctions between SQL selection queries that might help you.
A generic select statement (without any particular type) looks like this.
Select * from [table] where [field] = [value]
Depending on whether or not and how you specify into
clause a certain type of select is used.
into table
into table
selects one or multiple records into internal table. can only be used when your select clause (field list) is identical to structure of your internal table.
data: lt_ekko type table of ekko,
ls_ekko type table of ekko,
select * from ekko into table @lt_ekko.
loop at lt_ekko into ls_ekko.
write: / ls_ekko-ebeln.
endloop.
into
into
means you are selecting into a variable (if you are selecting 1 column) or a structure (if you are selecting more than 1). This is important, because structures can only and variables only store 1 value or row, which means you must specify that you are selecting a single
row or use select
/endselect
statements to perform looping select.
data: ls_ekko type ekko.
select single * from ekko into @ls_ekko where ebeln = [some number]
write: / ls_ekko-ebeln.
OR
select * from ekko into @ls_ekko where ebeln = [some number].
write: / ls_ekko-ebeln. "will print one for each row
endselect.
into corresponding fields of (table)
into corresponding fields of
(and into corresponding fields of table
) selects records the same way into
and into internal table
. The difference is that your structure or internal table does not have to be identical to your selected field list. Selected fields will be stored into your table/structure fields with same names.
data: ls_ekko type ekko.
select single ebeln, bukrs from ekko into @ls_ekko where ebeln = [some number].
write: / ls_ekko-ebeln.
no into
clause
no into
clause is similar to into
[structure], because it can only select 1 record. That means you have to specify that you select a single
record.
Note: Tables you are selecting from must be declared in the program to use this type of select.
select single * from ekko where ebeln = [some number].
write: / ekko-ebeln.
Since you are not using into
clause, you are using the last type, and that means you must use select single