Entering content frame

Reading Data Locate the document in its SAP Library structure

The Open SQL statement for reading data from database tables is:

SELECT      result
  INTO      target
  FROM      source
  [WHERE    condition]
  [GROUP BY fields]
  [HAVING   cond]
  [ORDER BY fields].

The SELECT statement is divided into a series of simple clauses, each of which has a different part to play in selecting, placing, and arranging the data from the database.

This graphic is explained in the accompanying text




SELECT result

The SELECT clause result defines the structure of the data you want to read, that is, whether one line or several, which columns you want to read, and whether identical entries are acceptable or not.

INTO target

The INTO clause determines the target area target into which the selected data is to be read.

FROM source

The FROM clause specifies the database table or view the source from which the data is to be selected. It can also be placed before the INTO clause.

WHERE cond

The WHERE clause specifies which lines are to be read by specifying conditions for the selection. 

GROUP BY fields

The GROUP-BY clause produces a single line of results from groups of several lines. A group is a set of lines with identical values for each column listed in fields.


The HAVING clause sets logical conditions for the lines combined using GROUP BY.

ORDER BY fields

The ORDER-BY clause defines a sequence fields for the lines resulting from the selection.

The individual clauses and the ways in which they combine are all very important factors in the SELECT statement. Although it is a single statement like any other, beginning with the SELECT keyword and ending with a period, its division into clauses, and the ways in which they combine, make it more powerful than other statements. A single SELECT statement can perform functions ranging from simply reading a single line to executing a very complicated database query.

You can use SELECT statements in the WHERE and HAVINGclauses. These are called subqueries.

You can decouple the INTO clause from the SELECT statement by reading from the database using a cursor.

On certain database systems, this can result in lock conflicts, even with pure read access; these can be prevented by using database commits.



Leaving content frame