2009 Sep 18 10:08 AM
Hi All,
As my Post has been rejected from SAP Community Network Forum, Sorry for posting my thread in two categoires.
I have tried to search for solution in SDN but could not found a relevent solution.
I am able to send an Internal table using cl_document_bcs class to send XLS and Doc types as attachment as follows:
For Example :
My Internal table is tbl_bseg which final output table:
data : lv_string TYPE string.
*- tbl_bseg contains my data so..
LOOP AT tbl_bseg INTO wa_bseg.
CONCATENATE lv_string wa_bseg-bukrs wa_bseg-belnr wa_bseg-gjahr wa_bseg-buzei
wa_bseg-zumsk CN_CR_LF INTO lv_string SEPARATED BY CN_TAB.
*- Horizontal Tab Stop Character
*- Carriage Return and Line Feed
CLEAR wa_bseg.
ENDLOOP.
DATA: lv_xstring TYPE xstring,
ta_excelx TYPE SOLIX_TAB.
*- Convert the string into xstring
call function 'SCMS_STRING_TO_XSTRING'
exporting
TEXT = p_string
IMPORTING
BUFFER = lv_xstring
EXCEPTIONS
FAILED = 1
OTHERS = 2.
IF SY-SUBRC 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*- Convert the string into binary table
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_xstring
TABLES
binary_tab = ta_excelx.
*-
wa_attachments-type = 'XLS'
wa_attachments-subject = 'This final testing - XLS'.
wa_attachments-content_hex = lv_xstring.
APPEND wa_attachments to ta_attachments.
*-------- create and set document with attachment ---------------
cl_documents = cl_document_bcs=>create_document(
i_type = CN_RAW
i_text = gta_body
i_subject = wa_subject ).
* add attachment to document
CALL METHOD cl_document_bcs->add_attachment
EXPORTING i_attachment_type = wa_attachments-TYPE
i_attachment_subject = wa_attachments-SUBJECT
i_att_content_hex = wa_attachments-CONTENT_HEX.But my issue is to send a the same Internal Table tbl_bseg as attachement as PDF using in the same steps:
A sample snippet of code could be helpful or any valuable solution are welcome.
Regards,
Suneel G
2009 Sep 18 2:54 PM
You need to do make your internal table's content to PDF format.
The easiest way would be:
Generate a Spool of your data
Call FM CONVERT_ABAPSPOOLJOB_2_PDF to get the PDF data
Now, you can use the method ADD_ATTACHMENT to attach your PDF file as mail attachement.
Regards,
Naimesh Patel
You need to do make your internal table's content to PDF format.
The easiest way would be:
Generate a Spool of your data
Call FM CONVERT_ABAPSPOOLJOB_2_PDF to get the PDF data
Now, you can use the method ADD_ATTACHMENT to attach your PDF file as mail attachement.
Regards,
Naimesh Patel
2009 Sep 18 2:54 PM
You need to do make your internal table's content to PDF format.
The easiest way would be:
Generate a Spool of your data
Call FM CONVERT_ABAPSPOOLJOB_2_PDF to get the PDF data
Now, you can use the method ADD_ATTACHMENT to attach your PDF file as mail attachement.
Regards,
Naimesh Patel
2009 Sep 23 8:01 AM
>
> You need to do make your internal table's content to PDF format.
>
> The easiest way would be:
> Generate a Spool of your data
> Call FM CONVERT_ABAPSPOOLJOB_2_PDF to get the PDF data
> Now, you can use the method ADD_ATTACHMENT to attach your PDF file as mail attachement.
>
> Regards,
> Naimesh Patel
Thanks for the valuable reply, I have done what mentioned by You Naimesh.
By using FM CONVERT_ABAPSPOOLJOB_2_PDF I have got pdf data into tbl_pdf as this of structure TLINE,
How we need to convert in to solix_tab.
In order to use
Could you please give me light on this.
Regards,
Suneel G
2009 Sep 27 5:03 PM
1) convert TLINE_TAB to SOLI_TAB type (not solix_tab) using SX_TABLE_LINE_WIDTH_CHANGE function module
2) convert SOLI_TAB to XSTRING using SCMS_BINARY_TO_XSTRING function module
3) convert XSTRING to SOLIX_TAB using SCMS_XSTRING_TO_BINARY function module
Note: SOLI_TAB is chosen because it has only one field (required to use SCMS_BINARY_TO_XSTRING) and has a width (255) greater than TLINE_TAB (required to use SX_TABLE_LINE_WIDTH_CHANGE)
Edited by: Sandra Rossi on Sep 27, 2009 6:38 PM
2009 Sep 29 3:05 AM
Hi Sandra Rossi,
Thanks for valueble suggestion, I have tried doing it but I could do it so.
For ex:
1. From my CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF' I get it_pdf_output of type tline_tab.
the content of it_pdf_output is looking like some chinese characters.
2. Using below FM to convert 132 tline to 255 solitab.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
LINE_WIDTH_SRC = '132'
LINE_WIDTH_DST = '255'
TRANSFER_BIN = 'X' " I tried commenting this too
TABLES
CONTENT_IN = it_pdf_output
CONTENT_OUT = it_pdf_solitab
3. then use the below FM to convert it_pdf_solitab to it_pdf_xstring
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
INPUT_LENGTH = '255'
FIRST_LINE = 0
LAST_LINE = 0
IMPORTING
BUFFER = it_pdf_xstring
TABLES
BINARY_TAB = it_pdf_solitab
4. Then using this method
*- Converts pdf_xstring format into solix tab
CALL METHOD CL_DOCUMENT_BCS=>XSTRING_TO_SOLIX
EXPORTING
IP_XSTRING = it_pdf_xstring
RECEIVING
RT_SOLIX = pdf_content.
But I could not open the pdf_content, Could you please let me know where I am going wrong.
Regards,
Suneel G
2009 Sep 29 10:03 AM
Your error is with SCMS_BINARY_TO_XSTRING : you must not pass input_length = '255', instead use the binary length that is returned by CONVERT_ABAPSPOOLJOB_2_PDF.
The TRANSFER_BIN must be set to space (default).
Moreover, you may omit optional parameters:
- LINE_WIDTH_SRC and LINE_WIDTH_DST in SX_TABLE_LINE_WIDTH_CHANGE.
- FIRST_LINE and LAST_LINE in SCMS_BINARY_TO_XSTRING
Why did you use CL_DOCUMENT_BCS=>XSTRING_TO_SOLIX, is it because there was a problem with SCMS_XSTRING_TO_BINARY ?
2009 Sep 29 10:48 AM
Hi Sandra Rossi,
Thanks for the suggestions, I have done the changes accordingly and have tested but no luck, I could get a PDF with out
errors.
Can provide me any other ideas, or can send me any sample.
Regards,
Suneel G
2009 Sep 29 1:22 PM
Here is an example (it works for me). Check if it works by opening `C:\ffffffffff.pdf` with Acrobat Reader. Then adapt it to send the mail. If it doesn't work, then the problem is the way you send the mail.
REPORT z.
DATA e_spoolid TYPE rspoid.
PERFORM ali_spool_generator
CHANGING
e_spoolid.
DATA et_pdf TYPE tline_tab.
DATA e_binary_length TYPE i.
PERFORM convert_ali_spool_to_pdf
USING
e_spoolid
CHANGING
et_pdf
e_binary_length.
data SOLI_TAB type SOLI_TAB.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
TABLES
content_in = et_pdf
content_out = SOLI_TAB
EXCEPTIONS
OTHERS = 4.
data e_xstring TYPE xstring.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = e_binary_length
IMPORTING
buffer = e_xstring
TABLES
binary_tab = SOLI_TAB
EXCEPTIONS
OTHERS = 2.
DATA lt_solix TYPE solix_tab.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = e_xstring
TABLES
binary_tab = lt_solix.
* >>>>>>>>>>>>>>
* REPLACE THAT BY YOUR CODE TO SEND MAIL
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = e_binary_length
filename = `C:\ffffffffff.pdf`
filetype = 'BIN'
CHANGING
data_tab = lt_solix
EXCEPTIONS
OTHERS = 3.
* <<<<<<<<<<<<<<
FORM ali_spool_generator
CHANGING
e_spoolid TYPE rspoid.
NEW-PAGE PRINT ON NO DIALOG.
WRITE : / 'Hello World'.
NEW-PAGE PRINT OFF.
e_spoolid = sy-spono.
COMMIT WORK.
ENDFORM.
FORM convert_ali_spool_to_pdf
USING
i_spoolid TYPE rspoid
CHANGING
et_pdf TYPE tline_tab
e_binary_length TYPE i.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = i_spoolid
no_dialog = 'X'
IMPORTING
pdf_bytecount = e_binary_length
TABLES
pdf = et_pdf
EXCEPTIONS
OTHERS = 12.
ENDFORM.
2009 Sep 30 3:42 AM
Hi Sandra Rossi,
This works perfect and I am able to send the mail with out any errors.
Thanks a lot for your efforts and ideas.
I have a concer, as I was creating spool id with following FM's:
a. 'RSPO_OPEN_SPOOLREQUEST'
b. 'RSPO_WRITE_SPOOLREQUEST'
c. 'RSPO_CLOSE_SPOOLREQUEST'
Once I get spool ID I am doing as you have done, Do you have any idea why I am not getting PDF data with spool id what I got.
Thanks once agian.
Regards,
Suneel G
2009 Sep 30 10:11 AM
I can't see if you don't show your code (please just paste the minimum lines of code we need to answer you, not the whole code!)
Why do you use function modules instead of (shorter) ABAP statements? Refer to my code above, I generate a spool too!
2009 Sep 30 10:39 AM
Hi Sandra Rossi,
Your code is working and I am using the same code in my program, the spool data in ABAP list format.
As previously I was using the below FM's for spool no, I want to know why these FM's are not working:
Here is the code what I was doing previously.
data: v_handle type SY-TABIX,
gd_spool_nr type TSP01-RQIDENT,
v_rc,
v_errmessage.
data: v_text(80) type C.
data: it_mara like mara OCCURS 0 WITH HEADER LINE.
select * from mara
into table it_mara UP TO 10 ROWS.
CALL FUNCTION 'RSPO_OPEN_SPOOLREQUEST'
EXPORTING
dest = 'LOCL'
IMPORTING
handle = v_handle
spoolid = e_spoolid
rc = v_rc
errmessage = v_errmessage.
LOOP AT it_mara.
v_text = it_mara-matnr.
CALL FUNCTION 'RSPO_WRITE_SPOOLREQUEST'
EXPORTING
handle = v_handle
text = v_text
IMPORTING
rc = v_rc
errmessage = v_errmessage
EXCEPTIONS
handle_not_valid = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDLOOP.
CALL FUNCTION 'RSPO_CLOSE_SPOOLREQUEST'
EXPORTING
handle = v_handle
IMPORTING
rc = v_rc
errmessage = v_errmessage
EXCEPTIONS
handle_not_valid = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.and then using CONVERT_ABAPSPOOLJOB_2_PDF
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = gd_spool_nr
no_dialog = 'X'
dst_device = 'LOCL'
IMPORTING
pdf_bytecount = gd_bytecount
TABLES
pdf = it_pdf_output
EXCEPTIONS
OTHERS = 12.This code was not working and if I check spool its created with RAW data format.
I want to ask you any idea why this is not working.
Regards,
Suneel G
2009 Sep 30 2:25 PM
It doesn't work because you don't convert the text into abap list format. So you get an undefined spool, although CONVERT_ABAPSPOOLJOB_2_PDF expects an ABAP list spool (while CONVERT_OTFSPOOLJOB_2_PDF function module expects an OTF spool).
So, you must use abap WRITE so that to get ABAP list format : you may also use SUBMIT ... EXPORTING LIST TO MEMORY and related function modules (see abap doc) to get an abap list format without generating a spool in background.
2009 Sep 30 4:22 PM
Sorry, my last answer is wrong.
In fact, it doesn't work (you probably get the error message "Impossible to open this file because it doesn't contain any page" from Acrobat Reader) because you have to call function module RSPO_PAGE_BREAK_SPOOLREQUEST to terminate the last page!
Note also that you have to manage yourself the page break, otherwise if you write only one page with 20000 lines for example, these lines will be printed on the same unique page, and be overwritten several times, as the PDF converter restarts at the top of 1st page when bottom is reached.
So, really, my opinion is that these function modules should be used only in rare cases, use WRITE statement instead.
2009 Oct 01 3:48 AM
Hi Sandra Rossi,
I really thank you for the efforts and appreciate your knowledge.
If we use this RSPO_PAGE_BREAK_SPOOLREQUEST my problem can be solved, but need to think when we need a Page
break.
As said by Sandra I am using Write statements to get my PDF lines.
Regards,
Suneel G
2010 Oct 07 10:44 AM
Hi Sandra,
Can you plz help me in sending email with pdf attachmetnt.
I am getting the output with this FM
CONVERT_OTFSPOOLJOB_2_PDF
SX_TABLE_LINE_WIDTH_CHANGE
SCMS_BINARY_TO_XSTRING
SCMS_XSTRING_TO_BINARY
and sending mail with 'SO_NEW_DOCUMENT_ATT_SEND_API1' by
passing in content_hex as 'lt_solix'.
But i am getting '.pdf' file with junk values in receiver emailid.
what can be the problem?
I am passing Doc type as 'SCR'.
If I set doc type as 'PDF' in packing list then it gives error
...'Adobe Reader can not open the '.....pdf' bcoz it is either not a supported filet type.......wasn't correctly decoded'
Please tell me what i need to check.
Thanks.
2012 Feb 06 12:16 PM
2012 Sep 05 12:52 PM
Could you please tell me how u solved the issue..
I'm getting same error while sending PDF attachment.
It says "PDF could not be opened, since it has no pages"
Any kind of help will be rewarded points.
Thanks,
Sandy
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |