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: 

Extra job getting created in dynamic handling of jobs

Former Member
0 Kudos

I have the below code and I notice an extra job that is being created in SM35. Any reasons/clues please

bdcjob will have A/P_ACCOUNTS_BDC

adrjob will have A/P_ACCOUNTS_ADDRESS

Name of the batch input session is A/P

The 3rd extra job that is coming up is 'A/P' and I did not open any job by that name.

Thanks for your help.

Kiran

 DATA: bdcjob TYPE tbtcjob-jobname,
      bdcnum TYPE tbtcjob-jobcount,
      adrjob TYPE tbtcjob-jobname,
      adrnum TYPE tbtcjob-jobcount,
      params LIKE pri_params,
      l_valid   TYPE c.

CHECK fileonly IS INITIAL.
MOVE: jobname TO bdcjob.
adrjob = 'A/P_ACCOUNTS_ADDRESS'.

IF NOT logtable[] IS INITIAL.
  IF NOT testrun IS INITIAL.
*   If its a test run, Non Batch-Input-Session
    SUBMIT rfbikr00 AND RETURN
                    USER sy-uname
                    WITH ds_name EQ file_o
                    WITH fl_check EQ 'X'.         "X=No Batch-Input
  ELSE.
*   Create a session which will be processed by a job
    SUBMIT rfbikr00 AND RETURN
                    USER sy-uname
                    WITH ds_name EQ file_o
                    WITH fl_check EQ ' '.
*   Open BDC Job
    CALL FUNCTION 'JOB_OPEN'
      EXPORTING
        jobname          = bdcjob
      IMPORTING
        jobcount         = bdcnum
      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.
    ELSE.
*     Submit RSBDCSUB to trigger the session in background mode
      SUBMIT rsbdcsub
        VIA  JOB    bdcjob
             NUMBER bdcnum
        WITH von     = sy-datum
        WITH bis     = sy-datum
        WITH z_verab = 'X'
        WITH logall  = 'X'
        AND RETURN.
      IF sy-subrc EQ 0.
*       Export data to a memory id. This data will be used by the program
*       that updates the address & email id
        EXPORT t_zzupdate TO SHARED BUFFER indx(st) ID 'MEM1'.
*       Get Print Parameters
        CALL FUNCTION 'GET_PRINT_PARAMETERS'
          EXPORTING
            no_dialog      = 'X'
          IMPORTING
            valid          = l_valid
            out_parameters = params.
*       Open a second job to trigger a program which updates addresses & email ids
        CALL FUNCTION 'JOB_OPEN'
          EXPORTING
            jobname          = adrjob
          IMPORTING
            jobcount         = adrnum
          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.
        ELSE.
*         submit the program to update email id & long addresses
          SUBMIT zfpa_praa_address_update
                 VIA JOB adrjob
                 NUMBER  adrnum
                 TO SAP-SPOOL WITHOUT SPOOL DYNPRO
                     SPOOL PARAMETERS params
                        AND RETURN.
          IF sy-subrc EQ 0.
*           First close the dependent job(address update job). Dependency
*           is shown by using pred_jobcount & pred_jobname parameters
            CALL FUNCTION 'JOB_CLOSE'
              EXPORTING
                jobcount             = adrnum
                jobname              = adrjob
                pred_jobcount        = bdcnum
                pred_jobname         = bdcjob
              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.
          ENDIF.
        ENDIF.
      ENDIF.
*     Close the main job(BDC Job)
      CALL FUNCTION 'JOB_CLOSE'
        EXPORTING
          jobcount             = bdcnum
          jobname              = bdcjob
          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
          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.
    ENDIF.
  ENDIF. 

Edited by: kiran dasari on Jul 9, 2010 12:58 AM

1 ACCEPTED SOLUTION

ThomasZloch
Active Contributor
0 Kudos

As for the formatting problem, please do take time to read the forum sticky notes occasionally.

Thomas

14 REPLIES 14

Jelena
Active Contributor
0 Kudos

Kiran, your code is unreadable - it looks like the tag did not work.

There are 2 sets of JOB_OPEN/JOB_CLOSE in the code though, so I'm not sure what did you expect...

Former Member
0 Kudos

I tried changing the tags..that did not help.

Since there are two open job statements, I expect to see ONLY two jobs in SM37 and am seeing 3 jobs as mentioned. That is the problem and I wish to know how and from where the 3rd job is getting created.

Let me try again and paste the code in the tags:

DATA: bdcjob TYPE tbtcjob-jobname,
      bdcnum TYPE tbtcjob-jobcount,
      adrjob TYPE tbtcjob-jobname,
      adrnum TYPE tbtcjob-jobcount,
      params LIKE pri_params,
      l_valid   TYPE c.

CHECK fileonly IS INITIAL.
MOVE: jobname TO bdcjob.
adrjob = 'A/P_ACCOUNTS_ADDRESS'.

IF NOT logtable[] IS INITIAL.
  IF NOT testrun IS INITIAL.
*   If its a test run, Non Batch-Input-Session
    SUBMIT rfbikr00 AND RETURN
                    USER sy-uname
                    WITH ds_name EQ file_o
                    WITH fl_check EQ 'X'.         "X=No Batch-Input
  ELSE.
*   Create a session which will be processed by a job
    SUBMIT rfbikr00 AND RETURN
                    USER sy-uname
                    WITH ds_name EQ file_o
                    WITH fl_check EQ ' '.
*   Open BDC Job
    CALL FUNCTION 'JOB_OPEN'
      EXPORTING
        jobname          = bdcjob
      IMPORTING
        jobcount         = bdcnum
      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.
    ELSE.
*     Submit RSBDCSUB to trigger the session in background mode
      SUBMIT rsbdcsub
        VIA  JOB    bdcjob
             NUMBER bdcnum
        WITH von     = sy-datum
        WITH bis     = sy-datum
        WITH z_verab = 'X'
        WITH logall  = 'X'
        AND RETURN.
      IF sy-subrc EQ 0.
*       Export data to a memory id. This data will be used by the program
*       that updates the address & email id
        EXPORT t_zzupdate TO SHARED BUFFER indx(st) ID 'MEM1'.
*       Get Print Parameters
        CALL FUNCTION 'GET_PRINT_PARAMETERS'
          EXPORTING
            no_dialog      = 'X'
          IMPORTING
            valid          = l_valid
            out_parameters = params.
*       Open a second job to trigger a program which updates addresses & email ids
        CALL FUNCTION 'JOB_OPEN'
          EXPORTING
            jobname          = adrjob
          IMPORTING
            jobcount         = adrnum
          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.
        ELSE.
*         submit the program to update email id & long addresses
          SUBMIT zfpa_praa_address_update
                 VIA JOB adrjob
                 NUMBER  adrnum
                 TO SAP-SPOOL WITHOUT SPOOL DYNPRO
                     SPOOL PARAMETERS params
                        AND RETURN.
          IF sy-subrc EQ 0.
*           First close the dependent job(address update job). Dependency
*           is shown by using pred_jobcount & pred_jobname parameters
            CALL FUNCTION 'JOB_CLOSE'
              EXPORTING
                jobcount             = adrnum
                jobname              = adrjob
                pred_jobcount        = bdcnum
                pred_jobname         = bdcjob
              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.
          ENDIF.
        ENDIF.
      ENDIF.
*     Close the main job(BDC Job)
      CALL FUNCTION 'JOB_CLOSE'
        EXPORTING
          jobcount             = bdcnum
          jobname              = bdcjob
          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
          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.
    ENDIF.
  ENDIF.
ELSEIF NOT t_zzupdate[] IS INITIAL.
* some other process
endif.

Thanks,

Kiran

Former Member
0 Kudos

I tried again and the format doesnt happen. Am not sure what to do to correct the alignment. I wish one of the moderators can look into this.

Thanks,

Kiran

Jelena
Active Contributor
0 Kudos

OK, it came out formatted in the 'watch' email. I think there is some kind of a bug in the forum...

So, anyway, which 'extra' job do you have - adrjob or bdcjob? I've never used the 'predecessor job' option myself, but maybe you need to do JOB_CLOSE for the predecessor first? You also could check the timestamp and options on the jobs in SM37 to troubleshoot this.

And why do you need two jobs to begin with? Couldn't one job include both steps? I don't really see how it would be different than having two separate jobs...

Also an unrelated note - I'd use IF... RETURN... ENDIF instead of a bunch of nested IF... ELSE... The code is rather difficult to follow in its current form.

Cheers.

Former Member
0 Kudos

I guess you did not make proper note from my first post. I need both adrjob & bdcjob. one other job am noticing is 'A/P'. which is the name of the BDC session. How and why is this getting created?

The reason why I cannot have both the jobs in steps of a single job is: the first one would trigger BDC Session. I will need to trigger the second job only after completion of the session. Hope this makes it clear now.

Any more clues please.

Thanks,

Kiran

Sandra_Rossi
Active Contributor
0 Kudos

Let me show you how to do it, it took me 2 minutes, I just removed what is not essential (list of exceptions), and please use Preview button.

> I tried changing the tags..that did not help.

> Since there are two open job statements, I expect to see ONLY two jobs in SM37 and am seeing 3 jobs as mentioned. That is the problem and I wish to know how and from where the 3rd job is getting created.

> Let me try again and paste the code in the tags:

DATA: bdcjob TYPE tbtcjob-jobname,
      bdcnum TYPE tbtcjob-jobcount,
      adrjob TYPE tbtcjob-jobname,
      adrnum TYPE tbtcjob-jobcount,
      params LIKE pri_params,
      l_valid   TYPE c.

CHECK fileonly IS INITIAL.
MOVE: jobname TO bdcjob.
adrjob = 'A/P_ACCOUNTS_ADDRESS'.

IF NOT logtable[] IS INITIAL.
  IF NOT testrun IS INITIAL.
*   If its a test run, Non Batch-Input-Session
    SUBMIT rfbikr00 AND RETURN
                    USER sy-uname
                    WITH ds_name EQ file_o
                    WITH fl_check EQ 'X'.         "X=No Batch-Input
  ELSE.
*   Create a session which will be processed by a job
    SUBMIT rfbikr00 AND RETURN
                    USER sy-uname
                    WITH ds_name EQ file_o
                    WITH fl_check EQ ' '.
*   Open BDC Job
    CALL FUNCTION 'JOB_OPEN'
      EXPORTING
        jobname          = bdcjob
      IMPORTING
        jobcount         = bdcnum
      EXCEPTIONS
        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.
    ELSE.
*     Submit RSBDCSUB to trigger the session in background mode
      SUBMIT rsbdcsub
        VIA  JOB    bdcjob
             NUMBER bdcnum
        WITH von     = sy-datum
        WITH bis     = sy-datum
        WITH z_verab = 'X'
        WITH logall  = 'X'
        AND RETURN.
      IF sy-subrc EQ 0.
*       Export data to a memory id. This data will be used by the program
*       that updates the address & email id
        EXPORT t_zzupdate TO SHARED BUFFER indx(st) ID 'MEM1'.
*       Get Print Parameters
        CALL FUNCTION 'GET_PRINT_PARAMETERS'
          EXPORTING
            no_dialog      = 'X'
          IMPORTING
            valid          = l_valid
            out_parameters = params.
*       Open a second job to trigger a program which updates addresses & email ids
        CALL FUNCTION 'JOB_OPEN'
          EXPORTING
            jobname          = adrjob
          IMPORTING
            jobcount         = adrnum
          EXCEPTIONS
            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.
        ELSE.
*         submit the program to update email id & long addresses
          SUBMIT zfpa_praa_address_update
                 VIA JOB adrjob
                 NUMBER  adrnum
                 TO SAP-SPOOL WITHOUT SPOOL DYNPRO
                     SPOOL PARAMETERS params
                        AND RETURN.
          IF sy-subrc EQ 0.
*           First close the dependent job(address update job). Dependency
*           is shown by using pred_jobcount & pred_jobname parameters
            CALL FUNCTION 'JOB_CLOSE'
              EXPORTING
                jobcount             = adrnum
                jobname              = adrjob
                pred_jobcount        = bdcnum
                pred_jobname         = bdcjob
              EXCEPTIONS
                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.
          ENDIF.
        ENDIF.
      ENDIF.
*     Close the main job(BDC Job)
      CALL FUNCTION 'JOB_CLOSE'
        EXPORTING
          jobcount             = bdcnum
          jobname              = bdcjob
          strtimmed            = 'X'
        EXCEPTIONS
          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.
    ENDIF.
  ENDIF.
ELSEIF NOT t_zzupdate[] IS INITIAL.
* some other process
endif.

Former Member
0 Kudos

Thank you Sandra Rossi.

ThomasZloch
Active Contributor
0 Kudos

As for the formatting problem, please do take time to read the forum sticky notes occasionally.

Thomas

0 Kudos

Thank you Thomas. I guess, my post exceeded 2500 chars and hence the format did not happen even though I placed the code in between

...

.

Any clues on the issue please.

Thanks,

Kiran

Edited by: kiran dasari on Jul 9, 2010 9:32 PM

0 Kudos

Please, reformat your question, and we'll try to help you !

0 Kudos

I already tried to do that and did not help. may be the no.of characters constraint.

Basically, I am opening a JOB A and submitting RSBDCSUB to fire a session in job. I am opening a JOB B and submitting program XYZ, the moment JOB A runs successfully. So, I expect to see two jobs get created in SM37 for JOB A & JOB B. But one other job is appearing with the "BDC SESSION NAME" in SM37. What could be the reason?

Thanks,

Kiran

0 Kudos

Standard behaviour. RSBDCSUB processes the sessions as a separate background job.

Thomas

0 Kudos

Hi Thomas, Did you mean to say that even though, my SUBMIT RSBDCSUB is pushed into JOB A, I will get to see two jobs: JOB A & 2nd job with session name?

Thanks,

Kiran

Edited by: kiran dasari on Jul 12, 2010 7:23 PM

0 Kudos

Yes, that's what I'm saying. When you process a session in background via SM35, there will also be a batch job with the name of the session, so same here.

Thomas