Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Spool to PDF sent by mail - Pb to open PDF -

nathalie_michel
Participant
0 Kudos

Dear all,

I try to convert a spool in a PDF file using the FM 'CONVERT_ABAPSPOOLJOB_2_PDF' and then I send it by mail using 'SO_NEW_DOCUMENT_ATT_SEND_API1'.

When I open the attachement I have the error message from adobe.This error can change depending on what I have in the spool (I let the cover page, I have error 117 from Adobe, I dont' let the cover page I have an other error) !!!

I think that this problem comes from the FM 'CONVERT_ABAPSPOOLJOB_2_PDF' - Sap has just provided 2 Sap note regarding this FM, But it seems that the problem is for Unicode system.

I'm in 4.7, all my programs are flag "Unicode Checks Activ", but my system isn't yet translate in Unicode.

Do you have an idea? May I have to implement the new sap note, or do you know an other solution?

Thanks for your answers .

Nat

19 REPLIES 19

Former Member
0 Kudos

Try Using SCMS_XSTRING_TO_BINARY after Converting to PDF. There us array of Function modules in the same Function group.

Regards

Shital

0 Kudos

Hello Sibi.

it's just a LIST - No SmartForm, No Sapscript.

Nat

0 Kudos

Hello Nathalie Michel ,

I dont think the version of the system is the problem .Even i worked on the same spool to pdf conversion and mailing and it is working fine.

You can try this code

https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/convertSpoolrequesttoPDFandsendase-mail

If you are not satisfied with this answer please revert back.

Regards,

K.Sibi

Edited by: sibi k kanagaraj on Apr 16, 2009 2:18 PM

0 Kudos

Refer [code1|http://sapprograms.blogspot.com/2008/11/convert-spool-request-to-pdf-and-send.html] or [code2|http://www.abapcode.info/2007/05/convert-spool-request-to-pdf-and-send.html]

0 Kudos

Hello Sibi,

I have based my program on this coding, I did some modification because I execute it online, and submit an other program. I copied your coding without changing anything, I receive a mail, but the PDF attached is empty !

Nat

0 Kudos

have you zipped it and mailed?

0 Kudos

Not zipped

0 Kudos

K fine.Since the code is not available i make a guess of the problem

1.It might be due to non addition of ".pdf" when you have created the name of the pdf file (try concatenating .pdf) Are you getting pdf file format icon or windows icon for the pdf which you are getting ?

2.It might be due to the presence of special characters like : \ / * etc which is not permitted in the pdf file name s.

@ note in the code which is above is not mine .So I cant take the credit , Please remove the " YOUR CODE" words from the reply

If the above is not the case please revert back.

Regards,

K.Sibi

*@ note in the code which is above is not mine .So I cant take the credit , Please remove the " YOUR CODE" words from the reply *

Edited by: sibi k kanagaraj on Apr 16, 2009 3:03 PM

0 Kudos

Hi Sibi, sorry for YOUR CODE ...on my last message

I become completely crazy ... find enclosed my coding - Just the modfications -

DATA: PARAMS LIKE PRI_PARAMS,

VALID(1).

START-OF-SELECTION.

IF sy-batch EQ 'X'.

PERFORM get_job_details.

PERFORM obtain_spool_id.

ELSE.

************************************

      • Alternative way could be to submit another program and store spool

      • id into memory, will be stored in sy-spono.

CALL FUNCTION 'GET_PRINT_PARAMETERS'

EXPORTING DESTINATION = 'ZL16'

COPIES = '1'

LIST_NAME = 'TEST'

LIST_TEXT = 'SUBMIT ... TO SAP-SPOOL'

IMMEDIATELY = ' '

RELEASE = 'X'

NEW_LIST_ID = 'X'

  • EXPIRATION = DAYS

LINE_SIZE = 132

LINE_COUNT = 65

LAYOUT = 'X_65_132'

SAP_COVER_PAGE = ' '

COVER_PAGE = ' '

RECEIVER = 'SAP*'

DEPARTMENT = 'System'

NO_DIALOG = ' '

IMPORTING OUT_PARAMETERS = PARAMS

VALID = VALID.

submit YFKD17AK

to sap-spool

spool parameters PARAMS

  • archive parameters %_print

without spool dynpro

and return.

************************************

  • Get spool id from program called above

get PARAMETER ID 'YSPOOL' FIELD nc_spool_nr.

move nc_spool_nr to gd_spool_nr.

ENDIF.

PERFORM convert_spool_to_pdf.

PERFORM process_email.

if p_delspl EQ 'X'.

PERFORM delete_spool.

endif.

IF sy-sysid = c_dev.

wait up to 5 seconds.

SUBMIT rsconn01 WITH mode = 'INT'

WITH output = 'X'

AND RETURN.

ENDIF.

" ELSE.

" SKIP.

" WRITE:/ 'Program must be executed in background in-order for spool',

" 'request to be created.'.

" ENDIF.

----


  • FORM convert_spool_to_pdf *

----


FORM convert_spool_to_pdf.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = gd_spool_nr

no_dialog = c_no

dst_device = c_device

IMPORTING

pdf_bytecount = gd_bytecount

TABLES

pdf = it_pdf_output

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.

CHECK sy-subrc = 0.

  • Transfer the 132-long strings to 255-long strings

LOOP AT it_pdf_output.

TRANSLATE it_pdf_output USING ' ~'.

CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.

ENDLOOP.

TRANSLATE gd_buffer USING '~ '.

DO.

it_mess_att = gd_buffer.

APPEND it_mess_att.

SHIFT gd_buffer LEFT BY 255 PLACES.

IF gd_buffer IS INITIAL.

EXIT.

ENDIF.

ENDDO.

ENDFORM.

----


  • FORM process_email *

----


FORM process_email.

DESCRIBE TABLE it_mess_att LINES gd_recsize.

CHECK gd_recsize > 0.

PERFORM send_email USING p_email1.

  • perform send_email using p_email2.

ENDFORM.

----


  • FORM send_email *

----


  • --> p_email *

----


FORM send_email USING p_email.

CHECK NOT ( p_email IS INITIAL ).

REFRESH it_mess_bod.

  • Default subject matter

gd_subject = 'Subject'.

gd_attachment_desc = 'Attachname'.

  • CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.

it_mess_bod = sy-DATUM.

APPEND it_mess_bod.

it_mess_bod = gd_spool_nr.

APPEND it_mess_bod.

  • If no sender specified - default blank

IF p_sender EQ space.

gd_sender_type = space.

ELSE.

gd_sender_type = 'PDF'.

ENDIF.

  • Send file by email as .xls speadsheet

PERFORM send_file_as_email_attachment

tables it_mess_bod

it_mess_att

using p_email

'Example .xls documnet attachment'

'PDF'

gd_attachment_name

gd_attachment_desc

p_sender

gd_sender_type

changing gd_error

gd_reciever.

ENDFORM.

*& Form SEND_FILE_AS_EMAIL_ATTACHMENT

&----


FORM send_file_as_email_attachment tables it_message

it_attach

using p_email

p_mtitle

p_format

p_filename

p_attdescription

p_sender_address

p_sender_addres_type

changing p_error

p_reciever.

DATA: ld_error TYPE sy-subrc,

ld_reciever TYPE sy-subrc,

ld_mtitle LIKE sodocchgi1-obj_descr,

ld_email LIKE somlreci1-receiver,

ld_format TYPE so_obj_tp ,

ld_attdescription TYPE so_obj_nam ,

ld_attfilename TYPE so_obj_des ,

ld_sender_address LIKE soextreci1-receiver,

ld_sender_address_type LIKE soextreci1-adr_typ,

ld_receiver LIKE sy-subrc.

data: t_packing_list like sopcklsti1 occurs 0 with header line,

t_contents like solisti1 occurs 0 with header line,

t_receivers like somlreci1 occurs 0 with header line,

t_attachment like solisti1 occurs 0 with header line,

t_object_header like solisti1 occurs 0 with header line,

w_cnt type i,

w_sent_all(1) type c,

w_doc_data like sodocchgi1.

ld_email = p_email.

ld_mtitle = p_mtitle.

ld_format = p_format.

ld_attdescription = p_attdescription.

ld_attfilename = p_filename.

ld_sender_address = p_sender_address.

ld_sender_address_type = p_sender_addres_type.

  • Fill the document data.

w_doc_data-doc_size = 1.

  • Populate the subject/generic message attributes

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ld_mtitle .

w_doc_data-sensitivty = 'F'.

  • Fill the document data and get size of attachment

CLEAR w_doc_data.

READ TABLE it_attach INDEX w_cnt.

w_doc_data-doc_size =

( w_cnt - 1 ) * 255 + STRLEN( it_attach ).

w_doc_data-obj_langu = sy-langu.

  • w_doc_data-obj_name = 'LIST'.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ld_mtitle.

w_doc_data-sensitivty = 'F'.

CLEAR t_attachment.

REFRESH t_attachment.

t_attachment[] = it_attach[].

  • Describe the body of the message

CLEAR t_packing_list.

REFRESH t_packing_list.

t_packing_list-transf_bin = space.

t_packing_list-head_start = 1.

t_packing_list-head_num = 0.

t_packing_list-body_start = 1.

DESCRIBE TABLE it_message LINES t_packing_list-body_num.

t_packing_list-doc_type = 'RAW'.

APPEND t_packing_list.

  • Create attachment notification

t_packing_list-transf_bin = 'X'.

t_packing_list-head_start = 1.

t_packing_list-head_num = 1.

t_packing_list-body_start = 1.

DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.

t_packing_list-doc_type = ld_format.

t_packing_list-obj_descr = ld_attdescription.

t_packing_list-obj_name = ld_attfilename.

t_packing_list-doc_size = t_packing_list-body_num * 255.

APPEND t_packing_list.

  • Add the recipients email address

CLEAR t_receivers.

REFRESH t_receivers.

t_receivers-receiver = ld_email.

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-notif_del = 'X'.

t_receivers-notif_ndel = 'X'.

APPEND t_receivers.

  • CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = w_doc_data

put_in_outbox = 'X'

  • sender_address = ld_sender_address

  • sender_address_type = ld_sender_address_type

commit_work = 'X'

IMPORTING

sent_to_all = w_sent_all

TABLES

packing_list = t_packing_list

contents_bin = t_attachment

contents_txt = it_message

receivers = t_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.

  • Populate zerror return code

ld_error = sy-subrc.

  • Populate zreceiver return code

LOOP AT t_receivers.

ld_receiver = t_receivers-retrn_code.

ENDLOOP.

ENDFORM.

+ The part of my Submit Program

Sort imodif.

LOOP AT imodif.

write 😕 'TEST PDF'.

ENDLOOP.

NEW-PAGE.

commit work.

new-page print off.

SET PARAMETER ID 'YSPOOL' FIELD sy-spono .

TOP-OF-PAGE.

WRITE 😕 'TEST'.

??? If I let the coding like this, it's ok, I just replace in the top of page

WRITE 😕 'TEST'. by WRITE 😕 'TESTABCDEABDEZZZZZZZZZFGJGFDGDFJGJ E30'., it's always OK, but if I add a blank like WRITE 😕 'TESTABCDEABDEZZZZZZZZZ FGJGFDGDFJGJ E30'. then I have a problem !!!!!

0 Kudos

I tried again and put again a second blank in the first line of the top of page, and now it's OK ..., then I can suppose that sometime is good, sometime not.... so we also can suppose that the problem isn't in the coding of the program !

0 Kudos

Hello Nathalie Michel ,

Please try posting the code with the markup

So that we can try it and give our maximum to clear the error .Do you get any errors or exceptions or is that your pdf is appearing and you are not finding anything inside your PDF.

I think you can try this way ..

Try various spool numbers like spools with pages 1 ,2 , and even large pages like 200.See the size of the pdf file which you get .If they differ , then surely your program is working fine.

Actually is the "test" the name of the pdf which is being created . You want a file name with spaces.Is my understanding rite .Please correct me if I am not getting the correct problem .

Regards,

K.SIbi

Edited by: sibi k kanagaraj on Apr 17, 2009 6:49 AM

Former Member
0 Kudos

Hello Nathalie Michel ,

Is your spool , a spool as a reult of report execution or script execution .Or in other words ..is it a LIST or not ?

Regards,

K.Sibi

former_member203501
Active Contributor
0 Kudos

hi see this coding ....i did it in the 4.7 for sending the script output to pdf through mail...



  wa_maildata-obj_name = 'EMAIL'.
  wa_maildata-obj_descr = 'Settlement Details'.

*-----mail contents
  it_mailtext-line = 'Sub-sequent settlement Details'.
  APPEND it_mailtext.

  DESCRIBE TABLE it_mailtext LINES v_lines.
  READ TABLE it_mailtext INDEX v_lines.
  wa_maildata-doc_size = ( v_lines - 1 ) * 255 + STRLEN( it_mailtext ).

*Creation of the entry for the compressed document
  CLEAR it_mailpack-transf_bin.
  it_mailpack-head_start = 1.
  it_mailpack-head_num   = 0.
  it_mailpack-body_start = 1.
  it_mailpack-body_num   = v_lines.
  it_mailpack-doc_type   = 'RAW'.
  APPEND it_mailpack.

*-----Get OTF data
  LOOP AT it_otfdata.
    it_mailcont-line = it_otfdata.
    APPEND it_mailcont.
  ENDLOOP.

*---Move  OTF data into binary table
  LOOP AT it_mailcont.
    MOVE-CORRESPONDING it_mailcont TO it_mailbin.
    APPEND it_mailbin.
  ENDLOOP.

*---Get no of lines in Binary data table
  DESCRIBE TABLE it_mailbin LINES v_lines.

*---Fill name of the header of email
  it_mailhead = 'Subsequent Settlement Details.OTF'.
  APPEND it_mailhead.

*---Creation of the entry for the compressed attachment
  it_mailpack-transf_bin   = 'X'.
  it_mailpack-head_start   = 1.
  it_mailpack-head_num     = 1.
  it_mailpack-body_start   = 1.
  it_mailpack-body_num     = v_lines.
  it_mailpack-doc_type     = 'OTF'.
  it_mailpack-obj_name     = 'EMAIL'.
  it_mailpack-obj_descr    = 'Settlement Details'.
  it_mailpack-doc_size     = v_lines * 255.
  APPEND it_mailpack.

*----Get email address from the address number of vendor
  CALL FUNCTION 'ADDR_GET_REMOTE'
    EXPORTING
      addrnumber = l_adrnum
    TABLES
      adsmtp     = it_adsmtp.

*----Get mail address
  loop at it_adsmtp where remark = 'AP_SUB_SETT'.
    it_mailrec-receiver   = it_adsmtp-smtp_addr.
    it_mailrec-rec_type   = 'U'.
    it_mailrec-com_type   = 'INT'.
    APPEND it_mailrec.
  endloop.

*---Send email with PDF attachment
 IF not it_mailrec[] is initial.
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
      EXPORTING
        document_data = wa_maildata
        put_in_outbox = ' '
        COMMIT_WORK   = 'X'
      TABLES
        packing_list  = it_mailpack
        object_header = it_mailhead
        contents_bin  = it_mailbin
        contents_txt  = it_mailtext
        receivers     = it_mailrec.
  ELSE.
    MESSAGE 'No email id Exist for the vendor' TYPE 'E'.
  ENDIF.

Former Member
0 Kudos

Hi,

Try the following logic to download the PDF file on your local machine and check whether it opens corectly. If YES then there might some problem in the way you are mailing the PDF file.


data: w_ident like tsp01-rqident,
w_doctype like tsp01-rqdoctype,
w_bytecount type i.

data: itab_pdf like tline occurs 0 with header line.

parameter spoolnum like tsp01-rqident obligatory.

form get_abap_spool_in_pdf.
refresh itab_pdf.
call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
exporting
src_spoolid = w_ident
importing
pdf_bytecount = w_bytecount
tables
pdf = itab_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.

if sy-subrc ne 0.
message e398(00) with 'Cannot convert to PDF. Error =' sy-subrc.
endif.
endform.

************************************************************************
form get_otf_spool_in_pdf.
refresh itab_pdf.
call function 'CONVERT_OTFSPOOLJOB_2_PDF'
exporting
src_spoolid = w_ident
importing
pdf_bytecount = w_bytecount
tables
pdf = itab_pdf
exceptions
err_no_otf_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_dstdevice = 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.
if sy-subrc <> 0.
message e398(00) with 'Cannot convert to PDF. Error =' sy-subrc.
endif.
endform.

form write_pdf_spool_to_pc.
call function 'WS_DOWNLOAD'
exporting
bin_filesize = w_bytecount
filename = pcfile
filetype = 'BIN'
tables
data_tab = itab_pdf
exceptions
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
others = 10.
if sy-subrc <> 0.
message e398(00) with 'Cannot download to PC. Error =' sy-subrc.
endif.
endform.

Regards,

Mansi.

0 Kudos

Hello mansi,

Thanks for your answer. Simple but now I can focus my problem only on the part when I send the mail, because when I dowload the PDF on my computer, it's correct. Means the FM CONVERT_ABAPSPOOLJOB_2_PDF functions correctly.

I'll check again my program reagarding the part send_mail.

Thanks a lot at all .

Nathalie

Former Member
0 Kudos

Hello Nathalie Michel ,

Is your problem solved or not .

Regards,

K.Sibi

0 Kudos

Hi Sibi,

I solved it ... but I'm not sure it'll be correct in the future . I explain.

In the coding I use to transfer the mail, I have

  • Transfer the 132-long strings to 255-long strings

LOOP AT it_pdf_output.

TRANSLATE it_pdf_output USING ' ~'.

CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.

ENDLOOP.

TRANSLATE gd_buffer USING '~ '.

DO.

it_mess_att = gd_buffer.

APPEND it_mess_att.

SHIFT gd_buffer LEFT BY 255 PLACES.

IF gd_buffer IS INITIAL.

EXIT.

ENDIF.

ENDDO.

I think you know that. When I did a test downloading directly my PDF on my computer, I downloaded the table it_pdf_output, means no change with blank and the caracter ''. But when I opened my PDF file with WordPad, I saw that the caracter '' was in the coding.

Then in my program, I replaced '~' by '|', and now it's ok.

but now I'm not sure that this caracter '|' is used or not in the PDF coding. (not a specialist)...

Do you use an other caracter?

Thanks

Nathalie

0 Kudos

Hello Nathalie ,

I am not sure abt the other characters which could replace '~' .If in future you encounter problems please post it .

Regards,

K.Sibi

nathalie_michel
Participant
0 Kudos

Dear all,

Just to inform how I solved my Problem - My coding - part convert_spool_to_pdf -

FORM convert_spool_to_pdf.

data: lv_fdpos type syst-fdpos,

lv_part1 type string,

lv_part2 type string.

data: ii type i,

jj type i,

kk type i.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = gd_spool_nr

no_dialog = c_no

dst_device = c_device

IMPORTING

pdf_bytecount = gd_bytecount

TABLES

pdf = it_pdf_output

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.

CHECK sy-subrc = 0.

  • Transfer the 2 + 132-long strings to 255-long strings

LOOP AT it_pdf_output.

CLEAR ii.

IF it_pdf_output+133(1) is INITIAL.

ii = 1.

it_pdf_output+133(1) = '*'.

ENDIF.

  • TRANSLATE it_pdf_output USING w_trans .

CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.

IF kk = 1.

lv_fdpos = jj - 1 .

lv_part1 = gd_buffer(lv_fdpos).

lv_fdpos = jj.

lv_part2 = gd_buffer+lv_fdpos.

clear gd_buffer.

concatenate lv_part1 lv_part2 into gd_buffer separated by space.

CLEAR : lv_fdpos, lv_part1, lv_part2.

ENDIF.

CLEAR kk.

IF ii = 1.

kk = 1.

ENDIF.

jj = STRLEN( gd_buffer ).

ENDLOOP.

DO.

it_mess_att = gd_buffer.

APPEND it_mess_att.

SHIFT gd_buffer LEFT BY 255 PLACES.

IF gd_buffer IS INITIAL.

EXIT.

ENDIF.

ENDDO.

ENDFORM.

Instead to use translate ' ' and then ' ', as we can read in some other coding. Using a character in the "TRANSLATE" we have the risk that this character already exists before the first "TRANSLATE" and then with the 2nd TRANSLATE, we lost information ~ are replaced by space, but some should not be modified !

Thanks at all

Nathalie