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

Update statement not working

Former Member
0 Likes
12,104

Hi,

I need to update a ztable in my program.

I have used the following statement.

UPDATE zeps_pr_eos FROM TABLE tab4.

But an entry alredy exists in the ztable zeps_pr_eos with the values in tab4 table.But still after the update statement the sy-subrc value is 0.It should show sy-subrc value as 4.

Which is the correct statement to update the ztable table

8 REPLIES 8
Read only

Former Member
0 Likes
4,392

Hi ,

Try this.

MODIFY TABLE TABLE NAME FROM INTERNAL TABLE.

if sy-subrc = 0.

COMMIT WORK AND WAIT.

else.

roll back.

endif.

Regards,

Vijay

Read only

rainer_hbenthal
Active Contributor
0 Likes
4,392

>

> But an entry alredy exists in the ztable zeps_pr_eos with the values in tab4 table.But still after the update statement the sy-subrc value is 0.It should show sy-subrc value as 4.

>

> Which is the correct statement to update the ztable table

Update is working only with existant rows.

Are you looking for inserting new rows?

Read only

former_member191735
Active Contributor
0 Likes
4,392

Use commit work after update statement if sy-subrc = 0. Usually, if there is a record in table with same key it should give you subrc value 4 but if you get 0 use commit work statement after check subrc

To insert new rows, you could use Modify or insert statement. Update statement will updates the existing row.

good luck

Read only

Former Member
0 Likes
4,392

Please F1 on UPDATE statement ... You will get the answer

Read only

Former Member
0 Likes
4,392

Hi,

If the primary key fields of the internal table matches with those of the database table, the update statement will update them irrespective of what the other fields contains. Thats why SY-SUBRC = 0.

Only if the primary ket field of the internal table does not match with the primary key fields of the database table, SY-SUBRC will be 4.

Regards,

Vikranth

Read only

awin_prabhu
Active Contributor
0 Likes
4,392

Hi Friend,

I think u are confused between UPDATE and INSERT statements.

UPDATE statement will upate all records in databse table with new values from the internal table for matching records.

INSERT statement will insert new records into database table when that record does not exist already.

Press F1 on both UPDATE & INSERT statements and see.

Note: When source(internal table) is empty sy-subrc is always zero.

Thanks,

Edited by: Sap Fan on Sep 22, 2009 3:47 PM

Read only

Former Member
0 Likes
4,392

HI,

Check after giving this..

*'COMMIT WORK'*

or

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT.

Regards

Surya

Read only

Former Member
0 Likes
4,392

hi abaper,

how do you expect update would fail here?

update only works if a record exist. so its perfectly fine.

only insert statement will fail(sy-subrc=0) if a corresponding entry exist..