3 Replies Latest reply: Apr 23, 2013 8:51 PM by satyajit chaudhuri RSS

FM JOB_CLOSE doesn't wait for pred job even when pred_jobname/jobcount set

Ebru POLAT
Currently Being Moderated

Dear experts,

I need to call in sequential order two batch jobs when there is a special condition. It's not always the case, which means when there is no successor task, then the job should be executed immediately. But when there is another waiting in the queue, then

I set the parameters pred_jobcount/pred_jobname so that the next job is executed when the previous is finished.

 

I tried with the combination of several parameters, read lots of help and checked example programs, but the problem I've got: either both jobs are launched at the same time (so it does';t really wait for the predecessor to be completed sucessfully even if predjob_checkstat is set to X), or the second job is never launched at all! Here is the call of JOB_CLOSE:

 

AS_PRED contains the correct information of the predecessor job (I verified against SM37 and no problem there). For the first job to be launched, I have no issue at all. However the successor is not launched at all!

(Just to play around and to test some other parameter combination, I called the FM with strtimmed always set to X but then both jobs are launched at the same time, which is not convenient for me!).

 

   

IF as_pred IS INITIAL.
    lv_strt_immed = 'X'.
  ELSE.
    lv_strt_immed = space..
    lv_checkstat = 'X'.
  ENDIF.
* Plan job with direct start after predecessor job (if available)
  CALL FUNCTION 'JOB_CLOSE'
    EXPORTING
      jobcount             = me->job_count
      jobname              = me->job_name
      pred_jobcount        = as_pred-predjobcnt
      pred_jobname         = as_pred-predjob
      predjob_checkstat    = lv_checkstat
      strtimmed            = lv_strt_immed
    IMPORTING
      job_was_released     = lp_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
      invalid_target       = 8
      OTHERS               = 9.

 

Do you have any hint what might be wrong with the function call above?

 

Many thanks for you help, best regards

Ebru

  • Re: FM JOB_CLOSE doesn't wait for pred job even when pred_jobname/jobcount set
    Thomas Zloch
    Currently Being Moderated

    Prerequisite for this functionality is that the predecessor job (as defined in AS_PRED in your case) is not active or finished yet at the time of the JOB_CLOSE call for the successor job.

     

    Example sequence that works for me:

    - job_open and submit for job A (no job_close!)

    - job_open, submit and job_close for job B (with PRED parameters filled linking to job A)

    - job_close for job A (with STRTIMMED or scheduled date/time)

     

    Please align this with your scenario.

     

    Thomas

    • Re: FM JOB_CLOSE doesn't wait for pred job even when pred_jobname/jobcount set
      Ebru POLAT
      Currently Being Moderated

      Hello Thomas,

      Thanks for the info. I've also read the following in sap help that gives the sample program for job_close that waits for the successor:

       

      • Important: If you specify a predecessor job directly in your

      • program (not interactively chosen), then be sure that the

      • predecessor job has the status Scheduled or Released when

      • you schedule the successor job. Otherwise, the successor

      • scheduling will fail. That is, a job that is active or

      • already completed cannot be specified as a predecessor job.

       

      I guess this is the problem in my case, as you state the similar issue. However, I have the following difficulty: My job(s) is/are launched by a UI when user clicks on save button. After save, according to some conditions the job is launched. In most of the cases, single job is released, executed and it's finished. But in very minor cases, user might change the data and click on save very rapidly that th first job is still active. Then the second job is put into a table. Then I need to schedule the second job but it should be released only when the previous job is finished successfully.

       

      Isn't it possible to define such rules via call of job_close? In JOB_OPEN, I can't define such a rule (only start date and time which is not really convenient for me). Otherwise, I'd need to change the code in such a way that I won't let the user saving  second time if the job is not yet finished (but this might be a bit too restrictive in iour application).

       

      Many thanks for your help, best regards

      Ebru

  • Re: FM JOB_CLOSE doesn't wait for pred job even when pred_jobname/jobcount set
    satyajit chaudhuri
    Currently Being Moderated

    BP_JOB_CREATE can be used to create dependent jobs. The below sample program creates a chain of jobs. Prerequisite: the report program YTEST should exist.

    ++++++++++++++++++++++

    REPORT  yjob_chain.

    DATA cntr(3) TYPE n.

    PARAMETERS:

      job_str(10) TYPE c DEFAULT 'ABC', "default jobname template

      p_njobs TYPE i. "number of nodes in chain

     

    DATA jobname LIKE tbtcjob-jobname.

    DATA jobcount LIKE tbtcjob-jobcount.

    DATA pred_jobname LIKE tbtcjob-jobname.

    DATA pred_jobcount LIKE tbtcjob-jobcount.

    DATA flg_1stjob TYPE c.

     

    START-OF-SELECTION.

      CLEAR flg_1stjob.

      DO p_njobs TIMES.

        PERFORM create_job.

      ENDDO.

     

    *&---------------------------------------------------------------------*

    *&      Form  create_job

    *&---------------------------------------------------------------------*

    *       text

    *----------------------------------------------------------------------*

    FORM create_job.

      DATA global_job01 TYPE tbtcjob.

      DATA global_job02 TYPE tbtcjob.

      DATA steplist TYPE STANDARD TABLE OF tbtcstep.

      DATA stepline TYPE tbtcstep.

      stepline-program = 'YTEST'.

      stepline-typ = 'A'.

      stepline-authcknam = sy-uname.

      APPEND stepline TO steplist.

      cntr = cntr + 1.

      CONCATENATE job_str '-' cntr INTO jobname.

      global_job01-jobname = jobname.

      global_job01-jobclass = 'C'.

      IF flg_1stjob IS NOT INITIAL.

        global_job01-eventid = 'SAP_END_OF_JOB'.

        global_job01-eventparm = pred_jobname.

        global_job01-eventcount = pred_jobcount.

      ELSE.

        global_job01-reldate = sy-datum.

        global_job01-reltime = sy-timlo.

        global_job01-strtdate = sy-datum + 1.

        global_job01-strttime = '010000'.

      ENDIF.

      CALL FUNCTION 'BP_JOB_CREATE'

        EXPORTING

          job_cr_dialog       = 'N'

          job_cr_head_inp     = global_job01

        IMPORTING

          job_cr_head_out     = global_job02

        TABLES

          job_cr_steplist     = steplist

        EXCEPTIONS

          cant_create_job     = 1

          invalid_dialog_type = 2

          invalid_job_data    = 3

          job_create_canceled = 4

          OTHERS              = 5.

      IF sy-subrc = 0.

        pred_jobname = jobname.

        pred_jobcount = global_job02-jobcount.

        flg_1stjob = 'X'.

        WRITE:/ 'Created Job- ', 'Name: ', global_job02-jobname, 'Number: ', global_job02-jobcount.

      ELSE.

        WRITE:/ 'Error creating job'.

      ENDIF.

    ENDFORM.                    "create_job

Actions