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: 

Spool list is not getting created for background job

Former Member
0 Kudos

I am creating background job using JOB_OPEN and then submitting my z-report using submit statement and then closing job using JOB_CLOSE. for this job is getting creating in sm37 and also gets finished but it does not create spool list showing output.

Any idea how to do this?

Thanks in advance.

9 REPLIES 9

Former Member
0 Kudos
   
DATA: sdate TYPE sy-datum,
           stime TYPE sy-uzeit,
           l_valid,
           ls_params LIKE pri_params,
           l_jobcount LIKE tbtcjob-jobcount,
           l_jobname LIKE tbtcjob-jobname.

START-OF-SELECTION.

* Get Print Parameters

  CALL FUNCTION 'GET_PRINT_PARAMETERS'
    EXPORTING
      no_dialog      = 'X'
    IMPORTING
      valid          = l_valid
      out_parameters = ls_params.

* Open Job

  l_jobname = 'ZJOB'.
  CALL FUNCTION 'JOB_OPEN'
    EXPORTING
      jobname  = l_jobname
    IMPORTING
      jobcount = l_jobcount.

* Submit report to job

  SUBMIT zrtest
  VIA JOB l_jobname
  NUMBER l_jobcount
  TO SAP-SPOOL WITHOUT SPOOL DYNPRO
  SPOOL PARAMETERS ls_params
  AND RETURN.

* Kick job off 60 seconds from now.
  sdate = sy-datum.
  stime = sy-uzeit + 60.

* Schedule and close job.
  CALL FUNCTION 'JOB_CLOSE'
  EXPORTING
  jobcount = l_jobcount
  jobname = l_jobname
  sdlstrtdt = sdate    

Edited by: Tanmoy Mondal on Aug 25, 2011 8:43 AM

Former Member
0 Kudos

DATA: lv_jobname TYPE tbtcjob-jobname,

lv_jobcount TYPE tbtcjob-jobcount,

lv_variant TYPE variant,

wa_var_desc TYPE varid,

wa_var_text TYPE varit,

it_var_text TYPE TABLE OF varit,

it_var_contents TYPE TABLE OF rsparams.

REFRESH: it_var_contents, it_var_text.

CLEAR: wa_var_desc, wa_var_text.

CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'

EXPORTING

curr_report = sy-cprog

TABLES

selection_table = it_var_contents

EXCEPTIONS

not_found = 1

no_report = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CONCATENATE sy-datum sy-timlo INTO lv_variant.

wa_var_desc-mandt = sy-mandt.

wa_var_desc-report = sy-cprog.

wa_var_desc-variant = lv_variant.

wa_var_desc-transport = 'F'.

wa_var_desc-environmnt = 'B'.

wa_var_desc-version = '1'.

wa_var_desc-protected = 'X'.

wa_var_text-mandt = sy-mandt.

wa_var_text-langu = sy-langu.

wa_var_text-report = sy-cprog.

wa_var_text-variant = lv_variant.

lv_jobname = lv_variant.

CONCATENATE 'Batch Job Variant -'(006)

sy-uname INTO wa_var_text-vtext.

APPEND wa_var_text TO it_var_text.

  • Create the varaint for the back ground job.

CALL FUNCTION 'RS_CREATE_VARIANT'

EXPORTING

curr_report = sy-cprog

curr_variant = lv_variant

vari_desc = wa_var_desc

TABLES

vari_contents = it_var_contents

vari_text = it_var_text

EXCEPTIONS

illegal_report_or_variant = 1

illegal_variantname = 2

not_authorized = 3

not_executed = 4

report_not_existent = 5

report_not_supplied = 6

variant_exists = 7

variant_locked = 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.

  • Open the job.

CALL FUNCTION 'JOB_OPEN'

EXPORTING

jobname = lv_jobname

IMPORTING

jobcount = lv_jobcount

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.

  • submitt the job in background mode.

CALL FUNCTION 'JOB_SUBMIT'

EXPORTING

authcknam = sy-uname

jobcount = lv_jobcount

jobname = lv_jobname

report = sy-repid

variant = lv_variant

EXCEPTIONS

bad_priparams = 1

bad_xpgflags = 2

invalid_jobdata = 3

jobname_missing = 4

job_notex = 5

job_submit_failed = 6

lock_failed = 7

program_missing = 8

prog_abap_and_extpg_set = 9

OTHERS = 10.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

  • close the job.

CALL FUNCTION 'JOB_CLOSE'

EXPORTING

jobcount = lv_jobcount

jobname = lv_jobname

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.

Hope this will be helpful..

Former Member
0 Kudos

@Tanmoy Mondal: I have done the same thing but still there is no list. Actually in my z-report which i am submitting i have used BAPI and i am using job_open after taking data from txt file in internal table.

0 Kudos

Some questions

- Which BAPI do you call in your program

- Do you manage RETURN parameter of the BAPI

- Do you check print parameters

Regards,

Raymond

0 Kudos

BAPI - BAPI_GOODSMVT_CREATE

Yes i have managed RETURN for it.

0 Kudos

AFAIK BAPI_GOODSMVT_CREATE wont generate any spool, the success message is in RETURN parameter...

Regards,

Raymond

0 Kudos

But i am taking messages from return into internal table and then writing these messages using write statement. When i run this report in foreground then i get these messages on output screen but no list is generated when i run the same in background.

0 Kudos

So do you check print parameters are okay: printer, time to print, keep, etc. (PRIPARAMS in JOB_SUBMIT), or do you use wrong (in this case) option in a SUBMIT statement like [EXPORTING LIST TO MEMORY|http://help.sap.com/abapdocu_70/en/ABAPSUBMIT_LIST_OPTIONS.htm] or [TO SAP-SPOOL|http://help.sap.com/abapdocu_70/en/ABAPSUBMIT_PRINT_PARAMETERS.htm] wrong option ?

For testing purpose, you can also use a MESSAGE TYPE 'I' along with the WRITE statement, so the success (or error) message will appear in job log. (and you will be sure that the program executes this piece of code)

0 Kudos

I have written code for scheduling as:


CALL FUNCTION 'GET_PRINT_PARAMETERS'
    EXPORTING
      no_dialog      = 'X'
    IMPORTING
      valid          = l_valid
      out_parameters = ls_params.


then i am passing job name in following: 

  CALL FUNCTION 'JOB_OPEN'
    EXPORTING
      jobname          = jobname
      jobclass         = jobclass
    IMPORTING
      jobcount         = jobcount
    EXCEPTIONS
      cant_create_job  = 1
      invalid_job_data = 2
      jobname_missing  = 3
      OTHERS           = 4.
  IF sy-subrc EQ 0.
*      SUBMIT zmb1a_massgif AND RETURN.
*    SUBMIT zmb1a_massgif  TO SAP-SPOOL WITHOUT SPOOL DYNPRO
*                 SPOOL PARAMETERS ls_params AND RETURN  VIA JOB jobname NUMBER jobcount.

then submitting my report by job_submit FM:

    CALL FUNCTION 'JOB_SUBMIT'
      EXPORTING
        jobname                 = jobname
        jobcount                = jobcount
        authcknam               = sy-uname
*        EXTPGM_STDOUT_IN_JOBLOG = 'X'
        report                  = 'ZMB1A_MASSGIF'
*        variant                 = 'TEST'
        priparams               = ls_params
      EXCEPTIONS
        bad_priparams           = 1
        bad_xpgflags            = 2
        invalid_jobdata         = 3
        jobname_missing         = 4
        job_notex               = 5
        job_submit_failed       = 6
        lock_failed             = 7
        program_missing         = 8
        prog_abap_and_extpg_set = 9
        OTHERS                  = 10.

    IF sy-subrc EQ 0.
      lv_date = sy-datum.
      lv_time = sy-uzeit + 10.
      CALL FUNCTION 'JOB_CLOSE'
       EXPORTING
         jobname              = jobname
         jobcount             = jobcount
         sdlstrtdt            = lv_date
         sdlstrttm            = lv_time
*         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.
      IF sy-subrc EQ 0.
        msg = jobname.
        CONCATENATE  msg ' - Job is Scheduled in Background' INTO msg.
        WRITE:/ msg.
      ENDIF.
    ENDIF.
  ENDIF.