Skip to Content
author's profile photo Former Member
Former Member

How to convert spool to pdf & then sent mail ?

For Billing document in SD module ,via VF02 we are creating spools.

We are using RSTXPDFT4, to convert spool request to PDF.

There are some 100 Invoices, & hence there are 100 spools.

We have to give this spool no one by one in the above program to convert to PDF, which is taking time.

Is there any way, where we can convert all the spools at one go & conver to PDF ?.Also, can this Billing document PDF, be directly sent to some recipients via e-mail from SAP ??

for the above problem ..i got the below link

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/8cd6adbb-0301-0010-39ba-938c601d5db9

in the program,what to give in selection screen.

which program is being called in submit.

also when i run the report....no mail is fired.

<removed_by_moderator>

Edited by: Julius Bussche on Oct 31, 2008 12:43 PM

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 31, 2008 at 11:03 AM

    hello,

    u can make use of these FM's SO_DOCUMENT_SEND_API1

    SO_NEW_DOCUMENT_SEND_API1

    to send mail .

    thank u,

    santhosh

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 31, 2008 at 11:03 AM

    Hi

    Check out the following link

    https://wiki.sdn.sap.com/wiki/display/Snippets/ConvertsspoolrequestintoPDFdocumentand+emails

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 31, 2008 at 11:04 AM

    try following code:

    PERFORM frm_pro_email.

    FORM frm_pro_email.

    PERFORM convert_spool_to_pdf.

    DESCRIBE TABLE gt_mess_att LINES gd_recsize.

    CHECK gd_recsize > 0.

    PERFORM send_email.

    ENDFORM. " process_email

    FORM convert_spool_to_pdf.

    CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

    EXPORTING

    src_spoolid = gs_scriptresults-tdspoolid

    no_dialog = ' '

    • DST_DEVICE =

    • PDF_DESTINATION =

    IMPORTING

    pdf_bytecount = numbytes

    pdf_spoolid = pdfspoolid

    • OTF_PAGECOUNT =

    btc_jobname = jobname

    btc_jobcount = jobcount

    TABLES

    pdf = 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.

    IF sy-subrc <> 0.

    RAISE conversion_to_pdf.

    ENDIF.

    CHECK sy-subrc = 0.

    CLEAR: gd_buffer, gt_mess_att.

    REFRESH: gt_mess_att[].

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

    LOOP AT pdf.

    TRANSLATE pdf USING ' ~'.

    CONCATENATE gd_buffer pdf INTO gd_buffer.

    ENDLOOP.

    TRANSLATE gd_buffer USING '~ '.

    DO.

    gt_mess_att = gd_buffer.

    APPEND gt_mess_att.

    SHIFT gd_buffer LEFT BY 255 PLACES.

    IF gd_buffer IS INITIAL.

    EXIT.

    ENDIF.

    ENDDO.

    ENDFORM. " conv

    FORM send_email .

    DATA: lv_sub(80).

    CLEAR gd_subject.

    REFRESH it_mess_bod.

    • Default subject matter

    CONCATENATE 'IBM GLOBAL FINANCING ORDER CONFIRMATION'

    vbdka-vbeln

    INTO lv_sub SEPARATED BY space.

    gd_attachment_desc = lv_sub.

    DATA : p_sender LIKE somlreci1-receiver.

    p_sender = gs_user-email.

    • If no sender specified - default blank

    IF p_sender EQ space.

    gd_sender_type = space.

    ELSE.

    gd_sender_type = 'INT'.

    ENDIF.

    it_mess_bod-line = c_head_text.

    APPEND it_mess_bod.

    it_mess_bod-line = c_email_text.

    APPEND it_mess_bod.

    it_mess_bod-line = c_email_text1.

    APPEND it_mess_bod.

    it_mess_bod-line = c_head_text.

    APPEND it_mess_bod.

    it_mess_bod-line = c_end_text.

    APPEND it_mess_bod.

    it_mess_bod-line = c_end_text.

    APPEND it_mess_bod.

    CLEAR it_mess_bod.

    • Send file by email as .pdf speadsheet

    PERFORM send_file_as_email_attachment

    TABLES it_mess_bod

    gt_mess_att

    USING lv_sub

    'PDF'

    gd_attachment_name

    gd_attachment_desc

    p_sender

    gd_sender_type

    CHANGING gd_error

    gd_reciever.

    ENDFORM. " send_email

    FORM send_file_as_email_attachment TABLES it_message

    it_attach

    USING 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_mtitle LIKE sodocchgi1-obj_descr,

    ld_format TYPE so_obj_tp ,

    ld_attdescription(50), "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_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

    t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,

    w_cnt TYPE i,

    w_sent_all(1) TYPE c, "#EC NEEDED

    w_doc_data LIKE sodocchgi1.

    DATA : BEGIN OF gt_shptoemail OCCURS 0,

    lv_email LIKE somlreci1-receiver,

    END OF gt_shptoemail.

    CLEAR gt_shptoemail.

    REFRESH gt_shptoemail.

    TABLES: vbpa.

    SELECT SINGLE * FROM vbak

    WHERE vbeln = vbdka-vbeln.

    SELECT SINGLE * INTO vbpa FROM vbpa

    WHERE vbeln = vbdka-vbeln

    AND parvw = 'RE'. " Bill to party

    IF sy-subrc = 0.

    SELECT smtp_addr INTO TABLE gt_shptoemail FROM adr6

    WHERE addrnumber = vbpa-adrnr.

    ELSE.

    • Can not find the Bill to part

    MESSAGE e999(zm) WITH

    text-e01.

    ENDIF.

    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 = '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.

    IF NOT gt_shptoemail[] IS INITIAL.

    SORT gt_shptoemail .

    DELETE ADJACENT DUPLICATES FROM gt_shptoemail.

    LOOP AT gt_shptoemail.

    t_receivers-receiver = gt_shptoemail-lv_email.

    t_receivers-rec_type = 'U'.

    t_receivers-com_type = 'INT'.

    t_receivers-notif_del = 'X'.

    t_receivers-notif_ndel = 'X'.

    APPEND t_receivers.

    CLEAR t_receivers.

    ENDLOOP.

    ELSE.

    • There is no one to email the output to

    CLEAR: syst-msgv1, syst-msgv2, syst-msgv3, syst-msgv4.

    retcode = 1.

    syst-msgid = 'ZM'.

    syst-msgno = 005.

    syst-msgty = 'E'.

    syst-msgv1 = text-e02.

    PERFORM protocol_update.

    ENDIF.

    CALL FUNCTION 'SO_DOCUMENT_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.

    IF sy-subrc = 0.

    LOOP AT gt_shptoemail.

    syst-msgid = 'Z1'.

    syst-msgno = 075.

    syst-msgty = 'S'.

    syst-msgv1 = text-s01.

    syst-msgv2 = gt_shptoemail-lv_email.

    CLEAR syst-msgv3.

    CLEAR syst-msgv4.

    PERFORM protocol_update.

    IF sy-batch = 'X'.

    MESSAGE i999(z1) WITH text-s01 gt_shptoemail-lv_email.

    ENDIF.

    ENDLOOP.

    ENDIF.

    • Populate zerror return code

    ld_error = sy-subrc.

    • Populate zreceiver return code

    LOOP AT t_receivers.

    ld_receiver = t_receivers-retrn_code.

    ENDLOOP.

    ENDFORM.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 31, 2008 at 12:17 PM

    Hello,

    You can use the logic for converting spool to PDF using program : RSTXPDFT4 . Alternatively you can use FM: CONVERT_ABAPSPOOLJOB_2_PDF . In this FM you need to pass the Spool id .

    Thereafter use FM SO_NEW_DOCUMENT_ATT_SEND_API1

    to send PDF as attachment in mail.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.