Continue to explain our database operation statements:
1. Select details:
Select single: This statement selects a piece of data from the database. If you can obtain multiple pieces of data based on the query condition (where), there must be (endselect). In this case, there will be a warning (slin) in the abap syntax check, so we should try to avoid using it. You can use this instead:
Select XXX from XXX into XXX.
Exit.
Endselect.
That is to say, the premise of using this is to use the table's primary key for queries.
Select distinct: duplicate records are filtered out. Because the use of distinct will lead to a sorting operation on the database server, affecting performance, it is better to implement it in ABAP.
Select XXX from XXX into itab Where xxx.
Sort itab by XXX.
Delete adjacent duplicates from itab comparing XXX.
Select single for update: When this is used, it can prevent other transactions from updating or modifying the field, which is generally not used.
Select *: select all defined fields in the database table. If not all fields are required, avoid using this option, which may affect the performance. It is best to specify the fields you need.
Select S1 S2... SN: Specify the field you want to select.
Note: If the selected field contains the data type: string or rawstring, it cannot be used.
Select (source_text ):
A. source_text is a field. You can define a struct variable and assign the name of the field you want to select to this variable.
Data: field (10) Type C. Field = "carrid ".
Select (field) from XXX ...........
B. source_text is a string. That is to say, if you want to select multiple fields, you can add the fields concatenate to the string, and then separated by space.
Data: Rochelle S (100) type C.
Data: l_carrid like SPFLI-CARRID,
Rochelle connid like SPFLI-CONNID.
Concatenate 'carrid' connid' into l_s separated by space.
Select (l_s)
From spfli
Into (l_carrid, l_connid)
Where xxx.
Endselect.
C. source_text is an internal table. You can select one or more fields.
Data: ftab type table of string.
Append 'cityfrom' to ftab.
Append 'city' to ftab.
Select (ftab)
From spfli into XXX Where xxx.
Endselect.