Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Report

Former Member
0 Likes
506

I want to retrieve data from ztable which contains eno,name,age,sal,level,date of join.In level i have T,M & L.I selected the data with level L.I want to add salary 1000 to their existing salary.How to do that?

I am getting level as input parameter.

4 REPLIES 4
Read only

Former Member
0 Likes
485

Hi

use the update statement

tables: ztable

update ztable set salary = '1000' where level = 'L'.

Regards

ANJI

Read only

Former Member
0 Likes
485

update ztable set sal = sal + 1000 where level = 'L'.

or

parameters: ilevel(1) type c.

update ztable set sal = sal + 1000 where level = ilevel.

Read only

former_member194152
Contributor
0 Likes
485

Hi try like this...

select * from ztable into table itab where leval = 'L'.

loop ai itab.

itab-salary = itab-salary + 1000.

modify itab.

write : / itab-eno,itab-ename,itab-salary......

endloop.

Rewards if helpful.

Regards

Gagan

Read only

Former Member
0 Likes
485

Hi Khanna,

Have a look at this.

UPDATE dbtab SET f1 ... fn. or

UPDATE (dbtabname) SET f1 ... fn.

Extras:

1. ... WHERE condition

2. ... CLIENT SPECIFIED

3. ... CONNECTION con

Effect

Updates values in a database table. If there is no WHERE clause, all lines (in the current client) are updated. If a WHERE condition is specified, only thoserecords which satisfy the WHERE condition are updated.

The SET clause f1 ... fn identifies the columns to be updated and assigns values to them. Four types of SET statements fi are supported:

f = g

In all selected lines, the database table column specified by f receives the value of g. g can be an ABAP field, a literal, or a field descriptor. In the latter case, the contents of the column to which g points are copied into the line of the table that you are updating.

f = f + g

In all selected lines, the contents of g are added to the value in the database table column determined by f. g can be an ABAP field, a literal, or a field descriptor. The NULL value remains unchanged. This statement can only be applied to a numeric field.

f = f - g

In all selected lines, the content of g is subtracted from the value in the database table column determined by f. g can be an ABAP field, a literal, or a field descriptor. The NULL value remains unchanged. This statement can only be applied to a numeric field.

(source_text)

For all selected lines, the program executes the SET statements that are specified dynamically in the source_text variable as ABAP-Quelltext source text. You can specify any SET statement that you could specify statically.

Example

Changing the discount to 3 percent for all customers in the current client:

UPDATE scustom SET discount = '003'.

Example

The same example using a dynamic SET condition:

DATA: tabname TYPE STRING,

set_clause TYPE STRING.

tabname = 'SCUSTOM'.

set_clause = 'DISCOUNT = ''003'' '.

UPDATE (tabname) SET (set_clause).

When the command has been executed, the system field SY-DBCNT contains the number of updated lines.

System values

SY-SUBRC = 0:

At least one line was updated,

SY-SUBRC = 4:

No line was updated because either no line could be selected or the change would have generated lines with primary keys that already existed.

Note

With pooled and cluster tables, an UPDATE cannot change any primary key field.

If you want to change a column of the type STRING, the primary key in the WHERE condition must be fully specified.

SET statements are not separated by commas.

Do not use the colon and commas to separate chained statements, since you could change an entire database table without wanting to, if you use them wrongly.

  • FALSCH * WRONG * FALSCH * WRONG * FALSCH * WRONG *

  • UPDATE SCUSTOM SET: DISCOUNT = '003',

  • TELEPHONE = '0621/444444'

  • WHERE ID = '00017777'.

This code fragment is not a single statement that update the discount and telephone number for the customer with the customer number '00017777'. Rather, it represents two statements - the first changes the discount for all customers, while the second changes the telephone number of the customer with the customer number '00017777'.

Addition 1

... WHERE condition

Effect

Updates only those lines which satisfy the

WHERE clause condition.

Note

You cannot include a subquery to the appropriate database table in the WHERE clause.

Example

Increase the number of occupied seats on Lufthansa flight 0400 on 28.02.2001 by 3 (in the current client):

UPDATE sflight SET seatsocc = seatsocc + 3

WHERE carrid = 'LH' AND

connid = '0400' AND

fldate = '20010228'.

Addition 2

... CLIENT SPECIFIED

Effect

Switches off automatic client handling. This allows you

to update across all clients when using client-specific tables. The client field is treated like a normal table field, for which you can formulate suitable conditions in the WHERE clause.

The CLIENT SPECIFIED addition must immediately follow the database table name.

Example

Increase the number of occupied seats on Lufthansa flight 0400 on 28.02.2000 by 3 in client 2:

TABLES SFLIGHT.

UPDATE sflight CLIENT SPECIFIED

SET seatsocc = seatsocc + 3

WHERE mandt = '002' AND

carrid = 'LH' AND

connid = '0400' AND

fldate = '20010228'.

Addition 3

... CONNECTION con

Effect

The Open SQL command is not executed on the

standard database, but on the secondary database connection specified with con. con is the name of the database connection as it was specified in the table DBCON in the column CON_NAME. The database connection con can also be specified dynamically in the form (source_text), where the source_text field contains the name of the database connection and must be type C or STRING.

The CONNECTION con addition must be specified directly after the name of the database table or after the CLIENT SPECIFIED addition.

So here you can use,

UPDATE ztab SET salary = '1000' where level = 'L'.

Reward If Useful.

Regards,

Chitra