Ansicht
Dokumentation

ABAPOPENSQL_DYNAMIC_SOURCE - OPENSQL DYNAMIC SOURCE

ABAPOPENSQL_DYNAMIC_SOURCE - OPENSQL DYNAMIC SOURCE

ROGBILLS - Synchronize billing plans   RFUMSV00 - Advance Return for Tax on Sales/Purchases  
This documentation is copyright by SAP AG.
SAP E-Book

(source_text): Source Code in Dynamic Open SQL

Variants:

1. ... (field)

2. ... (string)

3. ... (itab)

4. ... (stringtab)

Effect

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.

Variant 1

... (field)


Effect

The source code is specified in a field field of the type C.

Example

Deleting all lines in a table:

PARAMETERS tabname(80) TYPE C.

DELETE FROM (tabname).

Variant 2

... (string)


Effect

The source code is specified in a string string.

Example

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.

Variant 3

... (itab).


Effect

The source code is specified in an internal table itab with line type C.

Example

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.

Variant 4

... (stringtab)


Effect

The source code is specified in an internal table stringtab with line type STRING.

Example

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.

Note

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.






Addresses (Business Address Services)   ABAP Short Reference  
This documentation is copyright by SAP AG.

Length: 5804 Date: 20240329 Time: 080737     sap01-206 ( 60 ms )