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: 

Sending mail in PDF format in background

Former Member
0 Kudos

Hi,

I am running a program in backgorund.

After the completion, I am convertin gthe spool into PDF format and sending it to mail.

In SAP 4.6 B it was working.

But now in SAP 4.7 the mail is not working.

Regular mails are going from SAP.

What could be the reason?.

Regards

Elini.P

4 REPLIES 4

Former Member
0 Kudos

HEY ELINI.

THIS IS CHANDRA FROM JP(SRM-KODAMBAKKAM)

just check ur FM for sending mail is valid for Enterprise or not..

chandra...??

Former Member
0 Kudos

Hi,

can you tell me how to

convert a file in the spool to PDF-format ?

Paul Frei

Germany

0 Kudos

Dear Paul,

Here is the code for sending mail through ABAP converting Spool in PDF in background.

if sy-batch eq 'X'.

perform get_job_details.

perform obtain_spool_id.

perform convert_spool_to_pdf.

perform process_email.

if p_delspl eq 'X'.

perform delete_spool.

endif.

if sy-sysid = c_dev.

wait up to 5 seconds.

submit rsconn01 with mode = 'INT'

with output = 'X'

and return.

endif.

else.

skip.

write:/ 'Program must be executed in background in-order for spool',

'request to be created.'.

endif.

&----


*& Form GET_JOB_DETAILS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form get_job_details.

  • Get current job details

call function 'GET_JOB_RUNTIME_INFO'

importing

eventid = gd_eventid

eventparm = gd_eventparm

external_program_active = gd_external_program_active

jobcount = gd_jobcount

jobname = gd_jobname

stepcount = gd_stepcount

exceptions

no_runtime_info = 1

others = 2.

endform. " GET_JOB_DETAILS

&----


*& Form OBTAIN_SPOOL_ID

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form obtain_spool_id.

check not ( gd_jobname is initial ).

check not ( gd_jobcount is initial ).

select * from tbtcp into table it_tbtcp

where jobname = gd_jobname

and jobcount = gd_jobcount

and stepcount = gd_stepcount

and listident <> '0000000000'

order by jobname

jobcount

stepcount.

read table it_tbtcp into wa_tbtcp index 1.

if sy-subrc = 0.

message s004(zdd) with gd_spool_nr.

gd_spool_nr = wa_tbtcp-listident.

message s004(zdd) with gd_spool_nr.

else.

message s005(zdd).

endif.

endform. " OBTAIN_SPOOL_ID

&----


*& Form CONVERT_SPOOL_TO_PDF

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form convert_spool_to_pdf.

call function 'CONVERT_ABAPSPOOLJOB_2_PDF'

exporting

src_spoolid = gd_spool_nr

no_dialog = c_no

dst_device = c_device

importing

pdf_bytecount = gd_bytecount

tables

pdf = it_pdf_output

exceptions

err_no_abap_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_destdevice = 5

user_cancelled = 6

err_spoolerror = 7

err_temseerror = 8

err_btcjob_open_failed = 9

err_btcjob_submit_failed = 10

err_btcjob_close_failed = 11

others = 12.

check sy-subrc = 0.

  • Transfer the 132-long strings to 255-long strings

loop at it_pdf_output.

translate it_pdf_output using ' ~'.

concatenate gd_buffer it_pdf_output into gd_buffer.

endloop.

translate gd_buffer using '~ '.

do.

it_mess_att = gd_buffer.

append it_mess_att.

shift gd_buffer left by 255 places.

if gd_buffer is initial.

exit.

endif.

enddo.

endform. " CONVERT_SPOOL_TO_PDF

&----


*& Form PROCESS_EMAIL

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form process_email.

describe table it_mess_att lines gd_recsize.

check gd_recsize > 0.

perform send_email using p_email1.

endform. " PROCESS_EMAIL

&----


*& Form SEND_EMAIL

&----


  • text

----


  • -->P_P_EMAIL1 text

----


form send_email using p_email.

check not ( p_email is initial ).

refresh it_mess_bod.

  • Default subject matter

gd_subject = 'Subject'.

gd_attachment_desc = 'Attachname'.

  • CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.

it_mess_bod = 'SCGL - Purchase Order in 050'.

append it_mess_bod.

it_mess_bod = 'Success or Error messages'.

append it_mess_bod.

  • If no sender specified - default blank

if p_sender eq space.

gd_sender_type = space.

else.

gd_sender_type = 'INT'.

endif.

  • Add the recipients email address

open dataset file for input in text mode.

if sy-subrc = 0.

do.

read dataset file into itab_receivers.

if sy-subrc = 0.

append itab_receivers.

else.

exit.

endif.

enddo.

endif.

close dataset file.

loop at itab_receivers.

clear: p_email.

p_email = itab_receivers-receiver.

    • Send file by email as .xls speadsheet

perform send_file_as_email_attachment

tables it_mess_bod

it_mess_att

using p_email

'SCGL Purchase Order IN 050'

'PDF'

gd_attachment_name

gd_attachment_desc

p_sender

gd_sender_type

changing gd_error

gd_reciever.

endloop.

endform. " SEND_EMAIL

&----


*& Form SEND_FILE_AS_EMAIL_ATTACHMENT

&----


  • text

----


  • -->P_IT_MESS_BOD text

  • -->P_IT_MESS_ATT text

  • -->P_P_EMAIL text

  • -->P_1572 text

  • -->P_1573 text

  • -->P_GD_ATTACHMENT_NAME text

  • -->P_GD_ATTACHMENT_DESC text

  • -->P_P_SENDER text

  • -->P_GD_SENDER_TYPE text

  • <--P_GD_ERROR text

  • <--P_GD_RECIEVER text

----


form send_file_as_email_attachment tables it_message

it_attach

using p_email

p_mtitle

p_format

p_filename

p_attdescription

p_sender_address

p_sender_addres_type

changing p_error

p_reciever.

ld_email = p_email.

ld_mtitle = p_mtitle.

ld_format = p_format.

ld_attdescription = p_attdescription.

ld_attfilename = p_filename.

ld_sender_address = p_sender_address.

ld_sender_address_type = p_sender_addres_type.

  • Fill the document data.

w_doc_data-doc_size = 1.

  • Populate the subject/generic message attributes

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ld_mtitle .

w_doc_data-sensitivty = 'F'.

  • Fill the document data and get size of attachment

clear w_doc_data.

read table it_attach index w_cnt.

w_doc_data-doc_size =

( w_cnt - 1 ) * 255 + strlen( it_attach ).

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ld_mtitle.

w_doc_data-sensitivty = 'F'.

clear t_attachment.

refresh t_attachment.

t_attachment[] = it_attach[].

  • Describe the body of the message

clear t_packing_list.

refresh t_packing_list.

t_packing_list-transf_bin = space.

t_packing_list-head_start = 1.

t_packing_list-head_num = 0.

t_packing_list-body_start = 1.

describe table it_message lines t_packing_list-body_num.

t_packing_list-doc_type = 'RAW'.

append t_packing_list.

  • Create attachment notification

t_packing_list-transf_bin = 'X'.

t_packing_list-head_start = 1.

t_packing_list-head_num = 1.

t_packing_list-body_start = 1.

describe table t_attachment lines t_packing_list-body_num.

t_packing_list-doc_type = ld_format.

t_packing_list-obj_descr = ld_attdescription.

t_packing_list-obj_name = ld_attfilename.

t_packing_list-doc_size = t_packing_list-body_num * 255.

append t_packing_list.

  • Add the recipients email address

clear t_receivers.

refresh t_receivers.

t_receivers-receiver = ld_email.

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-notif_del = 'X'.

t_receivers-notif_ndel = 'X'.

append t_receivers.

call function 'SO_DOCUMENT_SEND_API1'

exporting

document_data = w_doc_data

put_in_outbox = 'X'

sender_address = ld_sender_address

sender_address_type = ld_sender_address_type

commit_work = 'X'

importing

sent_to_all = w_sent_all

tables

packing_list = t_packing_list

contents_bin = t_attachment

contents_txt = it_message

receivers = t_receivers

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.

  • Populate zerror return code

ld_error = sy-subrc.

  • Populate zreceiver return code

loop at t_receivers.

ld_receiver = t_receivers-retrn_code.

endloop.

endform. " SEND_FILE_AS_EMAIL_ATTACHMENT

&----


*& Form DELETE_SPOOL

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form delete_spool.

data: ld_spool_nr type tsp01_sp0r-rqid_char.

ld_spool_nr = gd_spool_nr.

check p_delspl <> c_no.

call function 'RSPO_R_RDELETE_SPOOLREQ'

exporting

spoolid = ld_spool_nr.

endform. " DELETE_SPOOL

0 Kudos

Dear all..

Do you managed to open the attachment? I facing some difficulties when trying to open the document.

The message that i've got is 'there was an error opening this document.The file is damaged and could not repair'.

can anybody help me????

regards..

Siti Noor

Message was edited by: Siti Noor Zahabiah Ishak