Skip to Content
avatar image
Former Member

Smartform PDF sending as email

Hi,

I had a requirement like sending smartform o/p as PDF to multiple email-id's.

I had used the FM's CONVERT_OTF and SO_NEW_DOCUMENT_ATT_SEND_API1 Function module's.

Now I am able to receive the emails but unable to open the PDF document It is saying that the PDF was not decoded properly. Kindly help me out. I had also tried it using the GUI_DOWNLOAD after the CONVERT_OTF Function module. and was able to open the PDF format.

Kindly help me out.

Thanks & Regards,

Sridhar.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Nov 27, 2007 at 04:32 PM

    Hi

    i had teh same problem. i used this fm SX_OBJECT_CONVERT_OTF_PDF for convert to OTF from PDF format

    Look this problem opening pdf file

    Regards

    Gregory

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi,

      I am receivng the email but unable to open the PDF attachement in email.

      I am using the AFS system here i.e Apparel Footwear system, in which i am able to see the different parameteres for the FM's CONVERT TO OTF TO PDF and SX_OBJECT_CONVERT_OTF_PD not the ones you had send me in ur email.

      I am also sending my code below.

      CALL FUNCTION g_fnam

      EXPORTING

      archive_index = toa_dara

      • ARCHIVE_INDEX_TAB =

      archive_parameters = arc_params

      control_parameters = ls_control_param "Smart Forms: Control structure

      • MAIL_APPL_OBJ =

      mail_recipient = ls_recipient "Recipient Object ID

      mail_sender = ls_sender "Sender Object ID

      output_options = ls_composer_param "Smart Forms: Composer structure

      user_settings = ' '

      g_ship_to = g_ship_to "SHIP-TO

      g_bill_to = g_bill_to "BILL-TO

      wa_vbrk = wa_vbrk "Billing Document: Header Data

      wa_adrc1 = wa_adrc1

      wa_adrc2 = wa_adrc2

      wa_vttk = wa_vttk "Shipment Header

      wa_likp = wa_likp "SD Document: Delivery Header Data

      g_name1 = g_name1 "NAME1

      g_country = g_country

      g_country1 = g_country1 "COUNTRY NAME

      g_country2 = g_country2

      *--->Start of changes by srperuma on 22nd november 2007 0007

      IMPORTING

      • DOCUMENT_OUTPUT_INFO =

      job_output_info = wa_return

      *--->End of changes by srperuma on 22nd november 2007 0007.

      • JOB_OUTPUT_OPTIONS =

      EXCEPTIONS

      formatting_error = 1

      internal_error = 2

      send_error = 3

      user_canceled = 4

      OTHERS = 5

      .

      *--->Start of changes by srperuma on 22nd november 2007 0007.

      REFRESH t_otf[].

      t_otf[] = wa_return-otfdata[].

      CALL FUNCTION 'CONVERT_OTF'

      EXPORTING

      format = 'PDF'

      max_linewidth = 132

      • ARCHIVE_INDEX = ' '

      • COPYNUMBER = 0

      • ASCII_BIDI_VIS2LOG = ' '

      • PDF_DELETE_OTFTAB = ' '

      IMPORTING

      bin_filesize = v_len_in

      • BIN_FILE =

      TABLES

      otf = t_otf

      lines = t_tline

      EXCEPTIONS

      err_max_linewidth = 1

      err_format = 2

      err_conv_not_possible = 3

      err_bad_otf = 4

      OTHERS = 5.

      IF sy-subrc <> 0.

      • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

      • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

      ENDIF.

      • DATA : file_size TYPE i.

      *

      • CALL FUNCTION 'GUI_DOWNLOAD'

      • EXPORTING

      • bin_filesize = v_len_in

      • filename = 'C:\Documents and Settings\srperuma\Desktop\test.pdf'

      • filetype = 'BIN'

      • APPEND = ' '

      • WRITE_FIELD_SEPARATOR = ' '

      • HEADER = '00'

      • TRUNC_TRAILING_BLANKS = ' '

      • WRITE_LF = 'X'

      • COL_SELECT = ' '

      • COL_SELECT_MASK = ' '

      • DAT_MODE = ' '

      • CONFIRM_OVERWRITE = ' '

      • NO_AUTH_CHECK = ' '

      • CODEPAGE = ' '

      • IGNORE_CERR = ABAP_TRUE

      • REPLACEMENT = '#'

      • WRITE_BOM = ' '

      • TRUNC_TRAILING_BLANKS_EOL = 'X'

      • WK1_N_FORMAT = ' '

      • WK1_N_SIZE = ' '

      • WK1_T_FORMAT = ' '

      • WK1_T_SIZE = ' '

      • WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE

    • IMPORTING

    • filelength = file_size

    • TABLES

    • data_tab = t_tline[]

      • FIELDNAMES =

    • 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.

    • *

      • IF sy-subrc <> 0.

      • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

      • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    • ENDIF.

    • LOOP AT t_tline.

      TRANSLATE t_tline USING ' ~'.

      CONCATENATE wa_buffer t_tline INTO wa_buffer.

      ENDLOOP.

      TRANSLATE wa_buffer USING '~ '.

      DO.

      t_record = wa_buffer.

      APPEND t_record.

      SHIFT wa_buffer LEFT BY 255 PLACES.

      IF wa_buffer IS INITIAL.

      EXIT.

      ENDIF.

      ENDDO.

      REFRESH : t_reclist[],

      t_objtxt[],

      t_objbin[],

      t_objpack[].

      CLEAR : wa_objhead.

      t_objbin[] = t_record[].

      *Create message body title and description

      • t_objtxt = 'Test with pdf-attachment'.

      • APPEND t_objtxt.

      DESCRIBE TABLE t_objbin LINES v_lines_bin.

      • DESCRIBE TABLE t_objtxt LINES v_lines_txt.

      • READ TABLE t_objtxt INDEX v_lines_txt.

      *Fill the document data.

      wa_doc_chng-obj_langu = sy-langu.

      wa_doc_chng-expiry_dat = sy-datum + 10.

      wa_doc_chng-obj_name = 'EMAIL'.

      wa_doc_chng-obj_descr = 'TEST'.

      wa_doc_chng-sensitivty = 'F'.

      wa_doc_chng-doc_size = v_lines_txt * 255.

      *Main Text

      CLEAR : t_objpack-transf_bin.

      t_objpack-head_start = 1.

      t_objpack-head_num = 0.

      t_objpack-body_start = 1.

      t_objpack-body_num = v_lines_txt.

      t_objpack-doc_type = 'RAW'.

      APPEND t_objpack.

      CLEAR : t_objpack.

      • READ TABLE t_objbin INDEX v_lines_bin.

      *Pdf attachment.

      t_objpack-transf_bin = 'X'.

      t_objpack-head_start = 1.

      t_objpack-head_num = 1.

      t_objpack-body_start = 1.

      t_objpack-body_num = v_lines_bin.

      t_objpack-doc_type = 'PDF'.

      t_objpack-obj_name = 'EMAIL'.

      t_objpack-obj_descr = 'TEST'.

      t_objpack-doc_size = v_lines_bin * 255.

      t_objpack-obj_langu = sy-langu.

      APPEND t_objpack.

      CLEAR : t_objpack.

      LOOP AT t_emails.

      t_reclist-receiver = t_emails-smtp_addr. "'sriperum@in.ibm.com'.

      t_reclist-express = 'X'.

      t_reclist-rec_type = 'U'.

      • t_reclist-com_type = 'INT'.

      • t_reclist-notif_del = 'X'.

      • t_reclist-notif_ndel = 'X'.

      APPEND t_reclist.

      ENDLOOP.

      DATA : w_sent_all(1) TYPE c.

      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

      EXPORTING

      document_data = wa_doc_chng

      put_in_outbox = 'X'

      commit_work = 'X'

      • IMPORTING

      • sent_to_all = w_sent_all

      • NEW_OBJECT_ID =

      TABLES

      packing_list = t_objpack

      object_header = wa_objhead

      contents_bin = t_objbin

      • contents_txt = t_objtxt

      • CONTENTS_HEX =

      • OBJECT_PARA =

      • OBJECT_PARB =

      receivers = t_reclist

      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.

      COMMIT WORK.

      IF sy-subrc <> 0.

      • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

      • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

      ENDIF.

      *

  • avatar image
    Former Member
    Nov 27, 2007 at 01:24 PM

    Hi,

    Let me know your E-Mail Id. I will send the code across.It works perfectly fine.

    Regards,

    Krishna

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 28, 2007 at 05:24 AM

    Compare your part of code with the below given code.

    *&----


    *

    *& Report YSSN_SIMPLE_SMARTFORM *

    *& *

    *&----


    *

    *& *

    *& *

    *&----


    *

    report zhr_bhaskar_pdf_to_email message-id zmsg.

    parameters: p_vbeln type vbak-vbeln default '35'.

    data: it_items type table of vbap,

    v_fm_name type rs38l_fnam,

    v_tot_lines type i,

    v_sy_tabix type i,

    output_data type ssfcrescl. " To hold Output information

    constants:

    c_sep type c value '-', " Value -

    c_x type c value 'X', " Value X

    c_space type c value ' '. " Space

    *****MAIL START

    include .

    data: g_mail_rec_obj type swotobjid,

    g_mail_sen_obj type swotobjid,

    g_mail_app_obj type swotobjid,

    g_cont_par type ssfctrlop,

    folder type swc_object,

    begin of sofmfol_key,

    foldertype like sofm-foltp,

    folderyear like sofm-folyr,

    foldernumber like sofm-folno,

    type like sofm-doctp,

    year like sofm-docyr,

    number like sofm-docno,

    forwarder like soub-usrnam,

    end of sofmfol_key,

    bor_key like swotobjid-objkey,

    g_mail type so_name value 'madang@intelligroup.com',

    g_rectype type so_escape value 'U'. " 'B'.

    data: job_output_info type ssfcrescl,

    hotfdata like itcoo occurs 1 with header line,

    htline like tline occurs 1 with header line,

    x_objcont like soli occurs 1 with header line,

    ld_packing_list like soxpl occurs 1 with header line,

    x_object_hd_change like sood1 occurs 1 with header line,

    x_objhead like soli occurs 1 with header line,

    x_receivers like soos1 occurs 1 with header line,

    format_pdf(10) value 'PDF',

    doc_size(12) type c,

    hltlines type i,

    htabix like sy-tabix,

    fle1(2) type p,

    fle2(2) type p,

    off1 type p,

    hfeld(500) type c.

    tables: soud.

    *****MAIL END

    select *

    into table it_items

    from vbap

    where vbeln = p_vbeln.

    if it_items[] is initial.

    exit.

    endif.

    perform call_smartform.

    *&----


    *

    *& Form call_smartform

    *&----


    *

    • text

    *----


    *

    • --> p1 text

    • <-- p2 text

    *----


    *

    form call_smartform .

    *DATA: lx_control_parameters TYPE SSFCTRLOP,

    • lx_OUTPUT_OPTIONS type SSFCOMPOP.

    • lx_OUTPUT_OPTIONS-TDIMMED = ' '.

    • lx_OUTPUT_OPTIONS-TDfinal = 'X'.

    • lx_OUTPUT_OPTIONS-TDDELETE = 'X'.

    • lx_CONTROL_PARAMETERS-NO_CLOSE = 'X'.

    • lx_CONTROL_PARAMETERS-NO_OPEN = ' '.

    data: x_ssfcompop type ssfcompop,

    x_ssfctrlop like ssfctrlop,

    x_ssfcrescl type ssfcrescl.

    **MAIL

    g_cont_par-langu = sy-langu.

    g_cont_par-no_dialog = 'X'.

    g_cont_par-getotf = 'X'.

    g_cont_par-device = 'MAIL'.

    • Get BOR-Objects for Recipient, Sender und Applikation

    perform mail_recipient_object changing g_mail_rec_obj.

    perform mail_sender_object changing g_mail_sen_obj.

    perform mail_appl_object changing g_mail_app_obj.

    **MAIL

    *--Internal table is having more than 1 record

    if v_tot_lines gt 1.

    if v_sy_tabix = 1.

    *--For first record of table

    x_ssfctrlop-no_open = c_space.

    x_ssfctrlop-no_close = c_x.

    elseif v_sy_tabix = v_tot_lines.

    *--For last record of table

    x_ssfctrlop-no_open = c_x.

    x_ssfctrlop-no_close = c_space.

    else.

    x_ssfctrlop-no_open = c_x.

    x_ssfctrlop-no_close = c_x.

    endif.

    endif.

    • IF r_previ = c_x.

    x_ssfctrlop-preview = c_x.

    x_ssfctrlop-getotf = c_x.

    • ENDIF.

    call function 'SSF_FUNCTION_MODULE_NAME'

    exporting

    formname = 'YSSN_SMARTFORM'

    • VARIANT = ' '

    • DIRECT_CALL = ' '

    importing

    fm_name = v_fm_name

    • EXCEPTIONS

    • NO_FORM = 1

    • NO_FUNCTION_MODULE = 2

    • OTHERS = 3

    .

    if sy-subrc <> 0.

    message i000 with 'Smart form module name failure'.

    exit.

    endif.

    • CALL FUNCTION '/1BCDWB/SF00000199'

    call function v_fm_name

    exporting

    • ARCHIVE_INDEX =

    • ARCHIVE_INDEX_TAB =

    • ARCHIVE_PARAMETERS =

    control_parameters = g_cont_par

    mail_appl_obj = g_mail_app_obj

    mail_recipient = g_mail_rec_obj

    mail_sender = g_mail_sen_obj

    • OUTPUT_OPTIONS = lx_OUTPUT_OPTIONS

    • USER_SETTINGS = 'X'

    t_vbap = it_items

    • IMPORTING

    • DOCUMENT_OUTPUT_INFO =

    job_output_info = job_output_info

    • JOB_OUTPUT_OPTIONS =

    • EXCEPTIONS

    • FORMATTING_ERROR = 1

    • INTERNAL_ERROR = 2

    • SEND_ERROR = 3

    • USER_CANCELED = 4

    • OTHERS = 5

    .

    perform send_pdf_mail.

    endform. " call_smartform

    *&----


    *

    *& Form send_pdf_mail

    *&----


    *

    • text

    *----


    *

    • --> p1 text

    • <-- p2 text

    *----


    *

    form send_pdf_mail .

    data ld_binfile type xstring.

    • pdf_table type rcl_bag_tline,

    data: ld_originator like soos1-recextnam.

    • convert form

    loop at job_output_info-otfdata into hotfdata.

    append hotfdata.

    endloop.

    call function 'CONVERT_OTF'

    exporting

    format = format_pdf

    max_linewidth = 132

    importing

    bin_filesize = doc_size

    bin_file = ld_binfile

    tables

    otf = output_data-otfdata

    lines = htline

    exceptions

    err_max_linewidth = 1

    err_format = 2

    err_conv_not_possible = 3

    others = 4.

    *-Itab 134 Zeichen nach 255 Zeichen überführen

    describe table htline lines hltlines.

    describe field htline length fle1 in character mode.

    describe field x_objcont length fle2 in character mode.

    loop at htline.

    htabix = sy-tabix.

    move htline to hfeld+off1.

    if htabix = hltlines.

    fle1 = strlen( htline ).

    endif.

    off1 = off1 + fle1.

    if off1 ge fle2.

    clear x_objcont.

    x_objcont = hfeld(fle2).

    append x_objcont.

    shift hfeld by fle2 places.

    off1 = off1 - fle2.

    endif.

    if htabix = hltlines.

    if off1 gt 0.

    clear x_objcont.

    x_objcont = hfeld(off1).

    append x_objcont.

    endif.

    endif.

    endloop.

    x_object_hd_change-objnam = 'EMAIL'.

    x_object_hd_change-objdes = 'Smart Form'.

    x_object_hd_change-objla = sy-langu.

    x_object_hd_change-objsns = 'O'.

    x_object_hd_change-objlen = doc_size.

    x_object_hd_change-file_ext = 'TXT'.

    ld_packing_list-transf_bin = 'X'.

    ld_packing_list-head_start = 1.

    ld_packing_list-head_num = 0.

    ld_packing_list-body_start = 1.

    describe table x_objcont lines ld_packing_list-body_num.

    ld_packing_list-objtp = 'EXT'.

    ld_packing_list-objdes = 'Smart Form'.

    ld_packing_list-objla = sy-langu.

    ld_packing_list-objlen = doc_size.

    ld_packing_list-file_ext = 'PDF'.

    append ld_packing_list.

    x_receivers-recextnam = g_mail.

    x_receivers-recesc = 'E'.

    x_receivers-sndart = 'INT'.

    append x_receivers.

    ld_originator = 'sampathc@intelligroup.com'.

    • ld_originator = FSABE-USRNAM.

    call function 'SO_OBJECT_SEND'

    exporting

    object_hd_change = x_object_hd_change

    object_type = 'RAW'

    originator_type = 'B' "Einfügen

    originator = ld_originator "Einfügen

    tables

    • objcont = ld_text

    receivers = x_receivers

    packing_list = ld_packing_list

    att_cont = x_objcont

    att_head = x_objhead

    exceptions

    active_user_not_exist = 1

    communication_failure = 2

    component_not_available = 3

    folder_not_exist = 4

    folder_no_authorization = 5

    forwarder_not_exist = 6

    note_not_exist = 7

    object_not_exist = 8

    object_not_sent = 9

    object_no_authorization = 10

    object_type_not_exist = 11

    operation_no_authorization = 12

    owner_not_exist = 13

    parameter_error = 14

    substitute_not_active = 15

    substitute_not_defined = 16

    system_failure = 17

    too_much_receivers = 18

    user_not_exist = 19

    x_error = 20

    others = 21.

    endform. " send_pdf_mail

    *&----


    *

    *& Form mail_sender_object

    *&----


    *

    • text

    *----


    *

    • <--P_G_MAIL_SEN_OBJ text

    *----


    *

    form mail_sender_object changing p_mail_sen_obj.

    call function 'CREATE_SENDER_OBJECT_PPF'

    exporting

    ip_sender = sy-uname

    importing

    ep_sender_id = p_mail_sen_obj

    exceptions

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

    endform. " mail_sender_object

    *&----


    *

    *& Form mail_appl_object

    *&----


    *

    • text

    *----


    *

    • <--P_G_MAIL_APP_OBJ text

    *----


    *

    form mail_appl_object changing p_mail_app_obj.

    • SELECT * FROM soud WHERE sapnam LIKE sy-uname AND deleted = ' '.

    • ENDSELECT.

    • IF sy-subrc NE 0.

    call function 'SO_USER_AUTOMATIC_INSERT'

    exporting

    sapname = sy-uname

    exceptions

    no_insert = 1

    sap_name_exist = 2

    x_error = 3

    others = 4.

    if sy-subrc ne 0.

    clear soud.

    else.

    select * from soud where sapnam like sy-uname and deleted = ' '.

    endselect.

    endif.

    • ENDIF.

    clear sofmfol_key.

    sofmfol_key-type = 'FOL'.

    sofmfol_key-year = soud-inbyr.

    sofmfol_key-number = soud-inbno.

    bor_key = sofmfol_key.

    if not bor_key is initial.

    swc_create_object folder 'SOFMFOL' bor_key.

    if sy-subrc = 0.

    swc_object_to_persistent folder p_mail_app_obj.

    if sy-subrc ne 0.

    clear p_mail_app_obj.

    endif.

    endif.

    else.

    clear p_mail_app_obj.

    endif.

    endform. " mail_appl_object

    *&----


    *

    *& Form mail_recipient_object

    *&----


    *

    • text

    *----


    *

    • <--P_G_MAIL_REC_OBJ text

    *----


    *

    form mail_recipient_object changing p_mail_rec_obj.

    call function 'CREATE_RECIPIENT_OBJ_PPF'

    exporting

    • IP_COUNTRY =

    • IP_FAXNO =

    ip_mailaddr = g_mail

    ip_type_id = g_rectype " 'U'

    importing

    ep_recipient_id = p_mail_rec_obj

    • EP_ADDRESS =

    • ET_RECIPIENT =

    exceptions

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

    endform. " mail_recipient_object

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      HI SIR,

      i copied to ur code in my prog now i getting the error message is "

      Element NO_COMMTYPE_CHECK is not available in th

      container ".

      plz help me what is the problem.

      thanking u,