Dear Experts,
My requirement is in my output a classical report is generated and a page break take place as soon as new custpmer code comes.For each customer code a separate page is coming. I need to send mail to that customer as soon as page break take place.The next page generated to that customer mail id. The third page generated to third customer's mail id and so on.My requirement is I have to send my output in pdf form to customers. Presently I am able to send the pdf generated to one customer only. My code is picking last customer from internal table and mail is going to that customer only.Guid eme how to resolve it.
Thanks in advance.
top-of-page.
perform header_data.
FORM DISPLAY_DATA .
sort it_final by kunrg erdat.
data col type i value 4.
clear wa_final_customer.
clear wa_final.
loop at it_final_customer into wa_final_customer.
cust = wa_final_customer-kunrg.
cust_name = wa_final_customer-name1.
town = wa_final_customer-city.
street = wa_final_customer-STRAS.
zip = wa_final_customer-pstlz.
addr1 = wa_final_customer-STR_SUPPL1.
addr2 = wa_final_customer-STR_SUPPL2.
state = wa_final_customer-state.
***----------------logic for page break on arrival of new customer ----------------------------------------------
at new kunrg.
new-page line-count 50.
loop at it_final into wa_final where kunrg = wa_final_customer-kunrg.
tot_value = wa_final-INVOICE_VALUE + tot_value.
format color = col.
AT FIRST.
PERFORM get_print_parameters.
ENDAT.
write : / wa_final-name_p(30),
44 wa_final-vbeln(10),
80 wa_final-erdat(8),
91 wa_final-INVOICE_VALUE,
119 ' '.
endloop.
skip 3.
write : / ' Total-Value' color 5,
91 tot_value color 5,
118 ' '.
AT LAST.
g_spool_no = sy-spono.
NEW-PAGE PRINT OFF.
CALL FUNCTION 'ABAP4_COMMIT_WORK'.
endat.
endat.
clear tot_value.
endloop.
PERFORM send_mail.
skip 6.
ENDFORM.
FORM HEADER_DATA .
data col type i value 4.
skip.
concatenate cust_name street town zip addr1 addr2 state into ship_party separated by space.
write : / 'Ship-to-Party : 'color 4 , cust .
skip.
write : / 'Ship-to-Party : 'color 4 , ship_party.
skip.
write : / 'Invoice Date : 'color 4 , so_erdat-low , '-' , so_erdat-high .
skip.
skip.
format color = col.
write : / 'Sending Plant' ,
42 ' Invoice No. ' ,
78' Invoice date ' ,
96 ' Invoice value' ,
119 ''.
skip.
skip.
ENDFORM. " HEADER_DATA
FORM GET_PRINT_PARAMETERS .
"Variables
DATA:
l_lay TYPE pri_params-paart,
l_lines TYPE pri_params-linct,
l_cols TYPE pri_params-linsz,
l_val TYPE c.
*Types
TYPES:
t_pripar TYPE pri_params,
t_arcpar TYPE arc_params.
"Work areas
DATA:
lw_pripar TYPE t_pripar,
lw_arcpar TYPE t_arcpar.
l_lay = 'X_65_132'.
l_lines = 65.
l_cols = 132.
"Read, determine, change spool print parameters and archive parameters
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
in_archive_parameters = lw_arcpar
in_parameters = lw_pripar
layout = l_lay
line_count = l_lines
line_size = l_cols
no_dialog = 'X'
IMPORTING
out_archive_parameters = lw_arcpar
out_parameters = lw_pripar
valid = l_val
EXCEPTIONS
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
OTHERS = 4.
IF l_val NE space AND sy-subrc = 0.
lw_pripar-prrel = space.
lw_pripar-primm = space.
NEW-PAGE PRINT ON
NEW-SECTION
PARAMETERS lw_pripar
ARCHIVE PARAMETERS lw_arcpar
NO DIALOG.
ENDIF.
ENDFORM. " GET_PRINT_PARAMETERS
FORM SEND_MAIL .
"Subject of the mail.
w_document_data-obj_name = 'MAIL_TO_HEAD'.
w_document_data-obj_descr = 'Regarding Mail Program by SAP ABAP'.
"Body of the mail
PERFORM build_body_of_mail
USING:space,
'Hi,'.
"Convert ABAP Spool job to PDF
PERFORM convert_spool_2_pdf TABLES i_attachment.
"Write Packing List for Body
DESCRIBE TABLE i_body_msg LINES g_tab_lines.
w_packing_list-head_start = 1.
w_packing_list-head_num = 0.
w_packing_list-body_start = 1.
w_packing_list-body_num = g_tab_lines.
w_packing_list-doc_type = 'RAW'.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.
"Write Packing List for Attachment
w_packing_list-transf_bin = 'X'.
w_packing_list-head_start = 1.
w_packing_list-head_num = 1.
w_packing_list-body_start = 1.
DESCRIBE TABLE i_attachment LINES w_packing_list-body_num.
w_packing_list-doc_type = 'PDF'.
w_packing_list-obj_descr = 'PDF Attachment'.
w_packing_list-obj_name = 'PDF_ATTACHMENT'.
w_packing_list-doc_size = w_packing_list-body_num * 255.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.
"Fill the document data and get size of attachment
w_document_data-obj_langu = sy-langu.
READ TABLE i_attachment INTO w_attachment INDEX g_tab_lines.
w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + strlen( w_attachment ).
"Receivers List.
* loop at it_adr6 into wa_adr6.
w_receivers-rec_type = 'U'. "Internet address
w_receivers-receiver = wa_final-SMTP_ADDR.
w_receivers-com_type = 'INT'.
w_receivers-notif_del = 'X'.
w_receivers-notif_ndel = 'X'.
APPEND w_receivers TO i_receivers .
CLEAR:w_receivers.
*endloop.
"Function module to send mail to Recipients
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = w_document_data
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = g_sent_to_all
TABLES
packing_list = i_packing_list
contents_bin = i_attachment
contents_txt = i_body_msg
receivers = i_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.
IF sy-subrc = 0 .
MESSAGE i303(me) WITH 'Mail has been Successfully Sent.'.
WAIT UP TO 2 SECONDS.
"This program starts the SAPconnect send process.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ELSE.
ENDIF.
ENDFORM. " SEND_MAIL
FORM build_body_of_mail USING l_message.
w_body_msg = l_message.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.
ENDFORM. " build_body_of_mail " BUILD_BODY_OF_MAIL
FORM convert_spool_2_pdf TABLES l_attachment .
"Variables
DATA:
l_no_of_bytes TYPE i,
l_pdf_spoolid LIKE tsp01-rqident,
l_jobname LIKE tbtcjob-jobname,
l_jobcount LIKE tbtcjob-jobcount.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = g_spool_no
no_dialog = ' '
IMPORTING
pdf_bytecount = l_no_of_bytes
pdf_spoolid = l_pdf_spoolid
btc_jobname = l_jobname
btc_jobcount = l_jobcount
TABLES
pdf = i_pdf
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.
CASE sy-subrc.
WHEN 0.
WHEN 1.
MESSAGE s000(0k) WITH 'No ABAP Spool Job'.
EXIT.
WHEN 2.
MESSAGE s000(0k) WITH 'Spool Number does not exist'.
EXIT.
WHEN 3.
MESSAGE s000(0k) WITH 'No permission for spool'.
EXIT.
WHEN OTHERS.
MESSAGE s000(0k)
WITH 'Error in Function CONVERT_ABAPSPOOLJOB_2_PDF'.
EXIT.
ENDCASE.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_src = 134
line_width_dst = 255
TABLES
content_in = i_pdf
content_out = l_attachment
EXCEPTIONS
err_line_width_src_too_long = 1
err_line_width_dst_too_long = 2
err_conv_failed = 3
OTHERS = 4.
IF sy-subrc NE 0.
MESSAGE s000(0k) WITH 'Conversion Failed'.
EXIT.
ENDIF.
ENDFORM. " convert_spool_2_pdf
Hi,
As per your code, it will generate only one spool.
To solve this issue, Get the mail address of all the customers in a internal table. Loop thorugh the internal table and populate the internal table I_RECEIVERS with all the mail id.
Then call the FM to send mail.
Cheers
~Niranjan
Hi Niranjan
I tried that in FORM DISPLAY_DATA .
Present code:
AT LAST.
g_spool_no = sy-spono.
NEW-PAGE PRINT OFF.
CALL FUNCTION 'ABAP4_COMMIT_WORK'.
endat.
endat.
clear tot_value.
endloop.
PERFORM send_mail.
skip 6.
ENDFORM.
I changed it to below code. But then the AT last block get skipped and spool number is not passed to g_spool_no and no commit take place..Mail is send but without any attachment.
AT LAST.
g_spool_no = sy-spono.
NEW-PAGE PRINT OFF.
CALL FUNCTION 'ABAP4_COMMIT_WORK'.
endat.
endat.
clear tot_value.
PERFORM send_mail.
endloop.
skip 6.
ENDFORM.
Hi,
Please try putting the PERFORM send_mail before the ENDAT.
Cheers
~Niranjan
I tried that also. If I put it before endat. The at Last is skipped at all.
Any suggestion for this issues ?
Dear experts Help me in resolving this issue
Hi,
It seems your program is generating the single spool output for all the customer. And single spool output can not be split into multiple PDFs..
You can write a wrapper program, which will submit your current program for individual Customers and generate Spool #. Take those spools, convert into PDFs and send the emails separately..