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

Modify a databsae table

Former Member
0 Likes
820

Hi,

If we use Modify for a row which is existing in database table, it will change the row and work as UPDATE.

If row is not exisitng in table , it will add to table and in this case it will work as INSERT.

so,both case SY-SUBRC = 0.

Can you please tell me in which case SY-SUBRC = 4.

Thanks,

Pramod

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
797

SY_SUBRC = 4 If One or more lines could not be inserted or updated

You cannot modify a line if there is already a line in the table with identical key field values in a UNIQUE index.

Unique Index

If an index is marked as a UNIQUE index, the table may only contain each combination of values for the fields specified in the table once. The index fields take on key attributes in this case, i.e. they already uniquely identify each record of the table.

The database system automatically checks that the value combinations for the index fields are unique and outputs an error message if this is not the case (e.g. in an INSERT operation).

In the SAP System, it could happen that an INSERT operation is ended with a SY-SUBRC = 4 (DUPLICATE RECORD) although the table obviously does not yet contain the specified value combination of the key fields. However, inserting the record would violate the uniqueness of the fields defined in the UNIQUE index.

The accessing speed is not affected by whether or not an index is defined as a Unique index.

Note: If a UNIQUE index is defined for a client-independent table, the client field must be included in the index since the SAP System assumes that client-independent uniqueness cannot be ensured for the table contents.

7 REPLIES 7
Read only

Former Member
0 Likes
797

If you are modifying from an internal table, it means that one or more of the lines from the internal table could not be updated.

Rob

Read only

0 Likes
797

Hi,

Not internal table , Modify any Databse table.

Cheers,

Pramod

Read only

0 Likes
797

Hi Pramod,

When you are modifying a Database table from internal table.

SY-SUBRC = 0.

All lines were successfully inserted or updated.

SY-SUBRC = 4,

One or more lines could not be inserted or updated.

Read only

0 Likes
797

I meant modifying a database table from an internal table. The same would hold for single updates.

Rob

Read only

Former Member
0 Likes
798

SY_SUBRC = 4 If One or more lines could not be inserted or updated

You cannot modify a line if there is already a line in the table with identical key field values in a UNIQUE index.

Unique Index

If an index is marked as a UNIQUE index, the table may only contain each combination of values for the fields specified in the table once. The index fields take on key attributes in this case, i.e. they already uniquely identify each record of the table.

The database system automatically checks that the value combinations for the index fields are unique and outputs an error message if this is not the case (e.g. in an INSERT operation).

In the SAP System, it could happen that an INSERT operation is ended with a SY-SUBRC = 4 (DUPLICATE RECORD) although the table obviously does not yet contain the specified value combination of the key fields. However, inserting the record would violate the uniqueness of the fields defined in the UNIQUE index.

The accessing speed is not affected by whether or not an index is defined as a Unique index.

Note: If a UNIQUE index is defined for a client-independent table, the client field must be included in the index since the SAP System assumes that client-independent uniqueness cannot be ensured for the table contents.

Read only

Former Member
0 Likes
797

Consider this situation:

You are trying to use modify on table Ztable which has the key K1. And key K1 has a check table Zchecktable.

So now from your program, when you try to modify Ztable with key-parameter which is not found in the Zchecktable then your subrc value will not be equal to 0.

Read only

Former Member
0 Likes
797

Also, if your table has a composite key and if one of the key paramters that you pass in the modify statement is initial/null then it will fail!