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: 

Need to Generate PDF file and send it to customer through email-ALV report

former_member209914
Participant
0 Kudos

HI All,

I am having data in Internal table.

can we create PDF file with out having spool-request number.

My requirement is whenever user clicks on execute button the output is generated in PDF format automatically and then send it to customer through email.

I found few programs in SDN for generation PDF. But problem is everyone passing the spool request to the function module.

spool request will be generated whenever we click on print button.

Am I correct?.

Is there any other way to create spool request automatically. If so we can pass the this spool number to the function module.

Regards,

vinod.

6 REPLIES 6

Former Member
0 Kudos

hi

For sending a mail, this code will help you.

Pls reward if help.

FORM send_mail_2 USING msgid msgno msgv1.

  • mailuser oder Gruppe like sy-uname default 'Ruckerk'.

DATA: express_hold_time LIKE sovaltime.

DATA: text LIKE sotxtinfo.

DATA: receiver LIKE somlreci1 OCCURS 0 WITH HEADER LINE.

  • MESSAGE ZF100 (FTP an UDB fehlgeschlagen)

text-msgid = msgid.

text-msgno = msgno.

text-msgv1 = msgv1.

text-msgv2 = ' '.

text-msgv3 = ' '.

text-msgv4 = ' '.

  • express_hold_time

express_hold_time-days = 01.

express_hold_time-h_min_sec = 240000.

  • receiver

receiver-receiver = mreceivr.

  • Gruppe von Empfängern

receiver-rec_type = 'C'.

  • und Expressmeldung ausgeben

receiver-express = 'X'.

APPEND receiver.

CALL FUNCTION 'MESSAGE_SEND_AS_MAIL'

EXPORTING

msgid = text-msgid

msgno = text-msgno

msgv1 = text-msgv1

msgv2 = text-msgv2

msgv3 = text-msgv3

TABLES

receivers = receiver.

IF sy-subrc <> 0.

WRITE:/ 'hat nicht geklappt', 'SY-SUBRC =', sy-subrc.

ENDIF.

PERFORM print_error_report.

  • Fehlermeldung zum Abbrechen des Report's ausgeben.

MESSAGE e398 WITH 'Jobabbruch' msgv1.

ENDFORM. " SEND_MAIL_2

Another Program:

*& Report ZSENDEMAIL *

*& *

*&----


*

*& Example of sending external email via SAPCONNECT *

*& *

*&----


*

REPORT zsendemail .

PARAMETERS: psubject(40) type c default 'Hello',

p_email(40) type c default 'test@sapdev.co.uk' .

data: it_packing_list like sopcklsti1 occurs 0 with header line,

it_contents like solisti1 occurs 0 with header line,

it_receivers like somlreci1 occurs 0 with header line,

it_attachment like solisti1 occurs 0 with header line,

gd_cnt type i,

gd_sent_all(1) type c,

gd_doc_data like sodocchgi1,

gd_error type sy-subrc.

data: it_message type standard table of SOLISTI1 initial size 0

with header line.

***********************************************************************

*START-OF-SELECTION.

START-OF-SELECTION.

Perform populate_message_table.

*Send email message, although is not sent from SAP until mail send

*program has been executed(rsconn01)

PERFORM send_email_message.

*Instructs mail send program for SAPCONNECT to send email(rsconn01)

perform initiate_mail_execute_program.

*&----


*

*& Form POPULATE_MESSAGE_TABLE

*&----


*

  • Adds text to email text table

*----


*

form populate_message_table.

Append 'Email line 1' to it_message.

Append 'Email line 2' to it_message.

Append 'Email line 3' to it_message.

Append 'Email line 4' to it_message.

endform. " POPULATE_MESSAGE_TABLE

*&----


*

*& Form SEND_EMAIL_MESSAGE

*&----


*

  • Send email message

*----


*

form send_email_message.

  • Fill the document data.

gd_doc_data-doc_size = 1.

  • Populate the subject/generic message attributes

gd_doc_data-obj_langu = sy-langu.

gd_doc_data-obj_name = 'SAPRPT'.

gd_doc_data-obj_descr = psubject.

gd_doc_data-sensitivty = 'F'.

  • Describe the body of the message

clear it_packing_list.

refresh it_packing_list.

it_packing_list-transf_bin = space.

it_packing_list-head_start = 1.

it_packing_list-head_num = 0.

it_packing_list-body_start = 1.

describe table it_message lines it_packing_list-body_num.

it_packing_list-doc_type = 'RAW'.

append it_packing_list.

  • Add the recipients email address

clear it_receivers.

refresh it_receivers.

it_receivers-receiver = p_email.

it_receivers-rec_type = 'U'.

it_receivers-com_type = 'INT'.

it_receivers-notif_del = 'X'.

it_receivers-notif_ndel = 'X'.

append it_receivers.

  • Call the FM to post the message to SAPMAIL

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = gd_doc_data

put_in_outbox = 'X'

importing

sent_to_all = gd_sent_all

tables

packing_list = it_packing_list

contents_txt = it_message

receivers = it_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.

  • Store function module return code

gd_error = sy-subrc.

  • Get it_receivers return code

loop at it_receivers.

endloop.

endform. " SEND_EMAIL_MESSAGE

*&----


*

*& Form INITIATE_MAIL_EXECUTE_PROGRAM

*&----


*

  • Instructs mail send program for SAPCONNECT to send email.

*----


*

form initiate_mail_execute_program.

wait up to 2 seconds.

if gd_error eq 0.

submit rsconn01 with mode = 'INT'

with output = 'X'

and return.

endif.

endform. " INITIATE_MAIL_EXECUTE_PROGRAM

Former Member
0 Kudos

Hi,

u can use this.....

submit <report name> to sap-spool.

check its syntax (F1 hlp) for options available...

Cheers,

Will.

Former Member
0 Kudos

Hi,

u can use these FM to convert into PDF

For a report in foreground.

CONVERT_ABAPSPOOLJOB_2_PDF

For background

CONVERT_ABAPSPOOLJOB_2_PDF

And finally use this FM to send as a mail

RS_SEND_MAIL_FOR_SPOOLLIST

thanx.......

sunil

Former Member
0 Kudos

Hi Vinod,

Yeah , you can do like below

get the print parameters.

DATA : l_arcpar LIKE arc_params, " Archive parameter

l_pripar LIKE pri_params, " Paramenter

l_lay TYPE char16 , " Layout

l_lines TYPE i , "#EC NEEDED " Lines

l_rows TYPE i , " Rows

l_val TYPE c . "#EC NEEDED " Valid

CLEAR: l_lay ,

l_lines,

l_rows.

*Set to default values.

l_lay = c_x_65_255.

l_lines = 65.

l_rows = 255.

CALL FUNCTION 'GET_PRINT_PARAMETERS'

EXPORTING

in_archive_parameters = l_arcpar

in_parameters = l_pripar

layout = l_lay

line_count = l_lines

line_size = l_rows

no_dialog = c_x

IMPORTING

out_archive_parameters = l_arcpar

out_parameters = l_pripar

valid = l_val

EXCEPTIONS

archive_info_not_found = 1.

IF sy-subrc <> 0.

MESSAGE e014(/ds1/a) WITH text-032.

ENDIF.

IF l_pripar-pdest IS INITIAL.

MESSAGE e014(/ds1/a) WITH text-033.

ENDIF.

CALL FUNCTION 'SET_PRINT_PARAMETERS'

EXPORTING

layout = l_lay

line_count = l_lines

line_size = l_rows.

and then call the alv list display....

w_slis_print_alv-print = c_x.

w_slis_print_alv-no_print_listinfos = c_x.

w_slis_print_alv-prnt_title = c_x.

  • A Popup is Displayed during the Process

  • to avoid this make the SY-BATCH as 'X'

  • like executing the Process in Background.

sy-batch = c_x.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = sy-repid

i_callback_pf_status_set = space

is_layout = w_layout

it_fieldcat = i_fieldcat[]

it_sort = i_sort[]

is_print = w_slis_print_alv

TABLES

t_outtab = p_outtab

EXCEPTIONS

program_error = 1.

IF sy-subrc <> 0.

MESSAGE e014(/ds1/a) WITH text-020.

ENDIF.

the above one automaticaly create the spool. then use the FM to convert spool to PDF and send an email as PDF attachment.

*Move the spool number to a variable

l_spono = sy-spono.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = l_spono

IMPORTING

pdf_bytecount = l_byte_count

TABLES

pdf = i_pdf

EXCEPTIONS

err_no_abap_spooljob = 1.

IF sy-subrc <> 0.

MESSAGE e014(/ds1/a) WITH text-034.

ENDIF.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = w_doc_chng

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = i_objpack

contents_txt = i_objtxt

contents_bin = i_mess_att

receivers = i_reclist.

0 Kudos

hi,

I copied your code into my program. I am getting some errors few variables are not declared.

Can u send me the entire code.

Regards,

vinod

Former Member
0 Kudos

Hi

Regarding the spool request you are asking.

First check if SY-SPONO is useful in ur case .

Otherwise check table TSP01..spool no are stored in this table in field

RQIDENT and RQOWNER contains User ID . RQCRETIME is created time .

U can select these fields using SELECT and read the latest record with RQCRETIME . You can get the latest SPOOL .

Hope this Helps .