‎2009 Sep 22 2:35 PM
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
‎2009 Sep 22 2:41 PM
Hi ,
Try this.
MODIFY TABLE TABLE NAME FROM INTERNAL TABLE.
if sy-subrc = 0.
COMMIT WORK AND WAIT.
else.
roll back.
endif.
Regards,
Vijay
‎2009 Sep 22 2:41 PM
>
> 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?
‎2009 Sep 22 2:42 PM
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
‎2009 Sep 22 2:44 PM
‎2009 Sep 22 2:44 PM
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
‎2009 Sep 22 2:47 PM
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
‎2009 Sep 22 2:51 PM
HI,
Check after giving this..
*'COMMIT WORK'*
or
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT.
Regards
Surya
‎2009 Sep 22 5:05 PM
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..