Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Database Operations
Database Operations |
Dec-2008
Objectives
The participants will be able to:
Manipulate data in the database tables using:
UPDATE
INSERT
MODIFY
DELETE
Database Operations |
Dec-2008
Overview
We will now add functionality to the Update
pushbutton by learning the database operation
UPDATE. We will also learn INSERT, MODIFY,
and DELETE.
Exit
YMOVIE
Database Table
UPDATE
INSERT
MODIFY
DELETE
Update
Academy Awards
Year
1994
Category PIC
Winner
Forrest Gump
Notes
Critic
Dean
Database Operations |
Enter Name
Dec-2008
YMOVIE
Database Table
TABLES YMOVIE.
DATA OKCODE(4).
TABLES statement
defines the work area for
YMOVIE table
ABAP
Program
UPDATE
INSERT
MODIFY
DELETE
Database
Interface
Layer
Open SQL
Native SQL
4
Database Operations |
Dec-2008
YMOVIE
Database Table
TABLES YMOVIE.
DATA OKCODE(4).
TABLES statement
defines the work area for
YMOVIE table
ABAP
Program
UPDATE
INSERT
MODIFY
DELETE
Database
Interface
Layer
Open SQL
Native SQL
5
Database Operations |
Dec-2008
Update
UPDATE YMOVIE.
UPDATE YMOVIE
SET WINNER = Forrest Gump
NOTES = Great movie!
WHERE AAYEAR = 1994
AND CATEGORY = PIC.
UPDATE YMOVIE
SET NOTES = Great movie!
WHERE CATEGORY = PIC.
Database Operations |
Dec-2008
Insert
INSERT YMOVIE.
Database Operations |
Dec-2008
Modify
MODIFY YMOVIE.
MODIFY YMOVIE
FROM MOVIE_REC.
If the record does not exist, MODIFY will insert the record.
If the record does exist, MODIFY will update the record.
8
Database Operations |
Dec-2008
Delete
DELETE YMOVIE.
Database Operations |
Dec-2008
10
Database Operations |
Dec-2008
Screen
1
Screen
2
Screen
3
SELECT A
SELECT B
UPDATE A
DELETE B
Database
Transaction
Database
Transaction
Database
Transaction
Update Transaction
(Logical Unit of Work)
11
Database Operations |
Dec-2008
Commit or Rollback
Update
IF SY-SUBRC = 0.
COMMIT WORK.
MESSAGE S002.
ELSE.
ROLLBACK WORK.
MESSAGE I003.
12
Database Operations |
ENDIF.
ENDIF.
ENDMODULE.
Dec-2008
Summary
Because SQL statements are not standardized across database systems, SAP has
two forms of SQL statements: Open SQL and Native SQL.
The ABAP Open SQL statement UPDATE will change an already existing record
(or records) in the database table.
The ABAP Open SQL statement INSERT will add a non-existing record to the
database table.
A way to avoid an error with UPDATE or INSERT is to use MODIFY. The
ABAP Open SQL statement MODIFY will either insert a record (if the record does
not exist) or update a record (if the record already exists).
The ABAP Open SQL statement DELETE will remove an already existing record
(or records) from the database table.
If you are going to perform these database operations on several records, it is
more efficient to use an internal table. If you use an internal table, these database
operations are called array operations.
13
Database Operations |
Dec-2008
Summary (Contd.)
The term logical unit of work (LUW) refers to a collection of all-or-nothing
actions performed at the database level as a complete unit.
The ABAP statement COMMIT WORK confirms all changes to the database
and closes an LUW. The ABAP statement ROLLBACK WORK cancels and
rolls back all changes in an LUW.
14
Database Operations |
Dec-2008
Questions
15
Database Operations |
Dec-2008