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: 

Create job via program with spool list recipient

nol_vanlaere2
Discoverer
0 Kudos
1,409

It is quite easy to create a job via SM36 and specify a "spool list recipient" to send the resulting spool in attachment to a distribution list.

I haven't find the way to have this 'spool list recipient' when I create the job via program (JOB_OPEN or BP_JOB_CREATE ...)

May be a smart abapper could help me ...

1 ACCEPTED SOLUTION

Former Member
0 Kudos
311

See the following ex code.

REPORT ZSDQ_BCK1 .

data: jobname like tbtcjob-jobname value

' SDQTEST'.

data: jobcount like tbtcjob-jobcount,

host like msxxlist-host.

data: begin of starttime.

include structure tbtcstrt.

data: end of starttime.

data: starttimeimmediate like btch0000-char1.

data: wa_jobhead like tbtcjob,

i_jobsteplist like TBTCSTEP occurs 0 with header line,

wa_jobsteplist like TBTCSTEP,

w_spool_number like TSP01-RQIDENT.

data: sdate type sy-datum,

stime type sy-uzeit,

l_valid,

ls_params like pri_params.

data: sdlstrtdt like starttime-sdlstrtdt,

sdlstrttm like starttime-sdlstrttm.

INCLUDE <CNTN01>.

DATA BEGIN OF LOCAL_JOB.

INCLUDE STRUCTURE TBTCJOB.

DATA END OF LOCAL_JOB.

DATA BEGIN OF LOCAL_STEP_TBL OCCURS 10.

INCLUDE STRUCTURE TBTCSTEP.

DATA END OF LOCAL_STEP_TBL.

*

  • Data declarations for the mail recipient

DATA RECIPIENT TYPE SWC_OBJECT.

DATA RECIPIENT_OBJ LIKE SWOTOBJID.

SWC_CONTAINER CONTAINER.

  • Data declarations for the background job

*EXECHOST LIKE SY-HOST DEFAULT 'host1',

*EXESERVR LIKE BTCTGTSRVR-SRVNAME DEFAULT 'host1_SID_00',

*ABAPNAME LIKE SY-REPID DEFAULT 'Program2run',

*EMPFNAME LIKE SY-UNAME DEFAULT 'JSmith'.

  • Generate recipient object (see report RSSOKIF1 for an example)

      • 1. Create the recipient:

*IF EMPFNAME <> SPACE.

"** 1.1 Generate an object reference to a recipient object

SWC_CREATE_OBJECT RECIPIENT 'RECIPIENT' SPACE.

"* 1.2 Write the import parameters for method

"* recipient.createaddress into the container

"* and empty the container

SWC_CLEAR_CONTAINER CONTAINER.

"* Set address element (internal user 'JSMITH')

SWC_SET_ELEMENT CONTAINER 'AddressString' SY-UNAME.

"* Set address type (internal user)

SWC_SET_ELEMENT CONTAINER 'TypeId' 'B'.

"* 1.3 Call the method recipient.createaddress

SWC_CALL_METHOD RECIPIENT 'CreateAddress' CONTAINER.

"* Issue any error message generated by a method exception

IF SY-SUBRC NE 0.

MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO.

ENDIF.

SWC_CALL_METHOD RECIPIENT 'Save' CONTAINER.

SWC_OBJECT_TO_PERSISTENT RECIPIENT RECIPIENT_OBJ.

*ENDIF.

      • Recipient has been generated and is ready for use in a

      • background job

sdlstrtdt = sy-datum.

sdlstrttm = sy-uzeit + 60.

call function 'GET_PRINT_PARAMETERS'

exporting

no_dialog = 'X'

importing

valid = l_valid

out_parameters = ls_params.

  • Job open

call function 'JOB_OPEN'

exporting

delanfrep = ' '

jobgroup = ' '

jobname = jobname

*sdlstrtdt = sy-datum

*sdlstrttm = sy-uzeit

importing

jobcount = jobcount

exceptions

cant_create_job = 01

invalid_job_data = 02

jobname_missing = 03.

if sy-subrc ne 0.

write:/ 'error in opening a job'.

endif.

  • Insert process into job

submit ZSDQ_BCK_TEST

with p_type = 'F'

via job jobname

number jobcount

to sap-spool without spool dynpro

spool parameters ls_params

and return.

if sy-subrc > 0.

WRITE:/ 'ERROR PROCESSING JOB'.

endif.

  • Close job

call function 'JOB_CLOSE'

exporting

*event_id = starttime-eventid

*event_param = starttime-eventparm

*event_periodic = starttime-periodic

jobcount = jobcount

jobname = jobname

*laststrtdt = starttime-laststrtdt

*laststrttm = starttime-laststrttm

*prddays = 1

*prdhours = 0

*prdmins = 0

*prdmonths = 0

*prdweeks = 0

*sdlstrtdt = sdlstrtdt

*sdlstrttm = sdlstrttm

strtimmed = 'X'

*targetsystem = host

RECIPIENT_OBJ = RECIPIENT_OBJ

exceptions

cant_start_immediate = 01

invalid_startdate = 02

jobname_missing = 03

job_close_failed = 04

job_nosteps = 05

job_notex = 06

lock_failed = 07

others = 99.

3 REPLIES 3

GauthamV
Active Contributor
0 Kudos
311

hi,

check this sample program which will help u.

&----


*& Report ZRC_JOB_TEST *& *

&----


*& *

*& *

&----


REPORT ZRC_JOB_TEST .

data : jobcount like TBTCJOB-JOBCOUNT ,

JOB_WAS_RELEASED like BTCH0000-CHAR1 ,

SDLSTRTDT like TBTCJOB-SDLSTRTDT ,

SDLSTRTTM like TBTCJOB-SDLSTRTTM .

data : l_ebeln like ekko-ebeln ,

l_ebelp like ekpo-ebelp .

l_ebeln = '0071005915' .

l_ebelp = '00010' .

CALL FUNCTION 'JOB_OPEN'

EXPORTING

  • DELANFREP = ' '

  • JOBGROUP = ' '

JOBNAME = 'job1'

  • SDLSTRTDT = NO_DATE

  • SDLSTRTTM = NO_TIME

  • JOBCLASS =

IMPORTING

JOBCOUNT = JOBCOUNT

  • CHANGING

  • RET =

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 ZFI_UPD_PO_DELIV_COMP_BDC

with ebeln = l_ebeln

with ebelp = l_ebelp

via job 'job1' number jobcount

and return .

if sy-subrc = 0 .

SDLSTRTDT = sy-datum .

SDLSTRTTM = sy-uzeit + 600 .

CALL FUNCTION 'JOB_CLOSE'

EXPORTING

  • AT_OPMODE = ' '

  • AT_OPMODE_PERIODIC = ' '

  • CALENDAR_ID = ' '

  • EVENT_ID = ' '

  • EVENT_PARAM = ' '

  • EVENT_PERIODIC = ' '

JOBCOUNT = JOBCOUNT

JOBNAME = 'job1'

  • LASTSTRTDT = NO_DATE

  • LASTSTRTTM = NO_TIME

  • PRDDAYS = 0

  • PRDHOURS = 0

  • PRDMINS = 0

  • PRDMONTHS = 0

  • PRDWEEKS = 0

  • PREDJOB_CHECKSTAT = ' '

  • PRED_JOBCOUNT = ' '

  • PRED_JOBNAME = ' '

SDLSTRTDT = SDLSTRTDT

SDLSTRTTM = SDLSTRTTM

  • STARTDATE_RESTRICTION = BTC_PROCESS_ALWAYS

  • STRTIMMED = 'X'

  • TARGETSYSTEM = ' '

  • START_ON_WORKDAY_NOT_BEFORE = SY-DATUM

  • START_ON_WORKDAY_NR = 0

  • WORKDAY_COUNT_DIRECTION = 0

  • RECIPIENT_OBJ =

  • TARGETSERVER = ' '

  • DONT_RELEASE = ' '

  • TARGETGROUP = ' '

  • DIRECT_START =

IMPORTING

JOB_WAS_RELEASED = JOB_WAS_RELEASED

  • CHANGING

  • RET =

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.

Former Member
0 Kudos
312

See the following ex code.

REPORT ZSDQ_BCK1 .

data: jobname like tbtcjob-jobname value

' SDQTEST'.

data: jobcount like tbtcjob-jobcount,

host like msxxlist-host.

data: begin of starttime.

include structure tbtcstrt.

data: end of starttime.

data: starttimeimmediate like btch0000-char1.

data: wa_jobhead like tbtcjob,

i_jobsteplist like TBTCSTEP occurs 0 with header line,

wa_jobsteplist like TBTCSTEP,

w_spool_number like TSP01-RQIDENT.

data: sdate type sy-datum,

stime type sy-uzeit,

l_valid,

ls_params like pri_params.

data: sdlstrtdt like starttime-sdlstrtdt,

sdlstrttm like starttime-sdlstrttm.

INCLUDE <CNTN01>.

DATA BEGIN OF LOCAL_JOB.

INCLUDE STRUCTURE TBTCJOB.

DATA END OF LOCAL_JOB.

DATA BEGIN OF LOCAL_STEP_TBL OCCURS 10.

INCLUDE STRUCTURE TBTCSTEP.

DATA END OF LOCAL_STEP_TBL.

*

  • Data declarations for the mail recipient

DATA RECIPIENT TYPE SWC_OBJECT.

DATA RECIPIENT_OBJ LIKE SWOTOBJID.

SWC_CONTAINER CONTAINER.

  • Data declarations for the background job

*EXECHOST LIKE SY-HOST DEFAULT 'host1',

*EXESERVR LIKE BTCTGTSRVR-SRVNAME DEFAULT 'host1_SID_00',

*ABAPNAME LIKE SY-REPID DEFAULT 'Program2run',

*EMPFNAME LIKE SY-UNAME DEFAULT 'JSmith'.

  • Generate recipient object (see report RSSOKIF1 for an example)

      • 1. Create the recipient:

*IF EMPFNAME <> SPACE.

"** 1.1 Generate an object reference to a recipient object

SWC_CREATE_OBJECT RECIPIENT 'RECIPIENT' SPACE.

"* 1.2 Write the import parameters for method

"* recipient.createaddress into the container

"* and empty the container

SWC_CLEAR_CONTAINER CONTAINER.

"* Set address element (internal user 'JSMITH')

SWC_SET_ELEMENT CONTAINER 'AddressString' SY-UNAME.

"* Set address type (internal user)

SWC_SET_ELEMENT CONTAINER 'TypeId' 'B'.

"* 1.3 Call the method recipient.createaddress

SWC_CALL_METHOD RECIPIENT 'CreateAddress' CONTAINER.

"* Issue any error message generated by a method exception

IF SY-SUBRC NE 0.

MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO.

ENDIF.

SWC_CALL_METHOD RECIPIENT 'Save' CONTAINER.

SWC_OBJECT_TO_PERSISTENT RECIPIENT RECIPIENT_OBJ.

*ENDIF.

      • Recipient has been generated and is ready for use in a

      • background job

sdlstrtdt = sy-datum.

sdlstrttm = sy-uzeit + 60.

call function 'GET_PRINT_PARAMETERS'

exporting

no_dialog = 'X'

importing

valid = l_valid

out_parameters = ls_params.

  • Job open

call function 'JOB_OPEN'

exporting

delanfrep = ' '

jobgroup = ' '

jobname = jobname

*sdlstrtdt = sy-datum

*sdlstrttm = sy-uzeit

importing

jobcount = jobcount

exceptions

cant_create_job = 01

invalid_job_data = 02

jobname_missing = 03.

if sy-subrc ne 0.

write:/ 'error in opening a job'.

endif.

  • Insert process into job

submit ZSDQ_BCK_TEST

with p_type = 'F'

via job jobname

number jobcount

to sap-spool without spool dynpro

spool parameters ls_params

and return.

if sy-subrc > 0.

WRITE:/ 'ERROR PROCESSING JOB'.

endif.

  • Close job

call function 'JOB_CLOSE'

exporting

*event_id = starttime-eventid

*event_param = starttime-eventparm

*event_periodic = starttime-periodic

jobcount = jobcount

jobname = jobname

*laststrtdt = starttime-laststrtdt

*laststrttm = starttime-laststrttm

*prddays = 1

*prdhours = 0

*prdmins = 0

*prdmonths = 0

*prdweeks = 0

*sdlstrtdt = sdlstrtdt

*sdlstrttm = sdlstrttm

strtimmed = 'X'

*targetsystem = host

RECIPIENT_OBJ = RECIPIENT_OBJ

exceptions

cant_start_immediate = 01

invalid_startdate = 02

jobname_missing = 03

job_close_failed = 04

job_nosteps = 05

job_notex = 06

lock_failed = 07

others = 99.

Former Member
0 Kudos
311

Hi eric dupuris,

welcome to sdn.

Sample Program: Creating a Job with JOB_OPEN

  • Create your job with JOB_OPEN. The module returns a unique job

  • number. Together with the jobname, this number identifies the

  • job. Other parameters are available, but are not required.

JOBNAME = 'Freely selectable name for the job(s) you create'.

CALL FUNCTION 'JOB_OPEN'

EXPORTING

JOBNAME = JOBNAME

IMPORTING

JOBCOUNT = JOBNUMBER

.

EXCEPTIONS

CANT_CREATE_JOB = 01

INVALID_JOB_DATA = 02

JOBNAME_MISSING = 03

OTHERS = 99.

IF SY-SUBRC > 0.

<Error processing>

ENDIF.

Sample Program: Adding an ABAP Job Step

  • Add a job step: ABAP program

CALL FUNCTION 'JOB_SUBMIT'

EXPORTING

AUTHCKNAM = SY-UNAME " Runtime authorizations

" user

JOBCOUNT = JOBNUMBER " Value from JOB_OPEN

JOBNAME = JOBNAME " Value from JOB_OPEN

REPORT = 'REPORT' " Report to be run

VARIANT = 'VARIANT' " Variant to use with

" report

PRIPARAMS = USER_PRINT_PARAMS " User printing options

ARCPARAMS = USER_ARC_PARAMS " User archiving options

" Both sets of options

" come from

" GET_PRINT_PARAMETERS

EXCEPTIONS

BAD_PRIPARAMS = 01

INVALID_JOBDATA = 02

JOBNAME_MISSING = 03

JOB_NOTEX = 04

JOB_SUBMIT_FAILED = 05

LOCK_FAILED = 06

PROGRAM_MISSING = 07

PROG_ABAP_AND_EXTPG_SET = 08

OTHERS = 99.

IF SY-SUBRC > 0.

<Error processing>

ENDIF.

  • Error processing in the event of a non-recoverable error should

  • include a call to BP_JOB_DELETE with FORCEDMODE = 'X' to remove

  • the job from the database. This is required for error

  • processing in all calls after JOB_OPEN. (The background system

  • cleans up automatically in the event of a problem in JOB_OPEN).

dont mind if job_open doesnt works bcoz,JOB_OPEN, SUBMIT,

JOB_CLOSE in older versions of R/3 some times they wont work

So If you cannot get this to work, try BP_JOB_CREATE

Try this

We can do that via SUBMIT statement:

Go through the documentation os SUBMIT statement with addition:

... USER user VIA JOB job NUMBER n

Schedules the specified report in the job specified by the job name job and the job number n. The job runs under the user name user and you can omit the addition USER user. The assignment of the job number occurs via the function module JOB_OPEN (see also the documentation for the function modules JOB_CLOSE and JOB_SUBMIT). This addition can only be used with the addition ...AND RETURN.

OR

go through this link , i hope this ll help you to solve your problem

http://help.sap.com/saphelp_nw2004s/helpdata/en/5f/ff2138faeb3807e10000009b38f889/content.htm

thanks

shankar,,,,

reward me if usefull