Go to: run the ABAP report in the background

Source: Internet
Author: User

*&---------------------------------------------------------------------*
* & Report z_barry_set_job *
*&*
*&---------------------------------------------------------------------*
* & Set the background job. For more functions, see function group: btch *
*&---------------------------------------------------------------------*

Report z_barry_set_job.

Data: jobcount like tbtcjob-jobcount.
Data: abort type C,
Finish type C,
Prelim type C,
Ready type C,
Run type C,
Sched type C.

parameters: p_name like tbtcjob-jobname obligatory default 'z _ barry_test_job ',
p_date like sy-datum obligatory,
p_time like sy-uzeit obligatory.
select-options s_rept for Sy-repid no intervals obligatory.

Start-of-selection.
Call function 'job _ open' "to define a job
Exporting
Jobname = p_name
Importing
Jobcount = jobcount "job ID
Exceptions
Cant_create_job = 1
Invalid_job_data = 2
Jobname_missing = 3
Others = 4.
If sy-subrc <> 0.
Message ID sy-msgid type sy-msgty number sy-msgno
With sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
Endif.

Loop at s_rept.
Call function 'job _ submit '"scheduled this job
Exporting
Authcknam = sy-uname
Jobcount = jobcount
Jobname = p_name
Report = s_rept-low
* Variant = 'test'
Exceptions
Bad_priparams = 1
Bad_xpgflags = 2
Invalid_jobdata = 3
Jobname_missing = 4
Job_notex = 5
Job_submit_failed = 6
Lock_failed = 7
Program_missing = 8
Prog_abap_and_extpg_set = 9
Others = 10.
If sy-subrc <> 0.
Message ID sy-msgid type sy-msgty number sy-msgno
With sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
Endif.
Endloop.

Call function 'job _ close' "release this job
Exporting
Jobcount = jobcount
Jobname = p_name
Sdlstrtdt = p_date
Sdlstrttm = p_time
Exceptions
Cant_start_immediate = 1
Invalid_startdate = 2
Jobname_missing = 3
Job_close_failed = 4
Job_nosteps = 5
Job_notex = 6
Lock_failed = 7
Others = 8.
If sy-subrc <> 0.
Message ID sy-msgid type sy-msgty number sy-msgno
With sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
Endif.

Call function 'show _ jobstate'
Exporting
Jobcount = jobcount
Jobname = p_name
Importing
Aborted = abort
Finished = finish
Preliminary = prelim
Ready = ready
Running = run
Scheduled = sched
Exceptions
Jobcount_missing = 1
Jobname_missing = 2
Job_notex = 3
Others = 4.
If sy-subrc <> 0.
Message ID sy-msgid type sy-msgty number sy-msgno
With sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
Endif.

write:/'canceled: ', abort,
/'finished:', finish,
/'scheduled temporarily: ', prelim,
/'Ready for execution: ', ready,
/'Active:', run,
/'scheduling released: ', sched.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.