1. ... (field)
2. ...
(string)
3. ...
(itab)
4. ... (stringtab)
In all Open SQL statements you can specify the table name dynamically at runtime in an ABAP variable.
You can also specify the SELECTclause,
the FROMclause, the
WHEREclause, the GROUP
BYclause, the HAVINGclause,
the ORDER BYclause
and the SETclause (partially)
dynamically in an ABAP variable. The name of the variable that contains the source code must be put in parentheses. There must be no blanks between the variable name and the parentheses.
... (field)
The source code is specified in a field field of the type C.
Deleting all lines in a table:
PARAMETERS tabname(80) TYPE C.
DELETE FROM (tabname).
... (string)
The source code is specified in a string string.
Displaying the flight connections after entering airports of departure and arrival:
PARAMETERS: p_from TYPE SPFLI-CITYFROM, p_to TYPE SPFLI-CITYTO.
DATA: where_clause TYPE STRING,
carr TYPE spfli-carrid,
conn TYPE spfli-connid.
CONCATENATE 'CITYFROM = ''' p_from ''' AND CITYTO = ''' p_to ''''
INTO where_clause.
SELECT carrid connid FROM spfli
INTO (carr, conn)
WHERE (where_clause).
WRITE: / carr, conn.
ENDSELECT.
... (itab).
The source code is specified in an internal table itab with line type C.
Displaying the number of flight connections after entering airline carrier, flight number, and flight date:
PARAMETERS: p_carrid TYPE sbook-carrid,
p_connid
TYPE sbook-connid,
p_fldate
TYPE sbook-fldate.
TYPES: t_src(80) TYPE C.
DATA:
where_tab TYPE TABLE OF t_src, line TYPE t_src.
CONCATENATE 'CARRID = ''' p_carrid '''' INTO
line.
APPEND line TO where_tab.
APPEND 'AND' TO where_tab.
CONCATENATE 'CONNID = ''' p_connid
'''' INTO line.
APPEND line TO where_tab.
APPEND 'AND' TO where_tab.
CONCATENATE 'FLDATE
= ''' p_fldate '''' INTO line.
APPEND line TO where_tab.
SELECT count(*) FROM sbook WHERE (where_tab).
WRITE: / sy-dbcnt.
... (stringtab)
The source code is specified in an internal table stringtab with line type STRING.
Displaying the flight data for all flights with available seats (after entering the airline carrier and flight number):
PARAMETERS: p_carrid TYPE sflight-carrid,
p_connid
TYPE sflight-connid.
DATA: s TYPE STRING,
stringtab
TYPE TABLE OF STRING,
date TYPE
sflight-fldate.
CONCATENATE ' CARRID = ''' p_carrid ''' AND' INTO s.
APPEND s TO stringtab.
CONCATENATE ' CONNID = ''' p_connid '''' INTO s.
APPEND s TO stringtab.
SELECT fldate
FROM sflight INTO date
WHERE (stringtab) AND seatsocc < sflight~seatsmax.
WRITE : / date.
ENDSELECT.
If the source code is specified in an internal table with a header, the source code is normally taken from the table body. This is only not the case if the table name is specified dynamically and the dynamic FROMclause is used. The table name or source code of the clause is then taken from the table header.