Application Development and Automation 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: 
Read only

Problem in getting spool no. from database

Former Member
0 Likes
550

Hi,

I am trying to send a background job result to a mail.

But i am facing a problem in gettin the spool no. for job that i am scheduling.

If i go through debug mode. spool no. is obtained and mail has been sent.

But if i execute without debugging , spool no. is not obtained

Can any body give suggestions for this

below is the code:

if i put debug on statement:

  • Get job id

SELECT jobname

jobcount

SDLSTRTTM up to 1 rows

INTO (lv_jobname, lv_jobcount, l_SDLSTRTTM)

FROM tbtco

WHERE jobname = p_job

AND sdldate = sy-datum

AND sdluname = 'HS35413'

ORDER BY SDLSTRTTM descending.

endselect.

everything works fine

otherwise its not workin

Please give any soution to this

Thanks in Advance

Harkamal

&----


*& Report YHSENDMAILFROMSPOOL *

*& *

&----


*& *

*& *

&----


REPORT YHSENDMAILFROMSPOOL .

*variables for job scheduling

data: jobnumber like tbtcjob-jobcount,

job_started like btch0000-char1,

p_job like tbtco-jobname value 'P_ZSDRBD40'.

*data : p_spool LIKE tsp01-rqident.

DATA : gv_incomplete,

gv_jobhead LIKE tbtcjob.

DATA : BEGIN OF gv_spool OCCURS 0,

spool LIKE tsp01-rqident,

variant(30),

END OF gv_spool.

DATA : t_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE.

  • Database tables

TABLES: vbak, "Sales Document: Header Data

vbap. "Sales Document: Item Data

  • Selection screen

selection-screen:begin of block b1 with frame title text-001.

select-options: s_auart for vbak-auart OBLIGATORY.

selection-screen:skip.

select-options: s_VKBUR for vbak-VKBUR .

selection-screen:skip.

select-options: s_VKGRP for vbak-VKGRP.

selection-screen:skip.

select-options: s_erdat for vbak-erdat.

selection-screen:skip.

select-options: s_matnr for vbap-matnr.

selection-screen:skip.

parameters: p_s RADIOBUTTON GROUP radi default 'X',

p_m RADIOBUTTON GROUP radi.

selection-screen: end of block b1.

start-of-selection.

CALL FUNCTION 'JOB_OPEN'

EXPORTING

JOBNAME = p_job

IMPORTING

JOBCOUNT = jobnumber

EXCEPTIONS

CANT_CREATE_JOB = 1

INVALID_JOB_DATA = 2

JOBNAME_MISSING = 3

OTHERS = 4

.

IF SY-SUBRC <> 0.

  • write: / text-002, sy-uname.

*else.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

write: / sy-msgid, sy-msgty, sy-msgno,

sy-msgv1, sy-msgv2, sy-msgv3, sy-msgv4.

stop.

ENDIF.

submit ZSDRBD40

with s_auart in s_auart

with s_VKBUR in s_VKBUR

with s_VKGRP in s_VKGRP

with s_erdat in s_erdat

with s_matnr in s_matnr

with p_s = p_s

with p_m = p_m

via job p_job number jobnumber and return.

call function 'JOB_CLOSE'

EXPORTING

jobcount = jobnumber

jobname = p_job

strtimmed = 'X'

targetsystem = ' '

IMPORTING

job_was_released = job_started

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 <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

write: / sy-msgid, sy-msgty, sy-msgno,

sy-msgv1, sy-msgv2, sy-msgv3, sy-msgv4.

endif.

  • IF p_spool = space.

*

    • Get spool number

PERFORM get_spool_number.

*

  • ENDIF.

perform send_mail.

&----


*& Form get_spool_number

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_spool_number .

DATA: lv_jobname LIKE tbtco-jobname,

lv_jobcount LIKE tbtco-jobcount.

DATA: lt_steplist LIKE STANDARD TABLE OF tbtcstep ,

wa_steplist LIKE tbtcstep .

data l_SDLSTRTTM like tbtco-SDLSTRTTM .

*data: begin of itab occurs 0,

*lv_jobname like tbtco-jobname, lv_jobcount like tbtco-jobcount, l_SDLSTRTTM like tbtco-SDLSTRTTM ,

*end of itab.

  • Get job id

SELECT jobname

jobcount

SDLSTRTTM up to 1 rows

INTO (lv_jobname, lv_jobcount, l_SDLSTRTTM)

FROM tbtco

WHERE jobname = p_job

AND sdldate = sy-datum

AND sdluname = 'HS35413'

ORDER BY SDLSTRTTM descending.

endselect.

IF sy-subrc <> 0.

MESSAGE 'NO JOB found' type 'I'.

ENDIF.

  • data l_listident like tbtcp-listident.

*select single listident from TBTCP into l_listident where jobname = p_job and

*jobcount = lv_jobcount and stepcount = '1' and progname = 'ZSDRBD40'.

  • Get spool

CALL FUNCTION 'BP_JOB_READ'

EXPORTING

job_read_jobcount = lv_jobcount

job_read_jobname = lv_jobname

job_read_opcode = '20'

  • JOB_STEP_NUMBER =

IMPORTING

job_read_jobhead = gv_jobhead

TABLES

job_read_steplist = lt_steplist

EXCEPTIONS

invalid_opcode = 1

job_doesnt_exist = 2

job_doesnt_have_steps = 3

OTHERS = 4.

IF sy-subrc <> 0.

MESSAGE 'Error in BP_JOB_READ' type 'I'..

ENDIF.

*

LOOP AT lt_steplist INTO wa_steplist.

MOVE wa_steplist-listident TO gv_spool-spool.

MOVE wa_steplist-parameter TO gv_spool-variant.

*gv_spool-spool = l_listident .

APPEND gv_spool.

CLEAR gv_spool.

ENDLOOP.

IF sy-subrc <> 0.

MESSAGE 'Error in LT_steplist' type 'I'..

ENDIF.

ENDFORM. " get_spool_number

&----


*& Form send_mail

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM send_mail .

&----


*& Form send_mail

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


DATA: lt_ali LIKE soli OCCURS 0 WITH HEADER LINE,

l_docdata LIKE sodocchgi1,

l_objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,

l_objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,

l_objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,

l_objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,

l_objhex LIKE solix OCCURS 10 WITH HEADER LINE,

tab_lines TYPE i,

doc_size TYPE i,

lv_spool(10).

  • IF gv_spool[] IS INITIAL.

  • CLEAR gv_spool.

  • gv_spool-spool = p_spool.

  • APPEND gv_spool.

  • ENDIF.

LOOP AT gv_spool.

CHECK gv_spool-spool <> space.

CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'

EXPORTING

rqident = gv_spool-spool

TABLES

buffer = lt_ali

  • BUFFER_PDF =

EXCEPTIONS

no_such_job = 1

job_contains_no_data = 2

selection_empty = 3

no_permission = 4

can_not_access = 5

read_error = 6

type_no_match = 7

OTHERS = 8.

IF sy-subrc <> 0.

MESSAGE 'Error in SPO_RETURN_SPOOLJOB' type 'I'.

ENDIF.

  • Message header/content

  • IF p_spool = space.

CONCATENATE text-h01 p_job

INTO l_docdata-obj_descr SEPARATED BY space.

l_docdata-obj_name = l_docdata-obj_descr.

CONCATENATE text-b01 p_job

INTO l_objtxt SEPARATED BY space.

APPEND l_objtxt.

CLEAR l_objtxt.

CONCATENATE text-b02 gv_spool-variant

INTO l_objtxt SEPARATED BY space.

APPEND l_objtxt.

CLEAR l_objtxt.

MOVE gv_spool-spool TO lv_spool.

CONCATENATE text-b05 lv_spool

INTO l_objtxt SEPARATED BY space.

APPEND l_objtxt.

  • ELSE.

MOVE gv_spool-spool TO lv_spool.

CONCATENATE text-h02 lv_spool

INTO l_docdata-obj_descr SEPARATED BY space.

l_docdata-obj_name = l_docdata-obj_descr.

CLEAR l_objtxt.

MOVE gv_spool-spool TO lv_spool.

CONCATENATE text-b04 lv_spool

INTO l_objtxt SEPARATED BY space.

APPEND l_objtxt.

  • ENDIF.

  • Packing list

DESCRIBE TABLE l_objtxt LINES tab_lines.

READ TABLE l_objtxt INDEX tab_lines.

l_docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( l_objtxt ).

CLEAR l_objpack-transf_bin.

l_objpack-head_start = 1.

l_objpack-head_num = 0.

l_objpack-body_start = 1.

l_objpack-body_num = tab_lines.

l_objpack-doc_type = 'RAW'.

APPEND l_objpack.

  • Message attachment

l_objbin[] = lt_ali[].

DESCRIBE TABLE l_objbin LINES tab_lines.

READ TABLE l_objbin INDEX tab_lines.

l_objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( l_objbin ).

l_objpack-transf_bin = 'X'.

l_objpack-head_start = 1.

l_objpack-head_num = 0.

l_objpack-body_start = 1.

l_objpack-body_num = tab_lines.

l_objpack-doc_type = 'ALI'.

l_objpack-obj_name = 'Spool output'.

l_objpack-obj_descr = 'Spool output'.

APPEND l_objpack.

  • IF NOT p_objnam IS INITIAL.

t_reclist-receiver = 'HS35413'.

t_reclist-rec_type = 'B'.

APPEND t_reclist.

  • ENDIF.

  • Send message

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = l_docdata

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = l_objpack

object_header = l_objhead

contents_bin = l_objbin

contents_txt = l_objtxt

contents_hex = l_objhex

receivers = t_reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

IF sy-subrc <> 0.

MESSAGE 'Unable to send Email' type 'I'.

ELSE.

MESSAGE ' send Email' type 'I'.

ENDIF.

commit work.

ENDLOOP.

ENDFORM. " send_mail

3 REPLIES 3
Read only

Former Member
0 Likes
509

Hi

I believe the problem is the job parameters aren't stored in database yet: perhaps the report is running when you read the tbtco table or the commit isn't called by the system.

Max

Read only

Former Member
0 Likes
509

Hi Harkamlpreet,

In Debugiing the system does an explicit commit for you.

Thats the reason you are getting the spool id from the table.

So, put an explicit commit statement in your code and see if it works.

Regards,

Ravi

Read only

Former Member
0 Likes
509

I am also facing the same problem. Even though I am giving explicit commit, its not updating tbtcp-listident.