1. Purchase Order PDF Conversion
"Control Parameters
ls_ctrlop-getotf = 'X'.
ls_ctrlop-no_dialog = 'X'.
ls_ctrlop-preview = space.
"Output Options
ls_outopt-tdnoprev = 'X'.
ls_outopt-tddest = 'LOCL'.
ls_outopt-tdnoprint = 'X'.
"Get Function Name using FM : 'SSF_FUNCTION_MODULE_NAME'
"Convert Smartform to DF contents
CALL FUNCTION lv_fname
EXPORTING
control_parameters = ls_ctrlop
output_options = ls_outopt
smmdcdta_po = smmdcdta_po
smmcondv_po = sconditionvalues
"output_options = output_options
po_head = po_head
IMPORTING
job_output_info = lt_otfdata
TABLES
it_items_po = it_items_po .
lt_otf[ ] = lt_otfdata-otfdata[ ] .
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = lv_bin_filesize
bin_file = lv_bin_xstr
TABLES
otf = lt_otf[]
lines = lt_pdf_tab[]
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
"***Xstring to binary
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_bin_xstr
TABLES
binary_tab = lt_binary_content.
"" lt_binary_content
"" is very important since it has the PDF Contents of Smartform
:Add the following within the program lines:
DATA:
emailsubject TYPE char80,
it_message TYPE STANDARD TABLE OF solisti1,
wa_it_message LIKE LINE OF it_message.
CLEAR: it_message[], wa_it_message.
DEFINE add_html.
wa_it_message-line = &1.
APPEND wa_it_message TO it_message. CLEAR wa_it_message.
END-OF-DEFINITION.
add_html:
'<html>',
'<body>',
'<p><b>Dear concern,</b></p>'.
CASE email_level.
WHEN 'B'.
add_html:
'<p>Approval of the following Purchase Order is <b>REQUESTED</b>, kindly appprove it. Thanks.'. "by <b style="color:black;font-size:12px;" > ', approver_name, '</b>.</p>'.
WHEN OTHERS.
add_html:
'<p>This is to inform you that following Purchase Order has been <b>APPROVED</b> by <b style="color:black;font-size:12px;" > ', approver_name, '</b>.</p>'.
ENDCASE.
add_html:
'<br/>',
'<table >',
' <tbody>',
' <tr>', "#ffcc00
' <td style="background-color:#EE82EE;font-size:12px;border-width: 2px;border-style: solid;padding: 5px;" ><b>Purchase Order</b></td>',
' <td style="color:blue;font-size:14px;border-width: 2px;border-style: solid; padding: 5px;" ><b>', purch_order_no, '</b></td>',
' </tr>',
' <td style="background-color:#EE82EE;font-size:12px;border-width: 2px;border-style: solid;padding: 5px;" ><b>Vendor</b></td>',
' <td style="font-size:12px;border-width: 2px;border-style: solid;padding: 5px;" >', purch_order-vndrname, '</td>',
' </tr>',
' <tr>', "#ffcc00
' <td style="background-color:#EE82EE;font-size:12px;border-width: 2px;border-style: solid;padding: 5px;" ><b>Order Net Value:</b></td>',
' <td style="font-size:12px;border-width: 2px;border-style: solid; padding: 5px;" >', purch_order-currency, ' ', char_po_value, '</td>',
' </tr>',
' </tbody>',
'</table>'.
add_html:
' </tbody>',
'</table>'.
add_html:
'</br>',
'</br>',
'<p><em><i>A System generated notification.</i></em></p>',
"'<img src="http://www.sap.com/dam/application/shared/logos/sap-logo-svg.svg/sap-logo-svg.svg"></img>',
"'<img src="http://www.mitchells.com.pk/wp-content/uploads/2018/05/strawberry-squash.png" style="max-width:100%;">',
'<img src="http://www.anysite.com/wp-content/themes/images/logo.jpg" style="max-width:100%;">',
'</body>',
'</html>'.
DATA: main_text TYPE bcsy_text,
lt_mailsubject TYPE sodocchgi1,
mailsubject TYPE so_obj_des,
attchsubject LIKE sood-objdes.
DATA:
lv_size TYPE i.
mailsubject = psubject .
DATA(send_request) = cl_bcs=>create_persistent( ).
DATA(email_document) = cl_document_bcs=>create_document( i_type = 'HTM'
i_text = it_message
i_subject = mailsubject
).
DATA lt_att_head TYPE soli_tab.
"APPEND '<(>&< )>SO_FILENAME=Prob_Compl_Emps.xlsx' TO lt_att_head.
APPEND 'Purchase_Order.pdf' TO lt_att_head.
"-----------------------------------------------------------------
"" add the spread sheet as attachment to document object
attchsubject = `Purchase_Order.pdf` && purch_order_no && '_' && sy-datum+4(2) && '_' && sy-datum(4).
attchsubject = `Purchase_Order_` && purch_order_no .
APPEND attchsubject TO lt_att_head.
email_document->add_attachment(
i_attachment_type = 'pdf'
i_attachment_subject = attchsubject
i_attachment_size = CONV so_obj_len( lv_size )
i_attachment_header = lt_att_head
i_att_content_hex = lt_binpdf_content ).
send_request->set_document( email_document ).
"Recipients
DATA sender TYPE REF TO cl_cam_address_bcs.
DATA recipient TYPE REF TO cl_cam_address_bcs.
DATA: saprecipient TYPE REF TO if_recipient_bcs.
DATA: emailid TYPE ad_smtpadr.
sender = cl_cam_address_bcs=>create_internet_address( 'donotreply@mail.com' ).
send_request->set_sender( sender ).
recipient = cl_cam_address_bcs=>create_internet_address( 'proc_manager@mail.com' ).
send_request->add_recipient( recipient ).
TRY.
* CATCH cx_send_req_bcs. " BCS: Send Request Exceptions.
DATA(sent_to_all) = send_request->send( i_with_error_screen = 'X' ).
CATCH cx_root .
"bcs_exception->get_text().
ENDTRY.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
4 | |
3 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 |