How to cancel the background job processing in ABAP programming?

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

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

Similar Messages

  • How to cancel the background job?

    Hi,
        I have schedule the backgroud job.How to cancel the background the job.
    When i select the job and click on stop button, iam getting message "job is not active - cancellation not possiable".How to schedule the background job.
    Regards,
    T.suresh

    goto sm37
    SM36 Define Background Job
    SM37 Background Job Overview
    SM39 Job Analysis
    U can Moniter the background Jobs through T code SM37
    In the Simple Job Selection window enter the name of the Job and User of that Job and u can check the status of that Job like “JobName, Job CreatedBy, Status, Start date, Start time Duration(sec.) Delay (sec.).

  • How to stop the background job "Sap_collector_for_job_statistic"

    Dear All,
    Kindly let me know how to stop the Background job "Sap_collector_for_job_statistic" which is running everyday.
    We want to stop this background job.
    Kindly suggest.
    Regards,
    Mullairaja

    Select the Job using SM37 transaction. In the Menu Choose
    Job ---> Cancel Active Job.
    Before you do this it may be good idea to check the pid using SM50.
    It will be using a Background work process. Check the pid and the status.
    Select the same and in the Menu Choose Process --> Cancel with Core.
    Refresh and check in SM37 for the Active and Cancelled Jobs.

  • How to schedule the background job using current selection screen field val

    Hello Friends,
    How to schedule the background job using current selection screen field values.
    after completion of the job the spool should be sent as a mail to SAP Inbox.
    Is there any way to create the variant dynamically by reading the current selection screen values.
    Thanks,
    Ravi

    Hi,
    To get the variant details you can use teh following FM.
    'RS_VARIANT_CONTENTS'.
    Regards,
    Ankur Parab

  • How to schedule the background job daily twice?

    Hi,
    How to schedule the background job daily twice? any conditions?
    Regards,
    Srihitha

    see the step by step procedure.
    Scheduling Background Jobs:
    1. Background jobs are scheduled by Basis administrators using transaction SM36.
    2. To run a report in a background, a job needs to be created with a step using the report name
    and a variant for selection parameters. It is recommended to create a separate variant for each
    scheduled job to produce results for specific dates (e.g. previous month) or organizational units (e.g.
    company codes).
    3. While defining the step, the spool parameters needs to be specified
    (Step-> Print Specifications->Properties) to secure the output of the report and help authorized users
    to find the spool request. The following parameters needs to be maintained:
    a. Time of printing: set to “Send to SAP spooler Only for now”
    b. Name – abbreviated name to identify the job output
    c. Title – free form description for the report output
    d. Authorization – a value defined by Security in user profiles to allow those users to access
    this spool request (authorization object S_SPO_ACT, value SPOAUTH). Only users with matching
    authorization value in their profiles will be able to see the output.
    e. Department – set to appropriate department/functional area name. This field can be used in
    a search later.
    f. Retention period – set to “Do not delete” if the report output needs to be retained for more
    than 8 days. Once the archiving/document repository solution is in place the spool requests could
    be automatically moved to the archive/repository. Storage Mode parameter on the same screen
    could be used to immediately send the output to archive instead of creating a spool request.
    Configuring user access:
    1. To access a report output created by a background job, a user must have at
    least access to SP01 (Spool requests) transaction without restriction on the user
    name (however by itself it will not let the user to see all spool requests). To have
    that access the user must have S_ADMI_FCD authorization object in the profile with
    SPOR (or SP01) value of S_ADMI_FCD parameter (maintained by Security).
    2. To access a particular job’s output in the spool, the user must have
    S_SPO_ACT object in the profile with SPOAUTH parameter matching the value used
    in the Print Specifications of the job (see p. 3.d above).
    3. Levels of access to the spool (display, print once, reprint, download, etc) are
    controlled by SPOACTION parameter of S_SPO_ACT. The user must have at least
    BASE access (display).
    On-line reports:
    1. Exactly the same configuration can be maintained for any output produced
    from R/3. If a user clicks “Parameters” button on a SAP Printer selection dialog, it
    allows to specify all the parameters as described in p. 3 of
    “Scheduling background jobs” section. Thus any output created by an online report
    can be saved and accessed by any user authorized to access that spool request
    (access restriction provided by the Authorization field of the spool request
    attributes, see p. 3.d of “Scheduling background jobs” section).
    Access to report’s output:
    1. A user that had proper access (see Configuring user access above) can
    retrieve a job/report output through transaction SP01.
    2. The selection screen can be configured by clicking “Further selection
    criteria…” button (e.g. to bring “Spool request name (suffix 2)” field or hide other
    fields).
    3. The following fields can be used to search for a specific output (Note that
    Created By must be blank when searching for scheduled job’s outputs)
    a. Spool request name (suffix 2) – corresponds to a spool name in p. 3.b in
    “Scheduling background jobs” section above).
    b. Date created – to find an output of a job that ran within a certain date range.
    c. Title – corresponds to spool Title in p. 3.c in “Scheduling background jobs”
    section above).
    d. Department - corresponds to spool Department in p. 3.e in “Scheduling
    background jobs” section above).
    4. Upon entering selection criteria, the user clicks the Execute button to
    retrieve the list of matching spool requests.
    5. From the spool list the user can use several function such as view the
    content of a spool request, print the spool request, view attributed of the spool
    request, etc. (some functions may need special authorization, see p.3 in
    Configuring user access)
    a. Click the Print button to print the spool request with the default attributes
    (usually defined with the job definition). It will print it on a printer that was
    specified when a job was created.
    b. Click the “Print with changed attributed” button to print the spool request
    with the different attributes (e.g. changing the printer name).
    c. Click the “Display contents” button to preview the spool request contents. A
    Print and Download functions are available from the preview mode.

  • How to debug the background job in ABAP

    Hi Guys,
    Can anyone let me know how to debug the background job in ABAP.
    Thanks in advance
    peter

    Hi,
    Goto SM37 and see the log if any is there and based on that you can check the code.
    you can't debug background job.
    Create a Variant for the Program and
    Schedule JOB in background:
    Go to SM36 create a Job
    enter Program and Variant for that program in STEP..
    click on Start Condition
    Click on DATE and TIME enter date scheduled Start and END times
    click on Period Values
    Click on HOURLY/WEEKLY etc
    CLick on RESTRICTIONS also to use further criteria.
    so your job will be scheduled and run as per your requirement.
    and in SM37 Transaction check the status of that JOB
    Check this link for scheduling jobs..
    http://help.sap.com/saphelp_nw2004s/helpdata/en/c4/3a7f87505211d189550000e829fbbd/content.htm
    Check this
    http://jplamontre.free.fr/SAP/Debug%20background%20process.htm
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/abap/abap+debugger&
    Regards,
    Padmam.

  • How to find the start condition of a ABAP program?

    Hello Gurus!,
    Could any one please explain how to find the start condition of a ABAP program?
    like its a event based or time based?and also how to find that event and time..
    Thanks in Advance...
    Dinakar

    Hi Dinkar,
    Go to Job Schedule, put Job Step parameter as your program and see scheduled Job.
    In Schedule Job double click to see start condition. and steps to see details and variant.
    Hope it helps.
    Thanks
    CK

  • How to cancel scheduled background job?

    Hi,
    I have used FM 'HR_START_BATCHJOB_IN_OTHER_SYS' to schedule background job.
    Some mistake has happend and this FM calling has gone to infinite loop. So, now the system is keep on generating background job. I tried looking into SM36 to stop this background job but i failed.
    Can anybody help me how to stop scheduled background job please.
    Regards,
    Mukund.

    Hi,
    Check which background process your job is  running from the Job details and inform your Basis consultant to Kill the process. If you have sm50 acess or sm66 access you can do the same.
    Regards,
    Vijay v

  • How to get the Background job name

    Hi,
    I am executing a report in background and i want to get the background job name in the same report program. How can i get the same.
    Regards,
    Rajgopal Dara.

    Hi,
    for this fm is used 148 times in our system, I made a check program and it works:
    report  zsbatchfm.
                                                                                    data: xv_jobcn type btcjobcnt.
    data: xv_jobnm type btcjob.
    data: xv_stepc type btcstepcnt.
                                                                                    call function 'GET_JOB_RUNTIME_INFO'
      importing
    *   EVENTID                       =
    *   EVENTPARM                     =
    *   EXTERNAL_PROGRAM_ACTIVE       =
        jobcount                      = xv_jobcn
        jobname                       = xv_jobnm
        stepcount                     = xv_stepc
      exceptions
        no_runtime_info               = 1
        others                        = 2.
                                                                                    if sy-subrc <> 0.
      write:  /1 'SY-SUBRC = ', sy-subrc.
    else.
      write:  /1 'JOBCOUNT  = ', xv_jobcn.
      write:  /1 'JOBNAME   = ', xv_jobnm.
      write:  /1 'STEPCOUNT = ', xv_stepc.
    endif.
                                                                                    commit work.
    In online mode you get a SUBRC = 1, in batch mode you get the informations (here: in SPOOL)
    Please check it on your system!
    Regards,
    Klaus

  • How to schedule the background job if report have Presentation server files

    Hi All,
    I have searched the forums and found , the way for the scheduling the background job if report selection screen have the presentation server file input.
    1. Using the Open data set method.
    And my client is not OK with Open dataset way, it there any other way to do this, As we are using the EXCEL file.
    Thanks and Regards,
    Bharani

    Hi,
    As said above it is generally not possible. Since your client most obviously doesn't like graphical background I would recomend storing data as till now, but show it with your own report in more userfriendly way. For example:
    - as ALV Grid
    - in excel with use of OLE either as embedded in SAP or new window (check transaction OLE for example)
    - with use of webdynpro
    BR
    Marcin Cholewczuk

  • How to shedule the background job

    hi experts,
    could you tell me
    how to shedule the background job

    hi,
    in abap u can schedule it by FM Job_open  and job_close...
    and then execute it in sm37
    thanks
    tanmaya

  • How to extend the execution time of an ABAP Program using the Process chain

    Hello Sapians,
    Our Environment has got 600seconds = 10 mintues as the execution time.
    My ABAP Program is taking more than this 600 seconds, to show the result, I found this when I tried to execute in debug mode, it shows the result.
    If I execute in background also it shows the results succesfully.
    Only issue is when I execute this report in foreground it has been taking ages and goes on Time OUT Error.
    It has been decided that we can extend the execution time only for this report, and it will reset the time back to 10mintues once the report has been executed successfully or failed in between for any other reasons.
    And we can achieve this by using the process chains.
    Can any body help me please in this regard
    Thanks,

    Hi,,,,,,,,,,
    Besides Process Chain There is another way out for this........
    Resetting time counter of dialog process so that time-out does not
    happen. Use this fm within your program at appropriate locations to
    reset time counter.
    "CALL FUNCTION 'TH_REDISPATCH'."
    Thanks
    Saurabh

  • How to cancel the background color in the tools content tab?

    I accidentally change the color of the background color,and I can't see the background image that I install using the extensions.

    Do you mean this:
    * Tools > Options > Content : Fonts & Colors > Colors : [X] "Allow pages to choose their own colors, instead of my selections above"
    If you installed a persona then you can uninstall that persona and revert to the default theme (Tools > Add-ons > Themes).<br />
    See:
    * [[Personas]]
    * [[Using themes with Firefox]]
    * http://kb.mozillazine.org/Themes (Lightweight theme)
    There are other things that need attention:
    Your above posted system details show outdated plugin(s) with known security and stability risks that you should update.
    *Java Plug-in 1.6.0_03 for Netscape Navigator (DLL Helper)
    Update the [[Java]] plugin to the latest version.
    *http://www.oracle.com/technetwork/java/javase/downloads/index.html (Java Platform: Download JRE)

  • Creating a Step for Background Job from within ABAP Program

    Step-1: I have a Report in ECC, which is scheduled as Background Job, which writes the file to the Application Server(UNIX)
    Step-2:  Trigger a Unix Command to ftp the file to other server.
    Both Step-1 & Step-2 can be done from SM36. 
    Another Scenario:
    Users can run the report in background from SE38 or using the transaction code for the report, In this case we want to call the external command.
    Instead of calling the External Command as below in the report, I want to create a Step from within the program when it is scheduled in background mode.
    CALL 'SYSTEM' ID 'COMMAND' FIELD lc_unixcom.    [ Here lc_unixcom has the External Command ].
    Any ideas??? Appreciate help.

    Hi,
    For submitting a report step, you may use either SUBMIT ... VIA JOB ... or JOB_SUBMIT function module.
    For external commands, this should be done only by calling JOB_SUBMIT function module.
    Sandra

  • How to find the Web AS Port from ABAP program

    Hi
    I have an ABAP program which passes an URL for a BSP page to the Alert Framework. While creating the URL I need to find out the Hostname and port number for the Web service for that server. Hostname comes from sy-host but I am not able to find the port number.
    Please help...
    Thanks in advance

    Hi,
    consider this little code snippet:
    data:  l_urls       type tihttpurls2.
    call method cl_http_server=>get_extension_info
       EXPORTING
        extension_class = 'cl_http_ext_bsp'                  
       IMPORTING
            urls            = l_urls.
    l_urls contains a table of configured ports. maybe that helps.
    regards, Ulli

Maybe you are looking for