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

Regarding Database MODIFY

Former Member
0 Likes
813

Hi,

I am updating(or Insert) database table in a user - Exit, using MODIFY statement.

On a particualr date, they have created 100 documents. But, in that 96 documents are inserted into the Custom data base table. But, 4 documents are not inserted.

So, can you please tell me. what are the chances of a "MODIFY" statment can fail.

If the 2 users are inserting simultaneuously, is there any chance of fail in MODIFY?

I am not using any locks in my code.

I am not using an Commit work here as this is user exit.

Please help me.

Code :

MODIFY DBTAB from WA.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
782

Hi Sandeep,

No Need for locks,

As MODIFY statement automatically sets a database lock until the next database commit or database rollback.

The Possible cause for not updating the records could be.

At least one line could not be processed as there is already a line with the same unique name secondary index in the database table.

means duplicay of records,

For ex 96 records are inserted so these 96 records contains unique entries in there primary key fields, rest 4 records doesn't contain unique entries in primary key fields.

for ex in table MSEG- document number is a key field, so you can not put same material number twice,

Kindly check your data which you are updating in your table, As key fields should have unique entries. This will definately solve your problem.

Thanks

Saurabh siwach

6 REPLIES 6
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
782

Modify statement updates the existing entries and inserts new entries.

You can check the sy-subrc value after modify statement.

Read only

Former Member
0 Likes
782

Hello

1. You doing INSERT. If exist record with same key field your new record will not insert.

2. You doing MODIFY. If not exist record - line could not be updated.

Read only

Former Member
0 Likes
783

Hi Sandeep,

No Need for locks,

As MODIFY statement automatically sets a database lock until the next database commit or database rollback.

The Possible cause for not updating the records could be.

At least one line could not be processed as there is already a line with the same unique name secondary index in the database table.

means duplicay of records,

For ex 96 records are inserted so these 96 records contains unique entries in there primary key fields, rest 4 records doesn't contain unique entries in primary key fields.

for ex in table MSEG- document number is a key field, so you can not put same material number twice,

Kindly check your data which you are updating in your table, As key fields should have unique entries. This will definately solve your problem.

Thanks

Saurabh siwach

Read only

0 Likes
782

Hi Sourabh,

Thanks for your reply.

I checked my entries. The document number is unique. So, there is no problem is Primary key.

So, if 2 users are simultaneously inserting into database, then because of these locks, is there any chance that, for the second user , the MODIFY can fail?

Thanks,

Sandeep

Read only

Former Member
0 Likes
782

Hi Sandeep,

Yes If 2 users simeltaneously Modify records in standard table, Then Modify will fail for second user. SAP Suggests that there has to be a fraction of seconds difference between 2 modify on same standard table.

You can use Dequeue Function module to unlock the entries, BUt That is not the right approach and not recommended by SAP.

Thanks

Saurabh

Read only

anup_deshmukh4
Active Contributor
0 Likes
782

sy-subrc Meaning for modify statement

0 At least one line was changed.

4 No lines were changed, since no suitable line was found for the insertion using the table key, or the specified index was greater than the current number of lines for the insertion using the table index.