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

DELETE from database table not working in background

former_member852447
Active Participant
0 Likes
5,076

Hello experts,

Using syntax DELETE database table where..........commit work works fine in the foreground but will not work in the background. Tried inserting WAIT FOR.....did not help

Anybody had this issue before.

Any ideas appreciated.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,079

> ...will not work in the background.

What exactly does "will not work" mean?

Rob

21 REPLIES 21
Read only

Former Member
0 Likes
3,080

> ...will not work in the background.

What exactly does "will not work" mean?

Rob

Read only

former_member852447
Active Participant
0 Likes
3,079

hello Rob,

'will not work' means it does the delete the content from the database table. When run in the foreground the deletion takes place...have checked the DELETE syntax over and over again and using COMMIT WORK and WAIT.

Read only

0 Likes
3,079

DELETE works in the background. The error lies elsewhere.

Rob

Read only

0 Likes
3,079

Have you checked your "where" clause?

Read only

0 Likes
3,079

Hi,

There is no restriction on Delete to not work in background.

Please check your where clause, or delete statement.Error lies somewhere else.

Read only

Former Member
0 Likes
3,079

Hi,

Try with a single record in back ground which record is available in database table. If it is working fine then your where condition is problem.

Example:

delete mara where matnr = '10000011'.

commit work.

Ram.

Read only

Former Member
0 Likes
3,079

Hi,

Try debugging the completed job in SM37 using jdbg.

Go to SM37 and display the jobs. Select your job and enter 'JDBG' in command area. Keep on pressing F7 till you reach code in your program.

Then step by step analyse the program and check the conditions given to DELETE statement.

Read only

Former Member
0 Likes
3,079

Hi David,

After the delete statement.

Use this:

Commit Work and WAIT.

The program will not go further until the commit has happened. This will ensure that the table entries get deleted.

Let me know if it worked.

Cheers,

Saurabh Mathuria

Read only

Lukas_Weigelt
Active Contributor
0 Likes
3,079

Hi,

I'm confused with your terms "foreground" and "background". Foreground means you execute a report and background, you run a job or?...

Might be an authority issue, whereas I've never seen one with DML-statements.

In my opinion: Run ST01, Run your background-whatever_it_is, check ST01 log for SQL or Authority errors.

regards, Lukas

Read only

former_member212713
Contributor
0 Likes
3,079

Hi David;

Can you write your code with little up and down rows?

Maybe your code has small problem.

Best ragards.

Read only

former_member852447
Active Participant
0 Likes
3,079

Hello All,

I checked my code over and over again and there is only one way to do it. The existing code posts correctly in dialogue mode (from the screen). However when I executed it in the background the same issue.

I debugged the completed background job from SM37 using transaction JDBG (thank you Vinraaj) and F7 until my program appeared and debugged again. The code was correctly executing.

However when I hit F7 multiple times and the completed program executed again (without my debugging thru single step) from the output in SM37 , the output was correct. (my code executed correcly)

Has anybody encountered this issue before, could this be a SAP issue. It is not an authorization problem. I am in a developmet system and have SAP all.

Any suggestions would be helpful.

Read only

0 Likes
3,079

when you run in foreground it works because you have authorization. However, when you run in background it doesn't use your userid it will be a generic background id (refer your security team they will know). I would say it is this id that needs the authorization update.

Read only

0 Likes
3,079

Can you paste your code and is your program dialog screen - module pool ? How are you running it in background ?

Read only

0 Likes
3,079

An obvious question - what is sy-subrc after the delete in the background?

Rob

Read only

former_member852447
Active Participant
0 Likes
3,079

Hello Rob,

When I run the completed program in the background using JDBG sy-subrc = 0 after the delete. This indicates that the code is correct. If the code was incorrect it would not work running it from the screen, right.

I am awaiting an answer from the security person as to the authorisation for batch and background. There might be some restrictions on DELETE and COMMIT WORK and WAIT.

Thanks for the input

Read only

0 Likes
3,079

If sy-subrc = 0, then the delete was done. How do you know it wasn't?

Rob

Read only

0 Likes
3,079

hi, can you try SM13 to see if there's any error in DB update??

Read only

0 Likes
3,079

Also check if any other program or same program is creating entries after delete.

Read only

andrs_sarcevic
Contributor
0 Likes
3,079

I just had a requirement to create a simple FM containing only a DELETE statement. This FM executes as part of an event in background mode. Works beautifully! No commit work whatsoever...

A security problem with the user that runs background processes seems likely, as suggested above.

...And let us know what was the problem!

Read only

former_member852447
Active Participant
0 Likes
3,079

Thank you All for the help. The issue has been finally traced to Authorisation issue. JDBG also useful..awarding points

Read only

former_member852447
Active Participant
0 Likes
3,079

Thanks to all who replied