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

Convert to PDF nad Send mail

Hello all,

I have an Internal table and i need to convert the same into PDF and send the mail as an attachment using CL_BCS.

Kindly help with the same by providing a good example.

Regards,

Arun

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

10 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Aug 11, 2009 at 12:44 PM
    *&---------------------------------------------------------------------*
    *&      Form  PROCESS_DATA
    *&---------------------------------------------------------------------*
    FORM process_data .
    
      SORT gt_final BY route route_pin pri_tech sec_tech mkt deltm.
    
      CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
        EXPORTING
          formname           = 'ZLSDR002_SM'
        IMPORTING
          fm_name            = g_fmodule
        EXCEPTIONS
          no_form            = 1
          no_function_module = 2
          OTHERS             = 3.
    
      gs_cparam-no_dialog = 'X'.     " Suppressing the dialog box
      gs_cparam-preview   = 'X'.     " for print preview
      gs_cparam-getotf    = 'X'.
    
      CALL FUNCTION g_fmodule
        EXPORTING
          control_parameters = gs_cparam
          output_options     = gs_outoptions
          g_pgbrk            = p_pgbrk
          g_date             = p_del_dt
          g_area             = g_area
        IMPORTING
          job_output_info    = gt_otf_from_fm
        TABLES
          gt_final           = gt_final
        EXCEPTIONS
          formatting_error   = 1
          internal_error     = 2
          send_error         = 3
          user_canceled      = 4
          OTHERS             = 5.
    
      gt_otf[] = gt_otf_from_fm-otfdata[].
    
      CALL FUNCTION 'CONVERT_OTF'
        EXPORTING
          format                = 'PDF'
          max_linewidth         = 132
        IMPORTING
          bin_filesize          = g_bin_filesize
        TABLES
          otf                   = gt_otf
          lines                 = gt_pdf_tab
        EXCEPTIONS
          err_max_linewidth     = 1
          err_format            = 2
          err_conv_not_possible = 3
          err_bad_otf           = 4
          OTHERS                = 5.
    
      CHECK sy-subrc = 0.
    
    * Transfer the 132-long strings to 255-long strings
      LOOP AT gt_pdf_tab.
        TRANSLATE gt_pdf_tab USING ' ~'.
        CONCATENATE g_buffer gt_pdf_tab INTO g_buffer.
      ENDLOOP.
    
      TRANSLATE g_buffer USING '~ '.
    
      DO.
        gt_mess_att = g_buffer.
        APPEND gt_mess_att.
        SHIFT g_buffer LEFT BY 255 PLACES.
        IF g_buffer IS INITIAL.
          EXIT.
        ENDIF.
      ENDDO.
    
    *  IF p_dnld EQ 'X'.            "Perform download
      PERFORM download_local.
    *  ENDIF.
    
      PERFORM process_email.
    
      IF sy-sysid = c_dev.
        WAIT UP TO 5 SECONDS.
        SUBMIT rsconn01 WITH mode   = 'INT'
                        WITH output = 'X'
                        AND RETURN.
      ENDIF.
    
    ENDFORM.                    " PROCESS_DATA
    
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 11, 2009 at 01:26 PM

    Hi,

    Check this link to convert internal table to pdf after which you can use CL_BCS to send email with the converted pdf as attachment

    [convertion-of-internal-table-data-to-pdf]

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 11, 2009 at 01:31 PM

    Cut and paste from above link. Do not copy other people's work

    Hi Arun,

    Try this.

    create Spool request for Internal Table or Output table..

    CALL FUNCTION 'RSPO_OPEN_SPOOLREQUEST'

    EXPORTING

    dest = 'LOCL'

    • LAYOUT =

    • NAME =

    • SUFFIX1 =

    • SUFFIX2 =

    • COPIES =

    • PRIO =

    • IMMEDIATE_PRINT =

    • AUTO_DELETE =

    • TITLELINE =

    • RECEIVER =

    • DIVISION =

    • AUTHORITY =

    • POSNAME =

    • ACTTIME =

    • LIFETIME = '8'

    • APPEND =

    • COVERPAGE =

    • CODEPAGE =

    • DOCTYPE =

    IMPORTING

    handle = v_handle

    spoolid = gd_spool_nr

    rc = v_rc

    errmessage = v_errmessage.

    LOOP AT i_mara.

    v_text = i_mara-matnr.

    CALL FUNCTION 'RSPO_WRITE_SPOOLREQUEST'

    EXPORTING

    handle = v_handle

    text = v_text

    • LENGTH =

    • CODEPAGE =

    • TRUNCATE =

    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 convert ABAP 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.

    and Down load the PDF to desk top..

    GUI_DOWNLOAD.

    Regards,

    Vijay

    Edited by: Matt on Aug 11, 2009 4:43 PM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 11, 2009 at 03:14 PM

    Hi Arun,

    I worked on a similar issue around 3 months back....we had an invoice smartform...our requirement was to convert it into PDF and send an email...well in ur case u have just internal table.

    I can advice you to create a smart for to print ur internal table first...we wont be displaying ur smartform we will create it to download it into pdf in some location at presentation server, after then we will send a email using OLE2 and call outlook in which we will attach the PDF and send the email....once email is sent we will delete the file which we downloaded on application server.

    Following is the code with wich we can achive the same.

    Firstly Data Declaration -


    >>>

    For PDF Download And Smartform Declare following variables------>>>

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

    • SMARTFORM and PDF DATA DECLARATION *

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

    DATA : w_fmname TYPE rs38l_fnam,

    w_form TYPE tdsfname VALUE 'ZSD_M_ME49'.

    *********************************PDF DATA******************************

    DATA: WA_CTRLOP TYPE SSFCTRLOP, "ssfctrlop,

    WA_OUTOPT TYPE SSFCOMPOP.

    DATA: T_OTFDATA TYPE SSFCRESCL,

    T_PDF_TAB LIKE TLINE OCCURS 0 WITH HEADER LINE.

    DATA: T_OTF TYPE ITCOO OCCURS 0 WITH HEADER LINE.

    DATA: W_BIN_FILESIZE TYPE I.",

    data :w_FILE_NAME type string,

    w_File_path type string,

    w_FULL_PATH type string.

    DATA: W_FILESIZE TYPE i.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 11, 2009 at 03:16 PM

    Continued from my last post.....

    after data declaration of pdf now we will declare data for email----->>>>

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

    • Data Declaration For E-Mail *

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

    TYPE-POOLS OLE2.

    DATA: W_PATH(256) TYPE C.

    DATA: begin of text_table occurs 0,

    text(255) TYPE c,

    end of text_table.

    data: wa_text_table like line of text_table.

    DATA: APPOUTLOOK TYPE OLE2_OBJECT,

    APPITEM TYPE OLE2_OBJECT,

    NAMESPACE TYPE OLE2_OBJECT,

    ATTACHS TYPE OLE2_OBJECT,

    BEGIN OF ITAB_PATHS OCCURS 0,

    PATH(255),

    END OF ITAB_PATHS,

    MAIL_INDEX TYPE I.

    DATA:TO1 TYPE STRING,

    CC1 TYPE STRING,

    SUB1 TYPE STRING.

    data : wa_itab_path like line of itab_paths.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 11, 2009 at 03:18 PM

    Continued from my last post------>>>>>>

    Now Code to download the PDF and send it as an attachment and delete the downloaded pdf after mail is sent is------>>>>>

    data: v_language TYPE sflangu VALUE 'E',

    v_e_devtype TYPE rspoptype.

    CALL FUNCTION 'SSF_GET_DEVICE_TYPE'

    EXPORTING

    i_language = v_language

    i_application = 'SAPDEFAULT'

    IMPORTING

    e_devtype = v_e_devtype.

    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

    EXPORTING

    FORMNAME = w_form

    IMPORTING

    FM_NAME = w_fmname

    EXCEPTIONS

    NO_FORM = 1

    NO_FUNCTION_MODULE = 2

    OTHERS = 3

    .

    IF sy-subrc <> 0.

    MESSAGE E002(zcpm) WITH 'Smartform call fails'.

    ENDIF.

    OUTPUT_OPTIONS-tdprinter = v_e_devtype.

    SSFCTRLOP1-no_dialog = 'X'.

    SSFCTRLOP1-getotf = 'X'.

    CALL FUNCTION w_fmname "'/1BCDWB/SF00000025'

    EXPORTING

    CONTROL_PARAMETERS = SSFCTRLOP1

    OUTPUT_OPTIONS = OUTPUT_OPTIONS

    IMPORTING

    JOB_OUTPUT_INFO = T_OTFDATA

    TABLES

    T_FINAL = T_FINAL

    T_ZSDT_WAGONS = T_ZSDT_WAGONS_1

    T_QTY = T_QTY

    T_QTY1 = T_QTY1

    T_CON1 = T_CON1

    T_CON2 = T_CON2

    EXCEPTIONS

    FORMATTING_ERROR = 1

    INTERNAL_ERROR = 2

    SEND_ERROR = 3

    USER_CANCELED = 4

    OTHERS = 5

    .

    IF SY-SUBRC <> 0.

    ENDIF.

    T_OTF[] = T_OTFDATA-OTFDATA[].

    CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

    format = 'PDF'

    max_linewidth = 132

    • ARCHIVE_INDEX = ' '

    IMPORTING

    bin_filesize = w_bin_filesize

    TABLES

    otf = t_otf

    lines = t_pdf_tab

    EXCEPTIONS

    err_max_linewidth = 1

    err_format = 2

    err_conv_not_possible = 3

    OTHERS = 4

    .

    IF sy-subrc <> 0.

    ENDIF.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 11, 2009 at 03:22 PM

    Continued from my last post......

    ************Saving the PDF file on to Application server***********************

    CONCATENATE 'C:\' wa_final-vbeln '.pdf' INTO w_FULL_PATH.

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    BIN_FILESIZE = w_bin_filesize

    FILENAME = w_FULL_PATH

    FILETYPE = 'BIN'

    IMPORTING

    FILELENGTH = w_filesize

    TABLES

    DATA_TAB = t_pdf_tab

    EXCEPTIONS

    FILE_WRITE_ERROR = 1

    NO_BATCH = 2

    GUI_REFUSE_FILETRANSFER = 3

    INVALID_TYPE = 4

    NO_AUTHORITY = 5

    UNKNOWN_ERROR = 6

    HEADER_NOT_ALLOWED = 7

    SEPARATOR_NOT_ALLOWED = 8

    FILESIZE_NOT_ALLOWED = 9

    HEADER_TOO_LONG = 10

    DP_ERROR_CREATE = 11

    DP_ERROR_SEND = 12

    DP_ERROR_WRITE = 13

    UNKNOWN_DP_ERROR = 14

    ACCESS_DENIED = 15

    DP_OUT_OF_MEMORY = 16

    DISK_FULL = 17

    DP_TIMEOUT = 18

    FILE_NOT_FOUND = 19

    DATAPROVIDER_EXCEPTION = 20

    CONTROL_FLUSH_ERROR = 21

    OTHERS = 22

    .

    wa_itab_path-path = w_FULL_PATH.

    APPEND wa_itab_path to itab_paths.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 11, 2009 at 03:29 PM

    Continued from my last post....

    Code till now i posted was to download the PDF to presentation server now i am posting the OLE2 Code to Call the outlook with attached PDF's.----->>>>

    CREATE OBJECT APPOUTLOOK 'outlook.application'.

    CALL METHOD OF APPOUTLOOK 'GetNameSpace' = NAMESPACE

    EXPORTING #1 = 'MAPI'.

    CALL METHOD OF APPOUTLOOK 'CreateItem' = APPITEM

    EXPORTING #1 = '0'.

    GET PROPERTY OF APPITEM 'Attachments' = ATTACHS. "creating outlook mail application and getting the mail attachments object.

    SET PROPERTY OF APPITEM 'to' = TO1."'xyz at zyx.com'. "u201D "to whom we will send mail

    SET PROPERTY OF APPITEM 'cc' = CC1."'xyz at zyx.com; abc at cba.com'. "u201D "to whom we will send mail in cc

    SET PROPERTY OF APPITEM 'Subject' = SUB1."'The first mail with OLE2'. "u201D mail subject

    DATA : GT TYPE STRING.

    DATA : KUNNR TYPE STRING.

    DATA : DATE TYPE STRING.

    GT = WA_FINAL-GT.

    KUNNR = WA_FINAL-KUNNR2.

    Call function 'CONVERSION_EXIT_ALPHA_OUTPUT'

    Exporting

    input = WA_FINAL-KUNNR2"KUNNR

    Importing

    output = WA_FINAL-KUNNR2."KUNNR.

    Call function 'CONVERSION_EXIT_ALPHA_OUTPUT'

    Exporting

    input = WA_FINAL-VBELN"KUNNR

    Importing

    output = WA_FINAL-VBELN."KUNNR.

    CONCATENATE WA_Final-FKDAT6(2) '.' WA_Final-FKDAT4(2) '.' WA_Final-FKDAT+0(4) INTO DATE.

    *CONDENSE WA_FINAL-VBELN.

    CONCATENATE 'Enclosed Bill No.' WA_FINAL-VBELN 'Dated' DATE 'of amount Rs.' GT 'against Dispatch To' WA_FINAL-KUNNR2 WA_FINAL-NAME11

    'FROM' WA_T001W-NAME2 'PLANT' '------SAP' SY-UNAME

    INTO wa_text_table-text SEPARATED BY SPACE.

    "wa_text_table-text = 'Enclosed is the bill &12345& Dated of amount &1245& raised to against Dispatch From &Plant Descrition '.

    append wa_text_table to text_table .

    loop at text_table .

    SET PROPERTY OF appitem 'Body' = wa_text_table-text.

    endloop.

    mail_index = 1.

    "We are now adding our attachments.

    data : wa_itab_path like line of itab_paths.

    • wa_itab_path-path = w_FULL_PATH."'G:\Documents and Settings\Akash\Desktop\BC415.pdf'.

    *APPEND wa_itab_path to itab_paths.

    LOOP AT ITAB_PATHS into wa_itab_path.

    CALL METHOD OF ATTACHS 'Add'

    EXPORTING

    #1 = wa_ITAB_PATH-PATH

    #2 = '1'

    #3 = MAIL_INDEX

    #4 = wa_ITAB_PATH-PATH.

    MAIL_INDEX = MAIL_INDEX + 1.

    ENDLOOP.

    CALL METHOD OF APPITEM 'Display'.

    FREE: ATTACHS, APPITEM, NAMESPACE, APPOUTLOOK."free ole objects.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 12, 2009 at 05:17 AM

    This message was moderated.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 13, 2009 at 08:37 AM

    This message was moderated.

    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.