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: 

Execute a Job in a specific time

michael_teran
Participant
0 Kudos
518

Hi Friends,

I want to create a job that is gonna start in a specific time.

But when the job is executed It does not receive the parameters that I'm sending with the sentence SUBMIT.

The code is:

  • BEGIN JOB

CALL FUNCTION 'JOB_OPEN'

EXPORTING

jobname = ls_job

sdlstrtdt = '20080702'

sdlstrttm = '180830'

jobclass = 'A'

IMPORTING

jobcount = li_number

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.

  • EXECUTE PROGRAMM Z WITH 3 PARAMETERS

SUBMIT zmmp0421

WITH pa_bukrs EQ e_trbkpv-bukrs

WITH pa_belnr EQ e_trbkpv-belnr

WITH pa_gjahr EQ e_trbkpv-gjahr

USER ls_user VIA JOB ls_job NUMBER li_number

AND RETURN.

  • CLOSE JOB

CALL FUNCTION 'JOB_CLOSE'

EXPORTING

jobcount = li_number

jobname = ls_job

sdlstrtdt = '20080702'

sdlstrttm = '180830'

dont_release = ' '

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.

Could you plzzz tell me ... what's wrong???

1 ACCEPTED SOLUTION

Former Member
0 Kudos
205

Hi Michael,

I once had a similar task.

I then created a job variant using FM's RS_VARIANT_EXISTS and RS_CREATE_VARIANT

I then submitted the Job with the FM JOB_SUBMIT with the created variant.

Kind Regards

Raymond

3 REPLIES 3

Former Member
0 Kudos
206

Hi Michael,

I once had a similar task.

I then created a job variant using FM's RS_VARIANT_EXISTS and RS_CREATE_VARIANT

I then submitted the Job with the FM JOB_SUBMIT with the created variant.

Kind Regards

Raymond

former_member705122
Active Contributor
0 Kudos
205

Hi,

Check this:

* DATA DECLARATION...............
DATA: 
  JOBNAME  LIKE TBTCJOB-JOBNAME VALUE '<GIVE THE JOBNAME>',                          
  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

Adil

valter_oliveira
Active Contributor
0 Kudos
205

Hello there!

Just look to some comments to your code:

1 - When you OPEN the job, don't give a start time and not needed paramters, that can avoid it to work properly.


CALL FUNCTION 'JOB_OPEN'
     EXPORTING
          jobname          = w_jobname
     IMPORTING
          jobcount         = w_jobcount
     EXCEPTIONS
          cant_create_job  = 1
          invalid_job_data = 2
          jobname_missing  = 3
          OTHERS           = 4.

2 - If you want your JOB to start in a specific time, why do you use parameter strtimmed EQ 'X' at CLOSE job? It's not coerent.


CALL FUNCTION 'JOB_CLOSE'
     EXPORTING
          jobcount             = w_jobcount
          jobname              = w_jobname
          sdlstrtdt            = sy-datum
          sdlstrttm            = l_hora
          targetserver         = w_servidor
     IMPORTING
          job_was_released     = l_liberado
     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.

3 - To pass parameters to your submited report, use a table to pass those to it:


DATA: seltab     TYPE TABLE OF rsparams,
      seltab_wa  LIKE LINE OF seltab.

CLEAR seltab_wa.
seltab_wa-selname = 'PA_BUKRS'.
seltab_wa-low = e_trbkpv-bukrs.
APPEND seltab_wa TO seltab.
seltab_wa-selname = 'PA_BELNR'.
seltab_wa-low = e_trbkpv-belnr.
APPEND seltab_wa TO seltab.
seltab_wa-selname = 'PA_GJAHR'.
seltab_wa-low = e_trbkpv-gjahr.
APPEND seltab_wa TO seltab.

SUBMIT zmmp0421
    WITH  SELECTION-TABLE seltab
    USER sy-uname
 VIA JOB w_jobname NUMBER w_jobcount
     AND RETURN.

Hope this helps you some way.

Regards.

Valter Oliveira.