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: 

Job Scheduling using job_close

Former Member
0 Kudos

Hi gurus,

im trying to scheduke several jobs using the FM Job close, but the jobs are running paralel..

The first job its' schedule with a start date or imediate, and the letf ones are schedule to start after his precessor finish, but once i run the programa 4 jobs start running ...

Can any one help me on this?

Below goes my code...

 


  DO njobs TIMES.
**Nome de Job

    CLEAR: jobname, jobcount, job_release.
    CLEAR: job_imediate, str_job.

    ADD 1 TO ind_job.
    WRITE ind_job TO str_job.
    CONCATENATE 'EXECORC' sy-uname sy-uzeit str_job
                 INTO jobname SEPARATED BY '-'.


    CALL FUNCTION 'JOB_OPEN'
         EXPORTING
              jobname          = jobname
         IMPORTING
              jobcount         = jobcount
         EXCEPTIONS
              cant_create_job  = 1
              invalid_job_data = 2
              jobname_missing  = 3
              OTHERS           = 4.
    IF sy-subrc <> 0.
      MESSAGE i003(zmapas).
      EXIT.
    ENDIF.


    IF gv_global EQ 'X'.

**Submit job
      SUBMIT z_mapa_execucao_orcamental
             VIA JOB jobname NUMBER jobcount
             WITH ano EQ ano
             WITH so_perio IN so_perio
             WITH so_date IN so_date
             WITH so_org EQ so_org
             WITH so_num IN so_num
             AND RETURN.




    ELSE.
***Limites
      CLEAR: upper_bound, lower_bound.
      upper_bound = njobs * ind_job.
      lower_bound = upper_bound - njobs + 1.

      CLEAR so_num.
      REFRESH so_num.

      LOOP AT tab_prog FROM lower_bound TO upper_bound.
        so_num-sign = 'I'.
        so_num-option = 'EQ'.
        so_num-low = tab_prog-zlinha.
        APPEND so_num.
      ENDLOOP.


      SUBMIT z_mapa_execucao_orcamental
             VIA JOB jobname NUMBER jobcount
             WITH ano EQ ano
             WITH so_perio IN so_perio
             WITH so_date IN so_date
             WITH so_org EQ so_org
             WITH so_num IN so_num
             AND RETURN.
    ENDIF.

    IF ind_job EQ 1.
      IF stdt_output-startdttyp EQ 'I'.
        job_imediate = 'X'.
      ENDIF.
      CALL FUNCTION 'JOB_CLOSE'
           EXPORTING
                jobcount             = jobcount
                jobname              = jobname
                sdlstrtdt            = stdt_output-sdlstrtdt
                sdlstrttm            = stdt_output-sdlstrttm
                strtimmed            = job_imediate
           IMPORTING
                job_was_released     = job_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
                OTHERS               = 8.
      IF sy-subrc <> 0.
        MESSAGE i003(zmapas).
        EXIT.
      ELSE.
        CLEAR: predjob, predjobcount, stdt_output.
        predjob = jobname.
        predjobcount = jobcount.
        MESSAGE s004(zmapas) WITH jobname.
      ENDIF.


    ELSE.

      CALL FUNCTION 'JOB_CLOSE'
           EXPORTING
                jobcount             = jobcount
                jobname              = jobname
*                predjob_checkstat    = 'X'
                pred_jobcount        = predjobcount
                pred_jobname         = predjob
*                strtimmed            = 'X'
           IMPORTING
                job_was_released     = job_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
                OTHERS               = 8.
      IF sy-subrc <> 0.
        MESSAGE i003(zmapas).
        EXIT.
      ELSE.
        CLEAR: predjob, predjobcount, stdt_output.
        predjob = jobname.
        predjobcount = jobcount.
        MESSAGE s004(zmapas) WITH jobname.
      ENDIF.
    ENDIF.

Thanks in Advance,

Best Regards,

João Martins

1 ACCEPTED SOLUTION

Former Member

Hi Thomas,

thanks for your reply but my problem it's a little bit diferent from the link you gave me. I need to schedule several jobs, not only 2... My idea it's that the second job only starts after the first one finishs and so on...

I also have a doubt in this FM, if someone could help me on this...

In the first call to the FM JOB_CLOSE the parameters sdlstrtdt sdlstrttm sdlstrttm are filled either with the imediate parameter or the start date and time, but after the first call until the last job close the only parameters that it makes sense to fill it up, to me, are the jobname jobcount pred_jobcount and the pred_jobname. I dont understand why we have to fill up the strtimmed parameter ?!?! and also what does the * predjob_checkstat* do?

Thanks again for your reply,

Best Regards,

João Martins

9 REPLIES 9

ThomasZloch
Active Contributor
0 Kudos

just went through a similar problem here, maybe this will help:

Greetings

Thomas

Former Member

Hi Thomas,

thanks for your reply but my problem it's a little bit diferent from the link you gave me. I need to schedule several jobs, not only 2... My idea it's that the second job only starts after the first one finishs and so on...

I also have a doubt in this FM, if someone could help me on this...

In the first call to the FM JOB_CLOSE the parameters sdlstrtdt sdlstrttm sdlstrttm are filled either with the imediate parameter or the start date and time, but after the first call until the last job close the only parameters that it makes sense to fill it up, to me, are the jobname jobcount pred_jobcount and the pred_jobname. I dont understand why we have to fill up the strtimmed parameter ?!?! and also what does the * predjob_checkstat* do?

Thanks again for your reply,

Best Regards,

João Martins

0 Kudos

Hello.

First of all, parameter predjob_checkstat makes the second job to start only if the previous one ends without error. Probably this solves your problem at all ... the second waits to the end of the first to see if it ended with error or not.

I was analysing your problem. Parameter strtimmed can only be set in the first JOB_CLOSE. All the others cannot have this parameter set to 'X' if you want them to wait for the end of the previous ones.

So, try predjob_checkstat = 'X' and strtimmed = space.

Also, I have one example that is working:


*** Escalona um JOB para cada ficheiro encontrado.
    LOOP AT t_processar.

      CLEAR: w_jobcount, w_jobname, l_liberado.

      ADD 1 TO l_conta.
      MOVE l_conta TO l_conta2.
      CONDENSE l_conta2.

      CONCATENATE t_jobs-jobname l_conta2 INTO w_jobname.

      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.


***   Criou-se o JOB com sucesso
      IF sy-subrc = 0.
        CLEAR seltab_wa.

***     Monta o parâmetro
        MOVE: t_jobs-param TO seltab_wa-selname,
              t_processar-line+34 TO seltab_wa-low.
        APPEND seltab_wa TO seltab.
        seltab_wa-selname = 'P_LOJA'.
        seltab_wa-low = t_processar-ficheiro+7(4).
        APPEND seltab_wa TO seltab.


***     Submete o programa para o JOB
        SUBMIT (t_jobs-repid)
               WITH  SELECTION-TABLE seltab
               USER sy-uname
               VIA JOB w_jobname NUMBER w_jobcount
               AND RETURN.

***     Encerra o JOB
        IF l_conta EQ 1.
          l_hora = sy-uzeit.
          ADD 120 TO l_hora.

          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.
        ELSE.
          CALL FUNCTION 'JOB_CLOSE'
               EXPORTING
                    jobcount             = w_jobcount
                    jobname              = w_jobname
                    predjob_checkstat    = 'X'
                    pred_jobcount        = w_jobcount2
                    pred_jobname         = w_jobname2
                    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.

        ENDIF.  "l_conta eq ...

      ENDIF. "sy-subrc = 0 do JOB-OPEN

      w_jobname2  = w_jobname.
      w_jobcount2 = w_jobcount.

      PERFORM f_limpa_param.
    ENDLOOP. "at t_processar

Regards.

Valter Oliveira.

0 Kudos

Based on the analysis I have done in the quoted thread, I suggest the following approach for scheduling n jobs with predecessor dependency:

- JOB_OPEN and SUBMIT for first job, but no JOB_CLOSE yet, if immediate start is required!

- JOB_OPEN / SUBMIT / JOB_CLOSE for the subsequent jobs, for each one giving jobcount and jobname from the predecessor job in PRED_JOBNAME and PRED_JOBCOUNT, PREDJOB_CHECKSTAT as desired, but no STRTIMMED!

- JOB_CLOSE for the first job with STRTIMMED = "X"

try to reflect this in your code, there is a good chance it will work.

Thomas

0 Kudos

uhmmm ... thomas solution probably works ... and maybe that's why my example works ... because my first JOB_CLOSE only starts 2 minutes after the schedule, i.e, after all the closes done.

l_hora = sy-uzeit.

ADD 120 TO l_hora.

Regards.

Valter Oliveira.

0 Kudos

just tried it here with 10 jobs in a row and immediate start...bingo

Former Member
0 Kudos

Hi Valter,

Thanks for your reply.

I thought that way to, in the second job_close call, but it's giving me an error of invalid_startdate ....!!!! i dont understand why because if has a predjob it's shouldnt had a start date and time... am i correct?



    IF ind_job EQ 1.
      IF stdt_output-startdttyp EQ 'I'.
        job_imediate = 'X'.
      ENDIF.
***Primeiro Job
      CALL FUNCTION 'JOB_CLOSE'
           EXPORTING
                jobcount             = jobcount
                jobname              = jobname
                sdlstrtdt            = stdt_output-sdlstrtdt
                sdlstrttm            = stdt_output-sdlstrttm
                strtimmed            = job_imediate
           IMPORTING
                job_was_released     = job_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
                OTHERS               = 8.
      IF sy-subrc <> 0.
        MESSAGE i003(zmapas).
        EXIT.
      ELSE.
        CLEAR: predjob, predjobcount, stdt_output.
        predjob = jobname.
        predjobcount = jobcount.
        MESSAGE s004(zmapas) WITH jobname.
      ENDIF.


    ELSE.
**Jobs Seguintes
      CALL FUNCTION 'JOB_CLOSE'
           EXPORTING
                jobcount             = jobcount
                jobname              = jobname
                predjob_checkstat    = 'X'
                pred_jobcount        = predjobcount
                pred_jobname         = predjob
                strtimmed            = space
           IMPORTING
                job_was_released     = job_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
                OTHERS               = 8.
      IF sy-subrc <> 0.
        MESSAGE i003(zmapas).
        EXIT.
      ELSE.
        CLEAR: predjob, predjobcount, stdt_output.
        predjob = jobname.
        predjobcount = jobcount.
        MESSAGE s004(zmapas) WITH jobname.
      ENDIF.
    ENDIF.

Thanks,

Regards,

João Martins

0 Kudos

Hi again.

Yes, you are correct. As you can see in my example, I don't even use parameter strtimmed because it makes no sense. In SM36, when you define a job, looking to a previous job, you don't have that option (starting time).

This may sound stupid, but try like this (perhaps parameter strtimmed affects the flow of JOB_CLOSE FM):


CALL FUNCTION 'JOB_CLOSE'
           EXPORTING
                jobcount                  = jobcount
                jobname                  = jobname
                predjob_checkstat    = 'X'
                pred_jobcount          = predjobcount
                pred_jobname          = predjob
           IMPORTING
                job_was_released     = job_release
           EXCEPTIONS
                cant_start_immediate = 1
           ...

Looking to your code everything looks fine.

Regards.

Valter Oliveira.

Edited by: Valter Oliveira on Jul 2, 2008 3:17 PM

Former Member
0 Kudos

Guys that's it...

Thanks Thomas and Valter foryour contribution, point will be rewarded..

Best Regards,

João Martins