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

simple select query..

Former Member
0 Likes
589

Hi All,

I want to select some rows from table ( T1, say ) and update a particular column value( T1-C, say ) with a value in the variable( Var1, say) for these selected rows. What would be the best statement for doing the same ?..

Thanks in Advance, Sudeep..

1 ACCEPTED SOLUTION
Read only

varma_narayana
Active Contributor
0 Likes
569

Hi..

You can do this using...

UPDATE <DB TABLE>

SET <FIELD> = <VALUE>

WHERE <CONDITION>.

Eg:

Update KNA1 set Ort01 = 'New York' Where Land1 = 'US'.

Reward if Helpful.

4 REPLIES 4
Read only

Former Member
0 Likes
569

Hi

Select *

from T1

into table lt_T1

where <ur condition>.

Loop at lt_T1 into wa_T1.

wa_T1-C1 = var1.

modify lt_T1 from wa_T1 index sy-tabix.

Endloop.

Thanks

Vasudha

Read only

varma_narayana
Active Contributor
0 Likes
570

Hi..

You can do this using...

UPDATE <DB TABLE>

SET <FIELD> = <VALUE>

WHERE <CONDITION>.

Eg:

Update KNA1 set Ort01 = 'New York' Where Land1 = 'US'.

Reward if Helpful.

Read only

Former Member
0 Likes
569

Hi,

Try this..



data: itab type standard table of T1,
        wa   type T1.

*" Select the data.
select * from T1 into itab where..

*" modify the internal table with the value VAR1 for field C.
 wa-c = var1.
 MODIFY itab FROM wa WHERE c <> var1.

*" Update the database.
 UPDATE T1 FROM TABLE itab.

*" commit the database.
  COMMIT WORK.

Thanks

naren

Read only

Former Member
0 Likes
569

Hi Sudeep,

Try the following code:-

Select * form T1 into corresponding fields of table itab_T1

where <condition>.

Loop at itab_T1 into wa_T1.

wa_T1-C = var.

Modify itab_T1 from wa_T1 transporting c.

clear wa_T1.

endloop.

Reward Points if useful.

Regards,

Shilpi