Skip to Content
avatar image
Former Member

regarding back ground job sheduling

hi,

could u plz clear my issu

i am running a report which i want to shedule in back ground by writing the code within in that program.

very urgent

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • avatar image
    Former Member
    Oct 09, 2007 at 02:11 PM

    Please refer to the below code...

    DATA: lv_job_name LIKE tbtco-jobname,

    lv_job_nr LIKE tbtco-jobcount,

    lv_job_released TYPE c,

    lv_job_start_sofort TYPE c,

    lv_print_parameters TYPE pri_params.

    lv_job_name = 'Z_BG_PGM'. " write your program name here

    CALL FUNCTION 'JOB_OPEN'

    EXPORTING

    jobname = lv_job_name

    IMPORTING

    jobcount = lv_job_nr

    EXCEPTIONS

    cant_create_job = 1

    invalid_job_data = 2

    jobname_missing = 3

    OTHERS = 4.

    IF syst-subrc = 0.

    *submit job with all the selection screen params...

    SUBMIT (lv_job_name)

    WITH p_apfile = applfile

    WITH p_lines = p_lines " parmeters of the bg pgm

    USER syst-uname " mandatory

    VIA JOB lv_job_name NUMBER lv_job_nr AND RETURN.

    IF sy-subrc = 0.

    CALL FUNCTION 'JOB_CLOSE'

    EXPORTING

    jobcount = lv_job_nr

    jobname = lv_job_name

    strtimmed = 'X'

    IMPORTING

    job_was_released = lv_job_released

    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 syst-subrc <> 0.

    MESSAGE i162(00) WITH

    'An error occured while closing the background job.'.

    STOP.

    ENDIF.

    ENDIF.

    ENDIF.

    SKIP 1.

    WRITE: / 'Background process', lv_job_name ,

    'called successfully' NO-GAP.

    WRITE: / 'You can check the job in transaction SM37'.

    Regards

    vasu

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 09, 2007 at 02:14 PM

    There are two ways for you to handle,

    one manually setting up the job through SM36 which is better and convinient,

    secondly through program using FM's JOB_OPEN, SUBMIT, JOB_CLOSE.

    Find below steps in doing both:

    Procedure 1:

    1. Goto Trans -> SM36

    2. Define a job with the program and variant if any

    3. Click on start condition in application tool bar

    4. In the pop-up window, click on Date/Time

    5. Below you can see a check box "Periodic Job"

    6. Next click on Period Values

    7. Select "Other Period"

    8. Now give '15' for Minutes

    9. Save the job

    In SM37 u can check the status of the jobs that u have assigned to background...

    Here u mention the job name or the report name to check the status of the job...

    After mentioning the job name or program name u just execute it.. ( without any name also u can execute then it gives u all the jobs set by your user name..

    the status colud be released,active,finished etc..

    Procedure 2 via Program:

    Below is a sample code for the same. Note the ZTEMP2 is the program i am scheduling with 15mins frequency.

    DATA: P_JOBCNT LIKE TBTCJOB-JOBCOUNT,

    L_RELEASE(1) TYPE c.

    CALL FUNCTION 'JOB_OPEN'

    EXPORTING

    JOBNAME = 'ZTEMP2'

    IMPORTING

    JOBCOUNT = P_JOBCNT

    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.

    SUBMIT ZTEMP2 VIA JOB 'ZTEMP2' NUMBER P_JOBCNT

    TO SAP-SPOOL WITHOUT SPOOL DYNPRO

    WITH DESTINATION = 'HPMISPRT'

    WITH IMMEDIATELY = SPACE

    WITH KEEP_IN_SPOOL = 'X' AND RETURN.

    CALL FUNCTION 'JOB_CLOSE'

    EXPORTING

    JOBCOUNT = P_JOBCNT

    JOBNAME = 'ZTEMP2'

    STRTIMMED = 'X'

    PRDMINS = 15

    IMPORTING

    JOB_WAS_RELEASED = L_RELEASE

    EXCEPTIONS

    CANT_START_IMMEDIATE = 1

    INVALID_STARTDATE = 2

    JOBNAME_MISSING = 3

    JOB_CLOSE_FAILED = 4

    JOB_NOSTEPS = 5

    JOB_NOTEX = 6

    LOCK_FAILED = 7

    INVALID_TARGET = 8

    OTHERS = 9.

    IF SY-SUBRC <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    **************

    *Submit report as job(i.e. in background)

    data: jobname like tbtcjob-jobname value

    ' TRANSFER TRANSLATION'.

    data: jobcount like tbtcjob-jobcount,

    host like msxxlist-host.

    data: begin of starttime.

    include structure tbtcstrt.

    data: end of starttime.

    data: starttimeimmediate like btch0000-char1.

    • Job open

    call function 'JOB_OPEN'

    exporting

    delanfrep = ' '

    jobgroup = ' '

    jobname = jobname

    sdlstrtdt = sy-datum

    sdlstrttm = sy-uzeit

    importing

    jobcount = jobcount

    exceptions

    cant_create_job = 01

    invalid_job_data = 02

    jobname_missing = 03.

    if sy-subrc ne 0.

    "error processing

    endif.

    • Insert process into job

    SUBMIT zreport and return

    with p_param1 = 'value'

    with p_param2 = 'value'

    user sy-uname

    via job jobname

    number jobcount.

    if sy-subrc > 0.

    "error processing

    endif.

    • Close job

    starttime-sdlstrtdt = sy-datum + 1.

    starttime-sdlstrttm = '220000'.

    call function 'JOB_CLOSE'

    exporting

    event_id = starttime-eventid

    event_param = starttime-eventparm

    event_periodic = starttime-periodic

    jobcount = jobcount

    jobname = jobname

    laststrtdt = starttime-laststrtdt

    laststrttm = starttime-laststrttm

    prddays = 1

    prdhours = 0

    prdmins = 0

    prdmonths = 0

    prdweeks = 0

    sdlstrtdt = starttime-sdlstrtdt

    sdlstrttm = starttime-sdlstrttm

    strtimmed = starttimeimmediate

    targetsystem = host

    exceptions

    cant_start_immediate = 01

    invalid_startdate = 02

    jobname_missing = 03

    job_close_failed = 04

    job_nosteps = 05

    job_notex = 06

    lock_failed = 07

    others = 99.

    if sy-subrc eq 0.

    "error processing

    endif.

    Thanks

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 09, 2007 at 02:17 PM

    Hi,

    Here is the sample program

    *Submit report as job(i.e. in background)

    data: jobname like tbtcjob-jobname value

    ' TRANSFER TRANSLATION'.

    data: jobcount like tbtcjob-jobcount,

    host like msxxlist-host.

    data: begin of starttime.

    include structure tbtcstrt.

    data: end of starttime.

    data: starttimeimmediate like btch0000-char1.

    • Job open

    call function 'JOB_OPEN'

    exporting

    delanfrep = ' '

    jobgroup = ' '

    jobname = jobname

    sdlstrtdt = sy-datum

    sdlstrttm = sy-uzeit

    importing

    jobcount = jobcount

    exceptions

    cant_create_job = 01

    invalid_job_data = 02

    jobname_missing = 03.

    if sy-subrc ne 0.

    "error processing

    endif.

    • Insert process into job

    SUBMIT zreport and return

    with p_param1 = 'value'

    with p_param2 = 'value'

    user sy-uname

    via job jobname

    number jobcount.

    if sy-subrc > 0.

    "error processing

    endif.

    • Close job

    starttime-sdlstrtdt = sy-datum + 1.

    starttime-sdlstrttm = '220000'.

    call function 'JOB_CLOSE'

    exporting

    event_id = starttime-eventid

    event_param = starttime-eventparm

    event_periodic = starttime-periodic

    jobcount = jobcount

    jobname = jobname

    laststrtdt = starttime-laststrtdt

    laststrttm = starttime-laststrttm

    prddays = 1

    prdhours = 0

    prdmins = 0

    prdmonths = 0

    prdweeks = 0

    sdlstrtdt = starttime-sdlstrtdt

    sdlstrttm = starttime-sdlstrttm

    strtimmed = starttimeimmediate

    targetsystem = host

    exceptions

    cant_start_immediate = 01

    invalid_startdate = 02

    jobname_missing = 03

    job_close_failed = 04

    job_nosteps = 05

    job_notex = 06

    lock_failed = 07

    others = 99.

    if sy-subrc eq 0.

    "error processing

    endif.

    Regards,

    Padmam.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 09, 2007 at 02:20 PM

    hi

    good

    check this code

    We can do this by Creating a background Job dynamically and using the ABAP Memory (Export / Import).

    You can try to SUBMIT to this program in the background using a JOB.

    SAMPLE CODE:

    DATA: print_parameters TYPE pri_params,

    valid_flag TYPE c LENGTH 1.

    START-OF-SELECTION.

    CALL FUNCTION 'GET_PRINT_PARAMETERS'

    IMPORTING

    out_parameters = print_parameters

    valid = valid_flag

    EXCEPTIONS

    invalid_print_params = 2

    OTHERS = 4.

    CALL FUNCTION 'JOB_OPEN'

    EXPORTING

    jobname = name

    IMPORTING

    jobcount = number

    EXCEPTIONS

    cant_create_job = 1

    invalid_job_data = 2

    jobname_missing = 3

    OTHERS = 4.

    IF sy-subrc = 0.

    EXPORT ITAB TO MEMORY ID 'ABC'.

    SUBMIT ZREP2 TO SAP-SPOOL

    SPOOL PARAMETERS print_parameters

    WITHOUT SPOOL DYNPRO

    VIA JOB name NUMBER number

    AND RETURN.

    IF sy-subrc = 0.

    CALL FUNCTION 'JOB_CLOSE'

    EXPORTING

    jobcount = number

    jobname = name

    strtimmed = 'X'

    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.

    ...

    ENDIF.

    ENDIF.

    ENDIF.

    reward point if helpful.

    thanks

    mrutyun^

    Add comment
    10|10000 characters needed characters exceeded