ABAPFROM_CLAUSE - FROM CLAUSE

BAL Application Log Documentation   SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up  
This documentation is copyright by SAP AG.

SELECT - source

Short Reference



Syntax

... FROM { {dbtab [AS tabalias]}
         | join
         | {(dbtab_syntax) [AS tabalias]} }
         [UP TO n ROWS]
         [CLIENT SPECIFIED]
         [BYPASSING BUFFER]
         [CONNECTION {con|(con_syntax)}] ... .

Alternatives:

1. ... dbtab [AS tabalias]

2. ... join

3. ... (dbtab_syntax) [AS tabalias]

Additions

1.... UP TO n ROWS

2.... CLIENT SPECIFIED

3.... BYPASSING BUFFER

Effect

Entries in source specify whether a database table or aview, or whether multiple database tables or views are accessed by ajoin expression. Optional additions execute theclient handling, specify whether theSAP buffering is avoided, and determine the maximum number of rows to be read.

Alternative 1

... dbtab [AS tabalias]


Effect

A database table or a view defined in the ABAP Dictionary can be specified for dbtab. An alternativetable name tabalias can be assigned to the database table or the view using the addition AS. This name can have a maximum of 14 characters and is valid during the SELECT statement only. It must be used in all other locations instead of the actual name.

Note

If a database table or a view appears multiple times after FROM in a join expression, you must use the alternative name to avoid ambiguities.

Example

Reading from the database table spfli and assigning the alternative name s. In this case,the specification of the prefix s~ after ORDER BY can also be omitted, because only onedatabase table is read and the column name carrid is unique. The prefix spfli~ can no longer be used when assigning the alternative name.

DATA wa TYPE spfli.

SELECT *
       FROM spfli AS s
       INTO wa
       ORDER BY s~carrid.
  WRITE: / wa-carrid, wa-connid.
ENDSELECT.

Alternative 2

... join


Effect

Specification of a Join expression that links several database tables or views with one another.

Alternative 3

... (dbtab_syntax) [AS tabalias]


Effect

Instead of static specifications, a data object dbtab_syntax can be specified in brackets. Whenexecuting the statement, it must contain the syntax displayed during the static specification. The data object dbtab_syntax can be a character-type data object or astandard table withoutsecondarytable keys and with a character-type data object. The syntax in dbtab_syntax is not case-sensitive as in the ABAP Editor. The syntax can be spread over many rows when specifying an internal table.

The addition AS can be specified only if dbtab_syntax exclusively contains the name ofa single database table or a view. The addition has the same meaning for this database table or view as in a static specification.

When specifying the syntax in dbtab_syntax, the following restrictions apply:

  • Only a list of fields and no selection table can be specified in a join condition after the language element IN.
  • No database table containing columns of the type RAWSTRING, SSTRING, or STRING can be used in a join expression.

Note

If dbtab_syntax is an internal table with aheader line, the header line and not thetable body is evaluated.

Example

Displaying the flight connections (flight date, airline name, and flight number) for the user entry of a departure and a destination location. The innerjoins are dynamically set up at runtime. The column specification after SELECT is also dynamic.

PARAMETERS: p_cityfr TYPE spfli-cityfrom,
            p_cityto TYPE spfli-cityto.

DATA: BEGIN OF wa,
         fldate TYPE sflight-fldate,
         carrname TYPE scarr-carrname,
         connid   TYPE spfli-connid,
       END OF wa.

DATA itab LIKE SORTED TABLE OF wa
              WITH UNIQUE KEY fldate carrname connid.
DATA: column_syntax TYPE string,
      dbtab_syntax TYPE string.

column_syntax = `c~carrname p~connid f~fldate`.

dbtab_syntax = `( ( scarr AS c `
  & ` INNER JOIN spfli AS p ON p~carrid  = c~carrid`
  & ` AND p~cityfrom = p_cityfr`
  & ` AND p~cityto   = p_cityto )`
  & ` INNER JOIN sflight AS f ON f~carrid = p~carrid `
  & ` AND f~connid = p~connid )`.

SELECT (column_syntax)
       FROM (dbtab_syntax)
       INTO CORRESPONDING FIELDS OF TABLE itab.

LOOP AT itab INTO wa.
  WRITE: / wa-fldate, wa-carrname, wa-connid.
ENDLOOP.

Example

Refer toSELECT, dynamic token input

Addition 1

... UP TO n ROWS

Effect

This addition restricts the number of rows in the result set. A data object of type i is expectedfor n. A positive number in n indicates the maximum number of rows in the result set.If n contains the value 0, all selected rows are passed to the result set. If n contains a negative number, an exception that cannot be handled is raised.

Notes

  • The use of the UP TO n ROWS addition is preferred to a SELECT loop, which is terminated once n rows have been read. In the latter case, the lastpackage transferred from the database to the application server usually contains superfluous rows.
  • If the addition ORDERBY is also specified, the rows of the hit list are sorted on the database server and only the numberof sorted rows specified in n are passed to the result set. If the addition ORDER BY isnot specified, n arbitrary rows that meet the WHERE condition are passed to the result set.
  • If the addition FORALL ENTRIES is also specified, all selected rows are first read into an internal system tableand the addition UP TO n ROWS does not take effect until the rows are transferred from the system table to the actual target area. This can result in unexpected memory bottlenecks.

Example

Reading the three commercial customers with the highest discount rates:

DATA: wa_scustom TYPE scustom.

SELECT *
       FROM scustom UP TO 3 ROWS
       INTO wa_scustom
       WHERE custtype = 'B'
       ORDER BY discount DESCENDING.
ENDSELECT.

Addition 2

... CLIENT SPECIFIED

Effect

This addition switches off the automatic client handling of Open SQL. When a single database table or a single view is specified, the additionmust be inserted directly after dbtab of the join condition. When a join expression is specified, it must be inserted after the last addition ON of the join condition.

When the addition CLIENT SPECIFIED is used, the first column of the client-specific database tables can be specified in the WHERE condition to determine theclientidentifier. In the addition ORDER BY, the column can be sorted explicitly according to client identifier.

Notes

  • If the addition CLIENT SPECIFIED is specified, the client column is treated like any other columnin the table. If the client ID is not specified in the WHERE condition, the selection is for all clients.

  • If the addition CLIENT SPECIFIED is specified but the client ID is not entered in the WHERE condition, the SELECT statement bypassesSAP buffering.

  • Since each client represents a closed unit, automatic client handling in application programs should never be switched off. In systems withmultitenancy, this is ensured by the ABAP runtime environment.


Example

Reading all customers in client 800.

DATA wa_scustom TYPE scustom.

SELECT *
       FROM scustom CLIENT SPECIFIED
       INTO wa_scustom
       WHERE mandt = '800'.
ENDSELECT.

Addition 3

... BYPASSING BUFFER

Effect

This addition causes the SELECT statement to avoid theSAP buffering and to read directly from the database and not from the buffer on theapplication server.


Fill RESBD Structure from EBP Component Structure   Fill RESBD Structure from EBP Component Structure  
This documentation is copyright by SAP AG.


Length: 13568 Date: 20120522 Time: 061135     triton ( 393 ms )