‎2007 Aug 10 12:35 AM
Hello! I hope someone could help me on this one...
I am now trying to develop a program that sends an email with multiple pdf attachments. I saw in one of the threads I think that an alternative to using the function modules is to use methods. The steps I did prior to the email subroutine are the following:
1. Call the Smartform to return an OTF table
2. Convert the OTF Using the 'CONVERT_OTF' function
3. Call the email subroutine
Now I am having some problems with the following code:
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = text
i_length = '12'
i_subject = '' ).
*--- Add attachments
IF NOT t_pdf_vrs[] IS INITIAL.
CLEAR binary_content[].
binary_content[] = t_pdf_vrs[]. "<==PROBLEM HERE
CASE p_rtyp.
WHEN 'V'.
CONCATENATE 'VRS' p_lifnr sy-datlo
INTO i_att_sub separated by '_'.
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = 'PDF'
i_attachment_subject = i_att_sub
i_att_content_hex = binary_content.
WHEN 'M',
ENDCASE.
ENDIF.I get an error saying:
<b>"BINARY_CONTENT" and "T_PDF_VRS" are not mutually convertible. In Unicode programs, "BINARY_CONTENT" must have the same structure layout as "T_PDF_VRS", independent of the length of a Unicode character.</b>
The declarations of the tables in question are the following:
DATA binary_content TYPE solix_tab.
DATA t_pdf_vrs LIKE tline OCCURS 0 with HEADER LINE.The t_pdf_vrs table contains the <b>lines</b> parameter from the CONVERT_OTF fm.
Please help. Points for any helpful answer.
Thanks in advance.
‎2007 Aug 10 4:44 AM
The CONVERT_OTF_2_PDF function returns the PDF data in a table of STRUCTURE TLINE which has lines of 134 characters long (2 + 132). The send email functions or methods want the data in a structure of length 255 (TYPE SOLI_TAB).
The returned PDF data is actually binary data, so you need to combine the input table entries as a single long string, and then split this into the output as blocks of 255 characters. Take care using CONCATENATE to do this - it trims spaces which corrupts the PDF if you do not have the RESPECTING BLANKS addition.
DATA: l_str TYPE string.
LOOP AT it_input.
CONCATENATE l_str it_input INTO l_str RESPECTING BLANKS.
ENDLOOP.
DATA: l_len TYPE i.
DO.
l_len = STRLEN( l_str ).
IF l_len = 0. EXIT. ENDIF.
IF l_len > 255. l_len = 255. ENDIF.
it_output = l_str+0(l_len).
APPEND it_output.
l_str = l_str+l_len.
ENDDO.Andrew
Message was edited by:
Andrew Marshall
‎2007 Aug 10 2:20 AM
chk both internal fields are same.
binary_content[] = t_pdf_vrs[].
refer the same strture.
‎2007 Aug 10 2:33 AM
Hi,
Try to use SX_OBJECT_CONVERT_OTF_PDF instead of CONVERT_OTF
CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
EXPORTING
format_src = 'OTF'
format_dst = 'PDF'
devtype = 'PRINTER'
len_in = lv_len_in
TABLES
content_in = lt_content_in
content_out = lt_content_out.
gt_pdfdata[] = lt_content_out[].
aRs
‎2007 Aug 10 3:17 AM
Hi aRs,
When I checked the FM you suggested, I got different parameters:
CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
EXPORTING
FORMAT_SRC =
FORMAT_DST =
* ADDR_TYPE =
* DEVTYPE =
* FUNCPARA =
CHANGING
TRANSFER_BIN =
CONTENT_TXT =
CONTENT_BIN =
OBJHEAD =
LEN =
* EXCEPTIONS
* ERR_CONV_FAILED = 1
* OTHERS = 2
.
‎2007 Aug 10 4:03 AM
‎2007 Aug 10 4:44 AM
The CONVERT_OTF_2_PDF function returns the PDF data in a table of STRUCTURE TLINE which has lines of 134 characters long (2 + 132). The send email functions or methods want the data in a structure of length 255 (TYPE SOLI_TAB).
The returned PDF data is actually binary data, so you need to combine the input table entries as a single long string, and then split this into the output as blocks of 255 characters. Take care using CONCATENATE to do this - it trims spaces which corrupts the PDF if you do not have the RESPECTING BLANKS addition.
DATA: l_str TYPE string.
LOOP AT it_input.
CONCATENATE l_str it_input INTO l_str RESPECTING BLANKS.
ENDLOOP.
DATA: l_len TYPE i.
DO.
l_len = STRLEN( l_str ).
IF l_len = 0. EXIT. ENDIF.
IF l_len > 255. l_len = 255. ENDIF.
it_output = l_str+0(l_len).
APPEND it_output.
l_str = l_str+l_len.
ENDDO.Andrew
Message was edited by:
Andrew Marshall
‎2007 Aug 10 5:23 AM
Hi Andrew!
Thanks for the info. It was a bit weird because the function SX_OBJECT_CONVERT_OTF_PDF have different parameters from the ones given by aRs, but checking the function code itself I discovered that formatting of the table is very much similar to the code you gave. Will try this. Thanks again!