Application Development 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: 

ABAP select query fails intermittantly

Former Member
0 Kudos

Hi ,

I am facing a strange issue with ABAP select query.

I am trying to retrieve a single field from the DB by firing a select query. The issue is a little bit strange in the sense the select returns with SY-SUBRC 4 at times  and returns an empty field record.

The select fails 1 out of 10 times or so.

I tried and setup a breakpoint immediately after the select. When the select failed examined all the values used in the where condition of the select.Everything seems fine except the select fails to fetch the field. After reaching the breakpoint I re-executed the select by changing the program flow using go to statement to re-execute the failed select and this time it succeeds in the same run.

It appears that after Sufficient delay the select succeeds.The problem is the record is already commited to the DB.But when trying to read this particular field it fails at times.

The table I am trying to hit is BKPF.

Can the experts enlighten me as to why the select query may fail to retrieve any field.Any pointers in resolving/root causing this.

Thanks

1 ACCEPTED SOLUTION

Clemenss
Active Contributor
0 Kudos

Hi Vighneswaran CE,

yes this has been discussed many times before.

ABAP transactions use an update process to commit all data to database while processing already continues with other tasks. The update task is enqueued so that sometimes it has to wait for other processed to complete.

You have different options:

Hard but in most (but not all) cases safe way: WAIT UP TO 3 SECONDS. before firing select.

Better and always safe way: Check the lock object.

Before updating the database, the calling transaction will set a lock, in your case probably EFBKPF, to ensure database consistency.

You can check the lock by trying to set it - which will fail as long as it is already locked:

Use a LOOP or WHILE to call function ENQUEUE_EFBKPF for the number in question. If successful, call function DEQUEUE_EFBKPF and continue with your select.

But set a maximum loop time to vaoid unwanted deadlocks.

It may be helpfuil to study and understand the SAP lock concept first.

Regards

Clemens

10 REPLIES 10

Former Member
0 Kudos

HI,

Can you mention the select query code >

Regards,

Ravi Singh

0 Kudos

SELECT SINGLE GJAHR INTO TST-FYEAR FROM BKPF

           WHERE BUKRS = TEMP-ZBUKR AND

                 BELNR = TEMP-BELNR AND

                 BUDAT = TEMP-BUDAT.

0 Kudos

Hi vignesh,

You are using TST-FYEAR , Instead u have to use Internal table name.

Regards,

Ramya R

davis_raja
Active Participant
0 Kudos

Dear,

     Did you the check the entries in the table by giving the entries in table selection screen.

     If the entry is there in table and not fetched in SELCT query.

     Select all the primary key fields using the SELECT query.

0 Kudos

Yes the enries are very much present in the table.

0 Kudos

Did you use all the primary keys of the table in the SELECT query??

yogendra_bhaskar
Contributor
0 Kudos

Hi Vighneswaran ,

Could you plz. tell me what is TEMP in your select query .

could You mention the code before the select query .

Regards,

Yogendra Bhaskar

0 Kudos

The select query is inside an a basic subroutine

Begin of routine using Temp like <FLD_SY_TEMP>         ----> <FLD_SY_TEMP> is of type structure of 171 fields

 

STATICS: BEGIN OF TST,

             BUKRS TYPE BUKRS,

             POSTDT TYPE BUDAT,

             FYEAR TYPE GJAHR,

           END OF TST.

  IF <Condition>. --->If condition has no issues

The select query. --->Fails intermittantly

ENDIF.

END of routine.

0 Kudos

Hi,

Can you please show us how you populate TEMP?

Regards,

Karl

Clemenss
Active Contributor
0 Kudos

Hi Vighneswaran CE,

yes this has been discussed many times before.

ABAP transactions use an update process to commit all data to database while processing already continues with other tasks. The update task is enqueued so that sometimes it has to wait for other processed to complete.

You have different options:

Hard but in most (but not all) cases safe way: WAIT UP TO 3 SECONDS. before firing select.

Better and always safe way: Check the lock object.

Before updating the database, the calling transaction will set a lock, in your case probably EFBKPF, to ensure database consistency.

You can check the lock by trying to set it - which will fail as long as it is already locked:

Use a LOOP or WHILE to call function ENQUEUE_EFBKPF for the number in question. If successful, call function DEQUEUE_EFBKPF and continue with your select.

But set a maximum loop time to vaoid unwanted deadlocks.

It may be helpfuil to study and understand the SAP lock concept first.

Regards

Clemens