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

COMMIT WORK and WAIT FOR n SECONDS

Former Member
0 Likes
6,731

I am designing a WebDynpro Java application. It makes an update call followed immediately by a display call which should return the data that was just updated. However, it appears that there is some DB latency involved and the data takes a few seconds to update. The application displays old data if the display call is performed too quickly after the update call.

All suggestions I could find point to having a Thread sleep on the Java side for a few seconds or have a WAIT FOR n SECONDS and/or COMMIT WORK AND WAIT statement in the ABAP function module. Neither of these solutions is acceptable in a company-wide application where database latency could vary significantly based on traffic.

I tried all kinds of functions (i.e. BAPI_TRANSACTION_COMMIT) as well as various forms of COMMIT WORK... nothing except a WAIT works correctly. There must be a statement out there that waits for the database write to be complete! How is this solved without picking an arbitrary WAIT time? What am I missing?

Thanks in advance!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,722

With the commit work and wait you do not have to have a time.

Addition

... AND WAIT

Effect

The addition ... AND WAIT makes the program wait for the type V1 update (update with immediate start) to be executed.

The Return Code is set as follows:

SY-SUBRC = 0:

The update was performed successfully.

SY-SUBRC <> 0:

The update was not performed successfully.

6 REPLIES 6
Read only

Former Member
0 Likes
2,723

With the commit work and wait you do not have to have a time.

Addition

... AND WAIT

Effect

The addition ... AND WAIT makes the program wait for the type V1 update (update with immediate start) to be executed.

The Return Code is set as follows:

SY-SUBRC = 0:

The update was performed successfully.

SY-SUBRC <> 0:

The update was not performed successfully.

Read only

0 Likes
2,722

I tried the statement:

COMMIT WORK AND WAIT

And it had no success. It's like when I call the data update BAPI it runs asychronously. Any other suggestions?

> With the commit work and wait you do not have to have

> a time.

>

> Addition

> ... AND WAIT

>

>

> Effect

> The addition ... AND WAIT makes the program wait for

> the type V1 update (update with immediate start) to

> be executed.

>

> The Return Code is set as follows:

>

>

>

> SY-SUBRC = 0:

> The update was performed successfully.

> SY-SUBRC <> 0:

> The update was not performed successfully.

Read only

0 Likes
2,722

You can write the other way.

declare one variable

data : wa_try type i.

wa_try = 10. -> set as 10 ,even you do not get value ,keep on incresing.

after BAPI FM

you can call comitt fm.

after BAPI_TRANSACTION_COMITT

just use simple logic.

do wa_try.

select * from table into table

where record = bapi fm record ( You get in RET2 Message).

if sy-subrc eq 0.

exit.

endif.

Thanks

Seshu

Read only

Former Member
0 Likes
2,722

It depends a bit on the way you update the data. If you're doing this via batch load and then you call "CALL TRANSACTION" you can use "UPDATE S" parameter.

In other cases you can try to lock a record until it is changed and not read data not in display mode but in change mode. You'll be sure that the data has changed

Read only

Former Member
0 Likes
2,722

Nothing worked; we unfortunately ended up sticking with the WAIT FOR n SECONDS solution.

Read only

matt
Active Contributor
0 Likes
2,722

Put the wait in a loop, and loop until the condition is met. The condition could be the retrieved data matches what was written, that a lock has been removed, or the data exists in the table. In the past, I've used the "lock" method.

i.e.

loop.
  if I can lock the object.
    unlock object.
    exit.
  endif.
  wait.
endloop.

do something.