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: 

schedule Job with Job_close after successful job doesn't work

Former Member
0 Kudos
1,045

Hi guys,

I'm using FM CLOSE_JOB with parameters :

JOBCOUNT = w_JobId

JOBNAME = w_JobName

PREDJOB_CHECKSTAT = 'X'

PRED_JOBCOUNT = w_oldJobId

PRED_JOBNAME = w_oldJobName

I have about 9 jobs wich must run the one after the others. The first start without PRED* parameters, but the 8 others one are filled with CHECKSTAT, and previous job name and id.

It works fine for the side "the one after the others", BUT, wathever the previous job give as result (cancelled or finished), the next one starts whereas I pass the parameter CHECKSTAT to X.

Any ideas of the problem and how to solve it?

Thanks in advance for your answers.

1 ACCEPTED SOLUTION

ThomasZloch
Active Contributor
0 Kudos
404

My first question is, why don't you use one job with nine steps, then you would have the desired "one after the other and only when successful" functionality.

A typical catch when using the predecessor functionality is that you must call the JOB_CLOSE for the first job in the queue after you have submitted and closed all the successor jobs (if you want to start the queue immediately, that is), but this seems to work OK in your case based on your description. I have not heard yet of problems with CHECKSTAT not working as intended.

Thomas

11 REPLIES 11

ThomasZloch
Active Contributor
0 Kudos
405

My first question is, why don't you use one job with nine steps, then you would have the desired "one after the other and only when successful" functionality.

A typical catch when using the predecessor functionality is that you must call the JOB_CLOSE for the first job in the queue after you have submitted and closed all the successor jobs (if you want to start the queue immediately, that is), but this seems to work OK in your case based on your description. I have not heard yet of problems with CHECKSTAT not working as intended.

Thomas

0 Kudos
404

Hi Thomas and thanks for your quick answer,

Effectively, I run the first JOB_CLOSE after I have closed the 8 others jobs. The only problem I met is that my second job is running whereas my first job get the status Canceled.

I can effectively code by another way to solve this, but as I already implement the solution with job_open and job_close, I don't want to break my code and do it again whereas SAP 'JOB_CLOSE' function module seems to give me the solution.

Regards,

0 Kudos
404

Cannot replicate the problem here, I have such a chain as well and just forced a cancelled job (seventh one out of fifteen), all successor jobs did not run, as expected.

No further idea at this point, other than trivial typos or bugs in the code, that we all love to overlook

Thomas

P.S. maybe it would help if you post the code for your first and second job as well as the last JOB_CLOSE here, don't let the post grow too big though, or the formatting is lost

0 Kudos
404

Hi

You don't have to break anything

You can create a only big job with 9 step

Max

0 Kudos
404

Here my code with explanation :

REPORT  YCOMJ023.

[....]
start-of-selection.
[....]

"Initialization of my vars
w_StepCount = 0. >> number of steps maxi in a job
w_jobCount = 1.  >> number to see easier in SM37 the job order
CONCATENATE pe_name '_STEPS' w_jobCountC INTO w_JobName. (example : TOTO_STEP1)
CONDENSE w_JobName NO-GAPS.

"I open my first job
  CALL FUNCTION 'JOB_OPEN' (OPEN job TOTO_STEP1)
    EXPORTING
      jobname          = w_JobName
    IMPORTING
      jobcount         = w_JobID
    EXCEPTIONS
      cant_create_job  = 1
      invalid_job_data = 2
      jobname_missing  = 3
      OTHERS           = 4.

"We keep in memory first job IDs to close it at the end of the prg
  w_firstjobName = w_JobName.
  w_firstjobID = w_JobID.

"imagine you do the bellow code in a loop and it makes several jobs TOTO_STEP2 TOTO_STEP3 TOTO_STEP4...
 ADD 1 TO w_StepCount.
 IF w_StepCount GT 250.
    "I call close job eatch time I reach 250 steps
     PERFORM fx_jobclose.
 ENDIF.
 submit RKGALKEUB to sap-spool and return
                                   without spool dynpro
                                   spool parameters print_parameters
                                        VIA JOB w_JobName NUMBER w_JobID


"End of the programmI close the current Job and the first one : 
"Current
        CALL FUNCTION 'JOB_CLOSE'
          EXPORTING
            JOBCOUNT             = w_JobId
            JOBNAME              = w_JobName
            PREDJOB_CHECKSTAT    = 'X'
            PRED_JOBCOUNT        = w_oldJobId
            PRED_JOBNAME         = w_oldJobName.

"First one + launch with STRIMMED
        CALL FUNCTION 'JOB_CLOSE'
        EXPORTING
          JOBCOUNT             = w_firstjobId
          JOBNAME              = w_firstjobName
          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.



*&---------------------------------------------------------------------*
*&      Form  fx_jobclose
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM fx_jobclose.
  "Step to zero to do a new loop after this form
  w_StepCount = 0.
  DATA : w_job_released TYPE CHAR1.

  "If the flag IsFirst, we don't do nothing, because it's the first JOb, and it should not be closed
  IF w_IsFirst = 'X'.
    "Flag is set to blank 
    w_IsFirst = ''.
  ELSE.
      "Else it mean we are closing a job with predecessor : 
      CALL FUNCTION 'JOB_CLOSE'
        EXPORTING
          JOBCOUNT             = w_JobId
          JOBNAME              = w_JobName
          PREDJOB_CHECKSTAT    = 'X'
          PRED_JOBCOUNT        = w_oldJobId
          PRED_JOBNAME         = w_oldJobName
          "SDLSTRTDT            = sy-datum
          "SDLSTRTTM            = sy-timlo
        IMPORTING
          JOB_WAS_RELEASED = w_job_released.
  ENDIF.

  "Vars get the value of current job, witch will become the older one
  w_oldJobId = w_jobID.
  w_oldJobName = w_JobName.
 "I make the new TOTO_STEPX job name
  ADD 1 TO w_jobCount.
  w_jobCountC = w_jobCount.
  CONCATENATE pe_name '_STEPS' w_jobCountC INTO w_JobName.
  CONDENSE w_JobName NO-GAPS.

  "I open the new job
  CALL FUNCTION 'JOB_OPEN'
    EXPORTING
      jobname          = w_JobName
    IMPORTING
      jobcount         = w_JobId
    EXCEPTIONS
      cant_create_job  = 1
      invalid_job_data = 2
      jobname_missing  = 3
      OTHERS           = 4.

ENDFORM.                    "fx_jobclose

I hope my code is clear enought, I tried to delete the superfluities code.

0 Kudos
404

Hi,

I think the issue is that you should'nt release the first job immediately because then the second can't be linked to the first as it is released!

Sandra

0 Kudos
404

Hi Sandra,

In fact, this is that I already do. I record my vars for my first job opened in order to release it at the end of the program.

And this works, because my jobs starts the one after the others. The only issue is that the nexts jobs start even if the job got the status cancelled and I want it to wait after a status finished only.

Any other idea ?

Thanks,

0 Kudos
404

If I've understood.....

You need to run a large number of program, so you're trying to create many jobs having a certain number of steps (max 250 programs), every job can start only if the previous job is finished successfully.

If it's so your code seems to be good, I've tried to schedule two jobs, the second one is linked to the first one:

if an error occurs while running the first job, so its status will be cancelled, the second will be also placed in cancelled status and so it doesn't start.

I can't understand why your job starts even if the previuos job has cancelled status, what I expect if a job is nterrupted all next jobs will be nterrupted.

I've scheduled my jobs by SM36, not programmatically, but I suppose the behavior should be the same.

U can try to insert a "traffic light" program as the first step of every job in order to check the true status of the previos job and abort it if it's neccessary.....but it should be useless.

Max

0 Kudos
404

Hi,

Sorry, I read a little too fast! That's really surprising.

Did you try with and without CHECKSTAT, and did you check SAP notes?

Sandra

0 Kudos
404

Ok Guys I fixed the issue.

If other people get the same :

Note 37624 - Creating status-dependent job chains

Jobs in background wich are calling KEUB and KEU5 T-Code could contains S-Message so you will see jobs cancelled, but this doesn't mean that the job is considered by the system as cancelled. That's why the others job will start whereas job got the status cancelled in SM37.

In fact, SAP do that because of customers request because many customers doesn't want to block the chain depending on KEU5 and KEUB (here) error messages.

So in my case I will see what my customer want to do but I guess I will let the jobs starts even if I got S-Messages.

Cheers,

Edited by: Joseph Nunes on Aug 29, 2011 9:46 AM

0 Kudos
404

Thanks for posting the solution.

Thomas