Function Reads values from a database table into an object or folder
Example myrc =
s10databaseselect(
    exporting
condition = mycondition
    changing
  folder = mycustomers ).
Format data:
  mycondition type string,
  myappend type boolean,
  mymaxrows type i,
  myorderby type string,
  myfolder type any,
  myrc type boolean.

myrc =
  s10databaseselect(
    exporting
      condition = mycondition
      append = myappend
      maxrows = mymaxrows
      orderby = myorderby
    changing
      folder = myfolder ).
Parameters
Name Type Description
condition string
SQL 'where' clause
append boolean
'X' = append rows to folder
dbtablename string
Overwrites the table name specified in the class. A join of multiple tables is also possible.
fieldlist string
Comma-separated list of database fields to read (default:all)
maxrows i
Maximum row count
orderby string
Comma separated database fields with ...- for descending
distinct  boolean
'X' = multiple value sets only once in result set
folder any
Folder (optional).
rc boolean
'X' = SQL statement executed
Description The parameter "condition" is the only mandatory parameter. It determines which rows are read from the database, i.e. it results in the where condition of the select statement. The format is identical to the format of the where condition of the ABAP Select statement with the following addition:

All expressions @XXXXX within "condition", where XXXXX is the name of a class attribute, are replaced by the respective current attribute value. Example:

s10databaseselect|LAND1 @LAND1 | )  

If the LAND1 attribute has the value "CA", LAND1 = 'CA' is used as the where condition. Please note that the apostrophe characters before and after the value are automatically added here.

The attribute name can be given in upper or lower case letters, e.g. also

s10databaseselect|LAND1 @land1 | )  

or, since in the ABAP select statement the column names can also be written in lower case,

s10databaseselect|land1 @land1 | )  

Depending on whether the "folder" parameter is specified or not, s10databaseselect( ) works differently. If "folder" is specified, a table must be passed where each row consists of an object reference to a /s10/any object. In addition, a reference to a database table must be established in the folder object class by defining a constant "dbtablename". Example:

class db_kna1 definition inheriting from /s10/any.

public section.

constants:
   
dbtablename type string value 'kna1'

s10databaseselect( ) reads all rows of the specified database table that satisfy the condition "condition", and from these the table columns for which an attribute of the same name exists in the class of the folder objects.

With an empty string as "condition" all rows of the database table are returned.

The parameter "orderby" is transmitted to the database system as the desired sort order. Likewise, the desired maximum number of rows to be read is set via the "maxrows" parameter. Example:

data:
      tabkna1 
type table of ref to db_kna1.
...

s10databaseselect
      exporting
 
           
condition condition 
            maxrows 
maxrows 
            orderby 
'land1,kunnr' 
     changing
 
            folder 
tabkna1 ).

If maxrows=1 the customer with lowest value for the country key and, within that, with lowest customer number would be returned here.

The return value of s10databaseselect() when the "folder" parameter is specified is  abap_true ('X') even if no rows were selected. In cases of syntactical errors like an invalid column name, abort occurs. Example (wrong column name "ORT1"):

If the "folder" parameter is not specified, s10databaseselect() works very similar to s10databaseread(), except that with s10databaseselect() we can specify an explicit where condition for access, while with s10databaseread() the condition is automatically derived from the key fields of the table.

If a matching table row is found, all attributes of the same name from the database are populated with the read values and the value abap_true ('X') is returned. Otherwise abap_false (' ')  is returned and no change of attribute values takes place.

The parameters "maxrows" and "append" are ignored in the case of single record access (no "folder" specified). In contrast, "orderby" is taken into account by the database system, i.e. the result set is not sorted, which would make little sense for a single row, but the desired sorting is already taken into account when determining the row to be read.
  

Components S10 Framework