ABAP Database Operations: SELECT Loop, INSERT, MODIFY, DELETE, and Joins, Slides of Fundamentals of E-Commerce

An overview of various database operations in abap, including using select loops for iterative data processing, insert statements for adding new records, modify statements for updating existing records, delete statements for removing records, and joining tables for querying data. It also covers the difference between dynamic and static links.

Typology: Slides

2012/2013

Uploaded on 07/29/2013

satinder
satinder 🇮🇳

4.2

(21)

131 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
9
SELECT loop
If INTO clause indicates INTO TABLE, result put into internal table in a
single step operation called an array fetch.
If INTO clause does not specify INTO TABLE, data copied iteratively to
a data object (or objects).
Creates a select loop where body of the loop can specify actions to
be taken on the data object during each iteration.
Loop ends with the ENDSELECT statement.
DATA str TYPE SPFLI. "structure matching table row
SELECT CARRID CONNID CITYFROM CITYTO FROM SPFLI
INTO CORRESPONDING FIELDS OF str.
WRITE: / str-CARRID, 'flight', str-CONNID,
str-CITYFROM, 'to', str-CITYTO.
ENDSELECT.
WRITE: / sy-dbcnt, 'rows output.'.
Select loop into individual data objects
In lieu of a structure as the copy destination, a set of individual data
objects may be specified:
SELECT fields FROM table INTO (var1, var2) WHERE …
DATA: my-client TYPE c LENGTH 3,
my-carrid TYPE c LENGTH 3,
my-connid TYPE c LENGTH 4.
SELECT mandt carrid connid FROM spfli CLIENT
SPECIFIED INTO (my-client, my-carrid, my-connid).
WRITE: / my-client, my-carrid, my-connid.
ENDSELECT.
WRITE: / sy-dbcnt, 'rows output.'.
Docsity.com
pf3
pf4

Partial preview of the text

Download ABAP Database Operations: SELECT Loop, INSERT, MODIFY, DELETE, and Joins and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

SELECT loop

If INTO clause indicates INTO TABLE , result put into internal table in a single step operation called an array fetch.

If INTO clause does not specify INTO TABLE , data copied iteratively to a data object (or objects). Creates a select loop where body of the loop can specify actions to be taken on the data object during each iteration. Loop ends with the ENDSELECT statement. DATA str TYPE SPFLI. "structure matching table row SELECT CARRID CONNID CITYFROM CITYTO FROM SPFLI INTO CORRESPONDING FIELDS OF str. WRITE: / str-CARRID, 'flight', str-CONNID, str-CITYFROM, 'to', str-CITYTO. ENDSELECT. WRITE: / sy-dbcnt, 'rows output.'.

Select loop into individual data objects

In lieu of a structure as the copy destination, a set of individual data objects may be specified: SELECT fields FROM table INTO (var1, var2) WHERE …

DATA: my-client TYPE c LENGTH 3, my-carrid TYPE c LENGTH 3, my-connid TYPE c LENGTH 4.

SELECT mandt carrid connid FROM spfli CLIENT SPECIFIED INTO (my-client, my-carrid, my-connid). WRITE: / my-client, my-carrid, my-connid. ENDSELECT.

WRITE: / sy-dbcnt, 'rows output.'.

Docsity.com

INSERT

INSERT INTO dbtable VALUES structure. INSERT INTO dbtable FROM structure. INSERT dbtable FROM TABLE internaltable. sy-subrc 0 = success 4 = insertion not possible as line with same key already present

For FROM TABLE option if even one line of internaltable cannot be inserted due to duplicate key in dbtable, the entire operation is rolled back. If desire all valid rows to be inserted, add ACCEPTING DUPLICATE KEYS to the statement. Duplicate rows still skipped, but other rows inserted. sy-subrc set to 4 to indicate this condition, sy-dbcnt set to number of rows successfully inserted.

UPDATE a single record or multiple records

UPDATE dbtable FROM str. Key field values in str are used for row selection.

UPDATE dbtable SET field = value field = value … WHERE keyfield = value AND keyfield = value. Only fields specified in SET clause are changed. If conditions specified in WHERE are not unique keys, multiple records may be changed.

UPDATE dbtable FROM TABLE internaltable.

sy-subrc 0 = success 4 = update not possible (key not found or other problem)

sy-dbcnt set to number of updated rows

Docsity.com

Joins

It is possible to join tables in a query. SELECT * FROM table1 INNER JOIN table2 ON table1~field = table2~field WHERE .

Called a link in ABAP. If the join done in a program it is a dynamic link.

Pre-existing links, static links , are defined in the ABAP Dictionary. These are called views.

Additional details on joins are beyond the scope of this class, but are well documented in the ABAP documentation.

Docsity.com