*&---------------------------------------------------------------------*
*& Report ZDUMMY_1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zmail_pdf_xls.
* Selection-screen.
*data it_attach.
SELECTION-SCREEN BEGIN OF LINE.
* Email address
SELECTION-SCREEN COMMENT 2(20) v_text1 FOR FIELD p_email.
PARAMETERS: p_email(50) OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
* Business object type
SELECTION-SCREEN COMMENT 2(20) v_text2 FOR FIELD p_bo.
PARAMETERS: p_bo TYPE borident-objtype DEFAULT 'BUS2078'.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
* Business object ID
SELECTION-SCREEN COMMENT 2(20) v_text3 FOR FIELD p_boid.
PARAMETERS: p_boid TYPE borident-objkey DEFAULT '000200000093'.
SELECTION-SCREEN END OF LINE.
DATA: it_attach TYPE TABLE OF soli,
wa_attach TYPE soli.
DATA: it_body TYPE TABLE OF soli ,
wa_body TYPE soli.
DATA: it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE.
* Internal table declarations.
DATA: lt_links TYPE TABLE OF relgraphlk,
lv_document_id TYPE sofolenti1-doc_id,
lt_plist LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE,
lt_soli LIKE soli OCCURS 100 WITH HEADER LINE,
lt_rec_tab LIKE somlreci1 OCCURS 1 WITH HEADER LINE,
lt_roles TYPE STANDARD TABLE OF relroles,
lt_appllinks TYPE STANDARD TABLE OF srl_aprel,
lt_object_content_l LIKE solisti1 OCCURS 0 WITH HEADER LINE,
lt_object_content LIKE solisti1 OCCURS 0 WITH HEADER LINE,
lt_doc_dat LIKE sofolenti1.
TYPES: ty_t_pdf TYPE STANDARD TABLE OF tline.
CONSTANTS: c_new_line TYPE char255 VALUE '<br>'.
* Variables.
DATA: lv_objtp LIKE soodk-objtp,
lv_lang LIKE tst01-dlang,
lv_line_size TYPE i VALUE 255,
lv_name LIKE soextreci1-receiver.
* Work areas
DATA: lwa_doc_data LIKE sodocchgi1,
lwa_document_data LIKE sofolenti1,
lwa_links LIKE LINE OF lt_links,
lwa_object TYPE borident.
DATA: lo_is_object_a TYPE sibflporb,
t_links TYPE obl_t_link,
wa_links LIKE LINE OF t_links.
DATA : lt_rel TYPE obl_t_relt,
wa_rel LIKE LINE OF lt_rel.
*For pdf display
DATA: gt_otf_from_fm TYPE ssfcrescl. "OTF data recd
DATA: gs_control_parameters TYPE ssfctrlop,
gs_output_options TYPE ssfcompop.
DATA: gt_email_body TYPE STANDARD TABLE OF solisti1,
gs_email_body TYPE solisti1.
DATA : lf_name TYPE rs38l_fnam.
* Initialization.
INITIALIZATION.
* Set the texts.
v_text1 = 'Email addr.'.
v_text2 = 'Business obj type'.
v_text3 = 'Business obj ID'.
* Start-of-selection.
START-OF-SELECTION.
* Assign the values
lwa_object-objkey = p_boid.
lwa_object-objtype = p_bo.
lo_is_object_a-instid = p_boid.
lo_is_object_a-typeid = p_bo.
lo_is_object_a-catid = 'BO'.
wa_rel-sign = 'I'.
wa_rel-option = 'EQ'.
wa_rel-low = 'ATTA'.
APPEND wa_rel TO lt_rel.
TRY.
CALL METHOD cl_binary_relation=>read_links
EXPORTING
is_object = lo_is_object_a
* IP_LOGSYS =
* IT_ROLE_OPTIONS =
it_relation_options = lt_rel
* IP_NO_BUFFER = SPACE
IMPORTING
et_links = t_links
* ET_ROLES =
.
ENDTRY.
* Process the attachment list
LOOP AT t_links INTO wa_links WHERE typeid_b = 'MESSAGE'.
MOVE wa_links-instid_b TO lv_document_id.
* Read the data
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
EXPORTING
document_id = lv_document_id
IMPORTING
document_data = lwa_document_data
TABLES
object_content = lt_object_content_l
EXCEPTIONS
document_id_not_exist = 1
operation_no_authorization = 2
x_error = 3
OTHERS = 4.
* Prepare the data.
lt_plist-transf_bin = 'X'.
lt_plist-head_start = 0.
lt_plist-head_num = 0.
lt_plist-body_start = 0.
lt_plist-body_num = 0.
lt_plist-doc_type = 'RAW'.
lt_plist-obj_descr = lwa_document_data-obj_descr.
APPEND lt_plist.
lt_plist-transf_bin = 'X'.
lt_plist-head_start = 0.
lt_plist-head_num = 0.
IF sy-tabix = 1.
lt_plist-body_start = 1.
ELSE.
DESCRIBE TABLE lt_object_content.
lt_plist-body_start = sy-tfill + 1.
ENDIF.
DESCRIBE TABLE lt_object_content_l LINES lt_plist-body_num.
lt_plist-doc_type = lwa_document_data-obj_type.
* Get the size.
READ TABLE lt_object_content_l INDEX lt_plist-body_num.
lt_plist-doc_size = ( lt_plist-body_num - 1 ) * lv_line_size
+ STRLEN( lt_object_content_l ).
APPEND lt_plist.
* Move the values to the main internal table.
APPEND LINES OF lt_object_content_l TO lt_object_content.
ENDLOOP.
REFRESH t_links[].
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZD2S_QM_CLAIMREPORT'
IMPORTING
fm_name = lf_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc = 0.
gs_control_parameters-no_dialog = 'X'.
gs_control_parameters-preview = ' '.
gs_control_parameters-langu = sy-langu.
ENDIF.
gs_output_options-tdnoprev = space. " make sure preview is off otherwise
gs_control_parameters-getotf = 'X'.
gs_output_options-tddest = 'LOCL'.
CALL FUNCTION lf_name
EXPORTING
control_parameters = gs_control_parameters
output_options = gs_output_options
user_settings = ' '
IMPORTING
job_output_info = gt_otf_from_fm.
IF sy-subrc = 0.
PERFORM convert_otf .
ENDIF.
INCLUDE zdummy_6_convert_otff01.
*----------------------------------------------------------------------*
***INCLUDE ZDUMMY_4_CONVERT_OTFF01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form CONVERT_OTF
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM convert_otf .
DATA: c_pdf TYPE string VALUE 'PDF',
c_u TYPE so_escape VALUE 'U',
c_raw TYPE so_obj_tp VALUE 'RAW',
c_test TYPE so_obj_nam VALUE 'PPAP.pdf',
c_objnam TYPE so_obj_nam VALUE 'PPAP',
* c_desnam TYPE so_obj_des VALUE 'PPAP Notification Process',
c_sen_f TYPE so_obj_sns VALUE 'F',
c_x TYPE c VALUE 'X'.
DATA: l_subject TYPE so_obj_des,
l_att_type TYPE soodk-objtp.
DATA: l_pdf_xstring TYPE xstring,
l_pdf_string TYPE xstring.
DATA: l_otfdata_tab TYPE STANDARD TABLE OF itcoo." OCCURS 1 WITH HEADER LINE.
DATA: g_pdf_tab TYPE STANDARD TABLE OF tline.
DATA: lt_xls TYPE STANDARD TABLE OF solisti1.
DATA: ls_xls LIKE LINE OF lt_xls.
DATA: lt_pdf_tab1 TYPE STANDARD TABLE OF solisti1.
DATA: ls_pdf_tab1 LIKE LINE OF lt_pdf_tab1.
*
CONSTANTS:
*-- Constants used in the body of the Email (HTML)
c_htm TYPE char3 VALUE 'RAW',
c_xls(3) TYPE c VALUE 'XLS'.
* *-- Local data declaration for sending mail
DATA: l_send_request TYPE REF TO cl_bcs,
l_document TYPE REF TO cl_document_bcs,
l_sender TYPE REF TO cl_sapuser_bcs,
l_sub TYPE char50,
l_recipient TYPE REF TO if_recipient_bcs,
tl_contents TYPE STANDARD TABLE OF soli,
l_doc_len TYPE so_obj_len,
l_cnt TYPE sy-tabix,
l_rcv_email TYPE adr6-smtp_addr,
l_result TYPE sy-binpt,
l_bcs_exception TYPE REF TO cx_bcs,
l_subj TYPE string,
wa_contents TYPE solisti1,
w_document TYPE REF TO cl_document_bcs.
DATA: l_wa_mail TYPE zdicv_emailuser.
DATA : bin_size TYPE i,
l_size TYPE i,
l_lines TYPE i.
DATA : lt_att_content_hex TYPE solix_tab.
*Variables
DATA: lw_com_type TYPE somlreci1-com_type VALUE 'INT'.
REFRESH :lt_xls[] ,g_pdf_tab[],l_otfdata_tab[],lt_att_content_hex[].
*--------------------------------------------------------------------*
*OTF data
l_otfdata_tab[] = gt_otf_from_fm-otfdata[].
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = c_pdf
IMPORTING
bin_filesize = l_pdf_xstring
bin_file = l_pdf_string
TABLES
otf = l_otfdata_tab
lines = g_pdf_tab
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = l_pdf_string
IMPORTING
output_length = bin_size
TABLES
binary_tab = lt_att_content_hex.
APPEND LINES OF lt_object_content[] TO lt_xls[] .
* Populate message body text
PERFORM populate_email_message_body.
TRY.
*-- Create persistent send request
l_send_request = cl_bcs=>create_persistent( ).
tl_contents[] = it_body[].
*-- Get the length of the Document
DESCRIBE TABLE tl_contents LINES l_cnt.
READ TABLE tl_contents INTO wa_contents INDEX l_cnt.
l_doc_len = ( l_cnt - 1 ) * 255 + STRLEN( wa_contents ).
*-- Subject of the mail
CONCATENATE 'GOS '
'Attachments'
INTO l_sub
SEPARATED BY space.
*-- Create Document
l_document = cl_document_bcs=>create_document(
i_type = c_htm
i_text = tl_contents
i_length = l_doc_len
i_subject = l_sub
i_language = sy-langu
i_importance = '1' ).
*-- Subject of the mail
MOVE l_sub TO l_subj.
w_document = l_document.
TRY.
*-- Set the Message Subject
CALL METHOD l_send_request->set_message_subject
EXPORTING
ip_subject = l_subj.
CATCH cx_sy_dyn_call_illegal_method.
ENDTRY.
*-- Add document to send request
CALL METHOD l_send_request->set_document( l_document ).
*-- Do send delivery info for successful mails
CALL METHOD l_send_request->set_status_attributes
EXPORTING
i_requested_status = 'E'
i_status_mail = 'A'.
*-- Set sender
l_sender = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD l_send_request->set_sender
EXPORTING
i_sender = l_sender.
*-- Attachments for the mail
IF NOT lt_xls[] IS INITIAL.
*-- Subject of the Attachment
l_subject = text-s01.
*-- Format of the Attachment
l_att_type = 'XLS'.
TRY.
*-- Add Attachment to the Document
CALL METHOD w_document->add_attachment
EXPORTING
i_attachment_type = l_att_type
i_attachment_subject = l_subject
i_att_content_text = lt_xls.
CATCH cx_document_bcs.
ENDTRY.
ENDIF.
*/ Size to multiplied by 2 for UNICODE enabled systems
* DESCRIBE TABLE lt_att_content_hex LINES l_lines." l_size
* l_size = l_lines * 2 * 255.
*-- Append Empty line to display data in full view.
IF NOT lt_att_content_hex[] IS INITIAL.
*-- Subject of the Attachment
l_subject = text-s02.
l_att_type = 'PDF'.
TRY.
*-- Add Attachment to the Document
CALL METHOD w_document->add_attachment
EXPORTING
i_attachment_type = l_att_type
* i_attachment_size = l_size
i_attachment_subject = l_subject
i_att_content_hex = lt_att_content_hex.
CATCH cx_document_bcs.
ENDTRY.
ENDIF.
*-- Add the recipients to the Send mail
l_rcv_email = pe.manikandan@gmail.com'.
CHECK NOT l_rcv_email IS INITIAL.
l_recipient = cl_cam_address_bcs=>create_internet_address(
l_rcv_email ).
CALL METHOD l_send_request->add_recipient
EXPORTING
i_recipient = l_recipient
i_express = c_x.
*-- Send Email
CALL METHOD l_send_request->send(
RECEIVING
result = l_result ).
IF l_result = c_x.
ENDIF.
CATCH cx_bcs INTO l_bcs_exception.
IF l_result NE c_x.
ENDIF.
ENDTRY.
COMMIT WORK.
ENDFORM. " CONVERT_OTF
*&---------------------------------------------------------------------*
*& Form POPULATE_EMAIL_MESSAGE_BODY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM populate_email_message_body .
*-- New Line
wa_body-line = c_new_line.
APPEND wa_body TO it_body.
CLEAR wa_body.
wa_body-line = text-t02.
APPEND wa_body TO it_body.
CLEAR wa_body.
ENDFORM. " POPULATE_EMAIL_MESSAGE_BODY
No comments:
Post a Comment