07-07-2012 5:37 AM
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
07-07-2012 9:44 PM
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
07-07-2012 5:52 AM
07-07-2012 6:14 AM
SELECT SINGLE GJAHR INTO TST-FYEAR FROM BKPF
WHERE BUKRS = TEMP-ZBUKR AND
BELNR = TEMP-BELNR AND
BUDAT = TEMP-BUDAT.
07-07-2012 6:22 AM
Hi vignesh,
You are using TST-FYEAR , Instead u have to use Internal table name.
Regards,
Ramya R
07-07-2012 6:31 AM
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.
07-07-2012 8:37 AM
07-07-2012 8:46 AM
Did you use all the primary keys of the table in the SELECT query??
07-07-2012 11:02 AM
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
07-07-2012 11:51 AM
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.
07-07-2012 6:08 PM
07-07-2012 9:44 PM
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