Skip to Content
avatar image
Former Member

How to mail smartform?

Hello everybody,

I have developed a smartform which now needs to be converted into PDF format and also needs to be mailed.

I have gone thru docs and threads already posted, but could not arrive at the right solution .

Will be thankful if any body helps me out in solving this issue.

Helpful answers will surely be rewarded.

thankx in advance,

Sanghamitra.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Aug 18, 2007 at 10:03 PM

    HI ,

    <b>Converting the smartfrom to PDF </b>

    • Calling the Smart form, then it returns the OTF data in Return.

    • Converting the OTF data into required format using the Function Module CONVERT_OTF_2_PDF.

    • Download the File

    &----


    *& Report ZTEST_NREDDY_PDF

    *&

    &----


    *&

    *&

    &----


    REPORT ZTEST_NREDDY_PDF.

    DATA: it_otf TYPE STANDARD TABLE OF itcoo,

    it_docs TYPE STANDARD TABLE OF docs,

    it_lines TYPE STANDARD TABLE OF tline,

    st_job_output_info TYPE ssfcrescl,

    st_document_output_info TYPE ssfcrespd,

    st_job_output_options TYPE ssfcresop,

    st_output_options TYPE ssfcompop,

    st_control_parameters TYPE ssfctrlop,

    v_len_in TYPE so_obj_len,

    v_language TYPE sflangu VALUE 'E',

    v_e_devtype TYPE rspoptype,

    v_bin_filesize TYPE i,

    v_name TYPE string,

    v_path TYPE string,

    v_fullpath TYPE string,

    v_filter TYPE string,

    v_uact TYPE i,

    v_guiobj TYPE REF TO cl_gui_frontend_services,

    v_filename TYPE string,

    v_fm_name TYPE rs38l_fnam.

    CONSTANTS c_formname TYPE tdsfname VALUE 'ZTEST'.

    CALL FUNCTION 'SSF_GET_DEVICE_TYPE'

    EXPORTING

    i_language = v_language

    i_application = 'SAPDEFAULT'

    IMPORTING

    e_devtype = v_e_devtype.

    st_output_options-tdprinter = v_e_devtype.

    *st_output_options-tdprinter = 'locl'.

    st_control_parameters-no_dialog = 'X'.

    st_control_parameters-getotf = 'X'.

    .................GET SMARTFORM FUNCTION MODULE NAME.................

    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

    EXPORTING

    formname = c_formname

    IMPORTING

    fm_name = v_fm_name

    EXCEPTIONS

    no_form = 1

    no_function_module = 2

    OTHERS = 3.

    IF sy-subrc <> 0.

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

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

    ENDIF.

    ...........................CALL SMARTFORM............................

    CALL FUNCTION v_fm_name

    EXPORTING

    control_parameters = st_control_parameters

    output_options = st_output_options

    IMPORTING

    document_output_info = st_document_output_info

    job_output_info = st_job_output_info

    job_output_options = st_job_output_options

    EXCEPTIONS

    formatting_error = 1

    internal_error = 2

    send_error = 3

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

    ELSE.

    .........................CONVERT TO OTF TO PDF.......................

    CALL FUNCTION 'CONVERT_OTF_2_PDF'

    IMPORTING

    bin_filesize = v_bin_filesize

    TABLES

    otf = st_job_output_info-otfdata

    doctab_archive = it_docs

    lines = it_lines

    EXCEPTIONS

    err_conv_not_possible = 1

    err_otf_mc_noendmarker = 2

    OTHERS = 3.

    IF sy-subrc <> 0.

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

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

    ENDIF.

    ........................GET THE FILE NAME TO STORE....................

    CONCATENATE 'smrt' '.pdf' INTO v_name.

    CREATE OBJECT v_guiobj.

    CALL METHOD v_guiobj->file_save_dialog

    EXPORTING

    default_extension = 'pdf'

    default_file_name = v_name

    file_filter = v_filter

    CHANGING

    filename = v_name

    path = v_path

    fullpath = v_fullpath

    user_action = v_uact.

    IF v_uact = v_guiobj->action_cancel.

    EXIT.

    ENDIF.

    ..................................DOWNLOAD AS FILE....................

    MOVE v_fullpath TO v_filename.

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    bin_filesize = v_bin_filesize

    filename = v_filename

    filetype = 'BIN'

    TABLES

    data_tab = it_lines

    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.

    ENDIF.

    <b>Mail the SF: </b>

    Here is the code to send the Smartform to mail as PDF attachment.

    • &---------------------------------------------------------------------

    *& Report ZTEST_NREDDY_PDF_MAIL

    *&

    &----


    REPORT ZTEST_NREDDY_PDF_MAIL.

    • Internal Table declarations

    DATA: I_OTF TYPE ITCOO OCCURS 0 WITH HEADER LINE,

    I_TLINE TYPE TABLE OF TLINE WITH HEADER LINE,

    I_RECEIVERS TYPE TABLE OF SOMLRECI1 WITH HEADER LINE,

    I_RECORD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

    • Objects to send mail.

    I_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

    I_OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

    I_OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

    I_RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,

    • Work Area declarations

    WA_OBJHEAD TYPE SOLI_TAB,

    W_CTRLOP TYPE SSFCTRLOP,

    W_COMPOP TYPE SSFCOMPOP,

    W_RETURN TYPE SSFCRESCL,

    WA_DOC_CHNG TYPE SODOCCHGI1,

    W_DATA TYPE SODOCCHGI1,

    WA_BUFFER TYPE STRING, "To convert from 132 to 255

    • Variables declarations

    V_FORM_NAME TYPE RS38L_FNAM,

    V_LEN_IN LIKE SOOD-OBJLEN,

    V_LEN_OUT LIKE SOOD-OBJLEN,

    V_LEN_OUTN TYPE I,

    V_LINES_TXT TYPE I,

    V_LINES_BIN TYPE I.

    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

    EXPORTING

    FORMNAME = 'ZTEST'

    IMPORTING

    FM_NAME = V_FORM_NAME

    EXCEPTIONS

    NO_FORM = 1

    NO_FUNCTION_MODULE = 2

    OTHERS = 3.

    IF SY-SUBRC <> 0.

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

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

    ENDIF.

    W_CTRLOP-GETOTF = 'X'.

    W_CTRLOP-NO_DIALOG = 'X'.

    W_COMPOP-TDNOPREV = 'X'.

    CALL FUNCTION V_FORM_NAME

    EXPORTING

    CONTROL_PARAMETERS = W_CTRLOP

    OUTPUT_OPTIONS = W_COMPOP

    USER_SETTINGS = 'X'

    IMPORTING

    JOB_OUTPUT_INFO = W_RETURN

    EXCEPTIONS

    FORMATTING_ERROR = 1

    INTERNAL_ERROR = 2

    SEND_ERROR = 3

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

    I_OTF[] = W_RETURN-OTFDATA[].

    CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

    FORMAT = 'PDF'

    MAX_LINEWIDTH = 132

    IMPORTING

    BIN_FILESIZE = V_LEN_IN

    TABLES

    OTF = I_OTF

    LINES = I_TLINE

    EXCEPTIONS

    ERR_MAX_LINEWIDTH = 1

    ERR_FORMAT = 2

    ERR_CONV_NOT_POSSIBLE = 3

    OTHERS = 4.

    IF SY-SUBRC <> 0.

    ENDIF.

    LOOP AT I_TLINE.

    TRANSLATE I_TLINE USING '~'.

    CONCATENATE WA_BUFFER I_TLINE INTO WA_BUFFER.

    ENDLOOP.

    TRANSLATE WA_BUFFER USING '~'.

    DO.

    I_RECORD = WA_BUFFER.

    APPEND I_RECORD.

    SHIFT WA_BUFFER LEFT BY 255 PLACES.

    IF WA_BUFFER IS INITIAL.

    EXIT.

    ENDIF.

    ENDDO.

    • Attachment

    REFRESH: I_RECLIST,

    I_OBJTXT,

    I_OBJBIN,

    I_OBJPACK.

    CLEAR WA_OBJHEAD.

    I_OBJBIN[] = I_RECORD[].

    • Create Message Body Title and Description

    I_OBJTXT = 'test with pdf-Attachment!'.

    APPEND I_OBJTXT.

    DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.

    READ TABLE I_OBJTXT INDEX V_LINES_TXT.

    WA_DOC_CHNG-OBJ_NAME = 'smartform'.

    WA_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.

    WA_DOC_CHNG-OBJ_DESCR = 'smartform'.

    WA_DOC_CHNG-SENSITIVTY = 'F'.

    WA_DOC_CHNG-DOC_SIZE = V_LINES_TXT * 255.

    • Main Text

    CLEAR I_OBJPACK-TRANSF_BIN.

    I_OBJPACK-HEAD_START = 1.

    I_OBJPACK-HEAD_NUM = 0.

    I_OBJPACK-BODY_START = 1.

    I_OBJPACK-BODY_NUM = V_LINES_TXT.

    I_OBJPACK-DOC_TYPE = 'RAW'.

    APPEND I_OBJPACK.

    • Attachment (pdf-Attachment)

    I_OBJPACK-TRANSF_BIN = 'X'.

    I_OBJPACK-HEAD_START = 1.

    I_OBJPACK-HEAD_NUM = 0.

    I_OBJPACK-BODY_START = 1.

    DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.

    READ TABLE I_OBJBIN INDEX V_LINES_BIN.

    I_OBJPACK-DOC_SIZE = V_LINES_BIN * 255 .

    I_OBJPACK-BODY_NUM = V_LINES_BIN.

    I_OBJPACK-DOC_TYPE = 'PDF'.

    I_OBJPACK-OBJ_NAME = 'smart'.

    I_OBJPACK-OBJ_DESCR = 'test'.

    APPEND I_OBJPACK.

    CLEAR I_RECLIST.

    I_RECLIST-RECEIVER = 'nareshreddy.k@gmail.com'.

    I_RECLIST-REC_TYPE = 'U'.

    APPEND I_RECLIST.

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    DOCUMENT_DATA = WA_DOC_CHNG

    PUT_IN_OUTBOX = 'X'

    COMMIT_WORK = 'X'

    TABLES

    PACKING_LIST = I_OBJPACK

    OBJECT_HEADER = WA_OBJHEAD

    CONTENTS_BIN = I_OBJBIN

    CONTENTS_TXT = I_OBJTXT

    RECEIVERS = I_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.

    IF SY-SUBRC <> 0.

    WRITE:/ 'Error When Sending the File', SY-SUBRC.

    ELSE.

    WRITE:/ 'Mail sent'.

    ENDIF.

    Regards,

    Murali

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thank u so much.

      But the problem is that it is working for COURIER font and is not working ARIAL.

      Any suggestion for this.

      Helpful answers will surely be rewarded.

      Regards,

      Sanghamitra.