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: 

How to cancel the background job processing in ABAP programming?

Former Member
0 Kudos

Hi,

I have a requirement where i need to cancel the job depending on some constraint. My code is something like this:

Select some data from the table.

if sy-subrc = 0.

Do nothing.

Else

  • Cancel the job

call function 'BP_JOB_ABORT'

exporting

jobcount = number

jobname = name

EXCEPTIONS

CHECKING_OF_JOB_HAS_FAILED = 1

JOB_ABORT_HAS_FAILED = 2

JOB_DOES_NOT_EXIST = 3

JOB_IS_NOT_ACTIVE = 4

NO_ABORT_PRIVILEGE_GIVEN = 5

OTHERS = 6

.

The above code is cancelling the job but it is throwing an exception called CX_SY_DYN_CALL_PARAM_MISSING because i dint pass job count. How can we find the job count of next job that is going to run? Or How to handle the exception which it is throwing. Even if i try to handle that exception something like this:

TRY

call function 'BP_JOB_ABORT'

exporting

jobcount = number

jobname = name

EXCEPTIONS

CHECKING_OF_JOB_HAS_FAILED = 1

JOB_ABORT_HAS_FAILED = 2

JOB_DOES_NOT_EXIST = 3

JOB_IS_NOT_ACTIVE = 4

NO_ABORT_PRIVILEGE_GIVEN = 5

OTHERS = 6

RAISE EXCEPTION TYPE CX_SY_DYN_CALL_PARAM_MISSING.

CATCH

CX_SY_DYN_CALL_PARAM_MISSING.

ENDTRY.

It avoids the exception but it doesnt cancel the job. I even tried with function modules like JOB_OPEN

JOB_SUBMIT,BP_JOB_SELECT,BP_JOB_ABORT and tried to build some logic using status overview table (TBTCO) and TBTCP (Jobstep overview table).

Can someone suggest me the right way to write this program ?

Thanks in advance.

Rashmi

1 ACCEPTED SOLUTION

Former Member
0 Kudos

try FM RSPO_CANCEL_JOB

11 REPLIES 11

Former Member
0 Kudos

try FM RSPO_CANCEL_JOB

0 Kudos

Hi,

I checked with RSPO_CANCEL_JOB function module. But in this FM we need to pass 2 parameters PJIDENT and PJNUMBER. What do we need to pass and what does this FM do?

Thanks,

Rashmi

Former Member
0 Kudos

Hi,

From table TBTCO you can get the jobcount with jobname.

Use this FM BP_DELETE_JOB_STEP.

Hope this works you.

Aswarth

0 Kudos

Hi,

Yes. From table TBTCO we can get the jobcount with jobname. But jobcount is unknown because we have to cancel the job even before it gets executed. For instance as mentioned in my first question. If the records are not found in the table then we should cancel the background job. How can we stop the background job running through ABAP programming based on this condition?

I checked with this FM BP_DELETE_JOB_STEP. But here in this case i can only pass jobname. Jobcount and STEP_NUM is unknown. How can we findout the jobcount and step_num for the job which has to canceled or skipped based on some condition.

Thanks,

Rashmi

0 Kudos

Hi,

Problem is solved.

Create an background job with 2 steps. The first step in the background job calls the program ZBACKJOB_STEP1. In the variant we have a wrong material number

If the material number is not found in Mara, the next step in the job should not get executed and the job should get cancelled..

In the above posts i had asked how do I get the job count of the job that is currently triggering the program at the runtimeu2026..If u see the below code uu2019ll get to know.. We have to use the standard structure TBTCM which captures the properties/characteristics of the job.

REPORT ZBACKJOB_STEP1.

TABLES: MARA,TBTCM.

PARAMETERS : MATNR TYPE MATNR.

START-OF-SELECTION.

SELECT SINGLE * FROM MARA WHERE MATNR = MATNR.

IF SY-SUBRC IS INITIAL.

WRITE / : 'This is the material selected on the selection-screen' , MARA-MATNR.

ELSE.

CALL FUNCTION 'GET_JOB_RUNTIME_INFO'

IMPORTING

EVENTID = TBTCM-EVENTID

EVENTPARM = TBTCM-EVENTPARM

EXTERNAL_PROGRAM_ACTIVE = TBTCM-XPGACTIVE

JOBCOUNT = TBTCM-JOBCOUNT

JOBNAME = TBTCM-JOBNAME

STEPCOUNT = TBTCM-STEPCOUNT

EXCEPTIONS

NO_RUNTIME_INFO = 1

OTHERS = 2.

IF SY-SUBRC = 0.

CALL FUNCTION 'BP_JOB_ABORT'

EXPORTING

JOBCOUNT = TBTCM-JOBCOUNT

JOBNAME = TBTCM-JOBNAME

EXCEPTIONS

CHECKING_OF_JOB_HAS_FAILED = 1

JOB_ABORT_HAS_FAILED = 2

JOB_DOES_NOT_EXIST = 3

JOB_IS_NOT_ACTIVE = 4

NO_ABORT_PRIVILEGE_GIVEN = 5

OTHERS = 6.

IF SY-SUBRC <> 0.

ENDIF.

ENDIF.

ENDIF.

Regards,

Rashmi

Former Member
0 Kudos

select the job in sm37 and click on cancel button on tool bar

0 Kudos

Hi,

I want to cancel my job based on through conditions in my ABAP code as mentioned in my first question.

Thanks,

Rashmi

Former Member
0 Kudos

incredible...?

why don't you just give an error message..

message 'end of the road' type 'E'.

arthur_fuscella
Participant
0 Kudos

Hello,

See note 666290. Use report RSBTCDEL to force deletion.

Arthur Silva

0 Kudos

Dear All,

As mentioned above, While executing (RSBTCDEL2) I can NOT see any record I have executed (RSBTCDEL), but the Job still running.

Please help, my problem is bit different.

I wanted to Stop/Cancel running background Job named (SAP_CCMS_MONI_BATCH_DP) which Active/running for last 7 days.

I have executed (RSBTCDEL) selected only this Job name and also typed "X" - in (Delete with force mode). But after executing I got following message -

RSBTCDEL Of the 2 jobs selected, 2 were not deleted.

The background Job (SAP_CCMS_MONI_BATCH_DP) still running.

Thanks

Kushal

changlin_ke
Participant
0 Kudos

Hi, Kushal

Have you resolved the issue?