Friday 9 August 2013

AUGUST 9


Inserting values in Database Table:

INSERT is the open SQL statement to add values to the database table. First we declare a work area as the line structure of database table and fill the work area with the desired values. Then add the values in the work area to the database table using INSERT statement.
The syntax for the INSERT statement is as follows.
INSERT <database table> FROM <work area>
or
INSERT INTO <database table> VALUES <work area>
Example:
DATA: gwa_employee TYPE zemployee.

gwa_employee-id      = 6.
gwa_employee-name    = 'MARY'.
gwa_employee-place   = 'FRANKFURT'.
gwa_employee-phone   = '7897897890'.
gwa_employee-dept_id = 5.

INSERT zemployee FROM gwa_employee.

Changing values in Database Tables:

UPDATE is the open SQL statement to change the values in the database table. First declare a work area as the line structure of database table and fill the work area with the desired values for a specific key in the database table. Then update the values for the specified key in the database table using UPDATE statement.

The syntax for the UPDATE statement is as follows.


UPDATE <database table> FROM <work area>

Example:
DATA: gwa_employee TYPE zemployee.

gwa_employee-id      = 6.
gwa_employee-name    = 'JOSEPH'.
gwa_employee-place   = 'FRANKFURT'.
gwa_employee-phone   = '7897897890'.
gwa_employee-dept_id = 5.

UPDATE zemployee FROM gwa_employee.

We can also change certain columns in the database table using the following syntax
UPDATE <target> SET <set1> <set 2> … [WHERE <condition>].
The WHERE clause determines the lines that are changed. If we do not specify a WHERE clause, all lines will be changed.
Example:
UPDATE zemployee SET place = 'MUMBAI' WHERE dept_id = 2.

Inserting or changing Values:

MODIFY is the open SQL statement to insert or change entries in the database table. If the database table contains no line with the same primary key as the line to be inserted, MODIFY works like INSERT, that is, the line is added. If the database already contains a line with the same primary key as the line to be inserted, MODIFY works like UPDATE, that is, the line is changed.

The syntax for the MODIFY statement is as follows.

MODIFY <database table> FROM <work area>


If the database table does not already contain a line with the same primary key as specified in the work area, a new line is inserted. If the database table does already contain a line with the same primary key as specified in the work area, the existing line is overwritten.

Example:
DATA: gwa_employee TYPE zemployee.

gwa_employee-id      = 6.
gwa_employee-name    = 'JOSEPH'.
gwa_employee-place   = 'FRANKFURT'.
gwa_employee-phone   = '7897897890'.
gwa_employee-dept_id = 5.

MODIFY zemployee FROM gwa_employee.

Since there is no entry with the key 6, a new entry will be added to the table.
Example:
DATA: gwa_employee TYPE zemployee.

gwa_employee-id      = 6.
gwa_employee-name    = 'JOHNNY'.
gwa_employee-place   = 'LONDON'.
gwa_employee-phone   = '7897897890'.
gwa_employee-dept_id = 3.


MODIFY zemployee FROM gwa_employee.


Since there is an entry with the key 6, the values in the existing record will be modified.