cancel
Showing results for 
Search instead for 
Did you mean: 

Smartform output to be send via Email

Former Member
0 Kudos

Hi Guys,

I have a custom report and output generated by Smartform, currently it is printing on printer.

My requirement is to sent this output to customer via Email.(email and perferred communication details are available from customer master)

We have a output management server which will receive this output and convert into PDF format and distribute this output to customer.

I would like to know what are the possible changes require on driver program.

Appriciate your help.

Regards

Pravin

Edited by: Pravin on Apr 16, 2008 9:23 PM

Edited by: Pravin on Apr 16, 2008 9:25 PM

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi,

For sending the output of a smartform as amail you need to

follow the steps given below.

1.converting smartform to PDF

Summury: Converting the smartfrom to PDF is process of 3 simple steps.

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

2. Sending PDF as mail.

CLEAR t_receivers.

REFRESH t_receivers.

t_receivers-receiver = sy-uname.

t_receivers-rec_type = 'B'.

t_receivers-com_type = 'INT'.

t_receivers-notif_del = 'X'.

t_receivers-notif_ndel = 'X'.

APPEND t_receivers.

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.

check these links ,definitely useful

http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm

Regards,

Raj.

Former Member
0 Kudos

With reference to Pravin's issue, Venkat , can u tell me why is that my PDF attachment files are not openiong, giving an error as opening file . File damaged!

Former Member
0 Kudos

Hi,

You need to convert the output in PDF format and then you can send it as an attachment via mail.

You can also write the recepients name in field Recipient. This field you will find in where you assign the Logical destination to your Document number.

Rewar if useful.

Thanks

Swati.

venkat_o
Active Contributor
0 Kudos

Hi Pravin, Check the following sample program. Smartform driver program. It helps you how to convert smartform output as PDF using function module CONVERT_OTF. Once it is converted mail can be sent through function module SO_NEW_DOCUMENT_ATT_SEND_API1. Wherever u find MAI that should be mail.


REPORT  zvenkat_smartform_via_mai.
*&---------------------------------------------------------------------*
*&  Structures and Infotype Internal tables.
*&---------------------------------------------------------------------*
TABLES pernr.

INFOTYPES:
  0000,
  0001,
  0002,
  0006,
  0022,
  0023.

INCLUDE dbpnpmac.
*&---------------------------------------------------------------------*
*&  Declaration part
*&---------------------------------------------------------------------*
* Types
TYPES:
   BEGIN OF t_emp_info,
     pernr TYPE pa0001-pernr,
     ename TYPE pa0001-ename,
     bukrs TYPE pa0001-bukrs,
     persk TYPE pa0001-persk,
     stell TYPE pa0001-stell,
     gblnd TYPE pa0002-gblnd,
   END OF t_emp_info,
   BEGIN OF t_mard,
     matnr TYPE mard-matnr,
     werks TYPE mard-werks,
     labst TYPE mard-labst,
     meins TYPE mara-meins,
   END OF t_mard.

* Work areas
DATA:
  w_emp_info TYPE t_emp_info.
* Internal tables
DATA:
  i_emp_info TYPE STANDARD TABLE OF t_emp_info,
  i_mard     TYPE STANDARD TABLE OF t_mard.
*--------------------------------------------------------*
"  Mai related declarations
*--------------------------------------------------------*
"Variables
DATA :
     g_sent_to_all   TYPE sonv-flag,
     g_tab_lines     TYPE i.
"Types
TYPES:
     t_document_data  TYPE  sodocchgi1,
     t_packing_list   TYPE  sopcklsti1,
     t_attachment     TYPE  solisti1,
     t_body_msg       TYPE  solisti1,
     t_receivers      TYPE  somlreci1,
     t_pdf            TYPE  tline.
"Workareas
DATA :
     w_document_data  TYPE  t_document_data,
     w_packing_list   TYPE  t_packing_list,
     w_attachment     TYPE  t_attachment,
     w_body_msg       TYPE  t_body_msg,
     w_receivers      TYPE  t_receivers,
     w_pdf            TYPE  t_pdf.
"Internal Tables
DATA :
     i_document_data  TYPE STANDARD TABLE OF t_document_data,
     i_packing_list   TYPE STANDARD TABLE OF t_packing_list,
     i_attachment     TYPE STANDARD TABLE OF t_attachment,
     i_body_msg       TYPE STANDARD TABLE OF t_body_msg,
     i_receivers      TYPE STANDARD TABLE OF t_receivers,
     i_pdf            TYPE STANDARD TABLE OF t_pdf.
PARAMETERS:
           p_mai_id(99) TYPE c.
*&---------------------------------------------------------------------*
*& Start-of-selection.
*&---------------------------------------------------------------------*

START-OF-SELECTION.

GET pernr.

  PERFORM get_data.
  PERFORM show_smartform.
*&---------------------------------------------------------------------*
*& End-of-selection.
*&---------------------------------------------------------------------*
END-OF-SELECTION.


*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
FORM get_data .

  rp-provide-from-last p0000 space pn-begda pn-endda.
  rp-provide-from-last p0001 space pn-begda pn-endda.
  rp-provide-from-last p0002 space pn-begda pn-endda.

  MOVE-CORRESPONDING: p0000 TO w_emp_info,
                      p0001 TO w_emp_info,
                      p0002 TO w_emp_info.


  SELECT matnr werks labst
  FROM mard
  INTO CORRESPONDING FIELDS OF TABLE i_mard.


ENDFORM.                    " get_data
*&---------------------------------------------------------------------*
*&      Form  show_smartform
*&---------------------------------------------------------------------*
FORM show_smartform .
  DATA :
    l_sform_name TYPE tdsfname,
    l_fm_name    TYPE rs38l_fnam.

  DATA :
        l_sf_control TYPE ssfctrlop,
        l_sf_options TYPE ssfcompop.


  DATA: i_otf LIKE itcoo OCCURS 100 WITH HEADER LINE.
*        i_pdf LIKE tline OCCURS 100 WITH HEADER LINE.

  DATA: op_option TYPE ssfctrlop,
        job_output TYPE ssfcrescl.

*  op_option-getotf = 'X'.

  l_sform_name = 'ZVENKAT_SMARTFORM'.
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = l_sform_name
    IMPORTING
      fm_name            = l_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.
  ELSE.

    CALL FUNCTION l_fm_name
      EXPORTING
        control_parameters = op_option
        output_options     = l_sf_options
        w_emp_info         = w_emp_info
 IMPORTING
*   DOCUMENT_OUTPUT_INFO       =
   job_output_info            = job_output
      TABLES
        p0006              = p0006
        p0022              = p0022
        p0023              = p0023
        i_mard             = i_mard.
    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 FUNCTION 'CONVERT_OTF'
      EXPORTING
        format = 'PDF'
      TABLES
        otf    = job_output-otfdata
        lines  = i_pdf.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.


    PERFORM send_mai.

  ENDIF.
ENDFORM.                    " show_smartform
*&---------------------------------------------------------------------*
*&      Form  send_mai
*&---------------------------------------------------------------------*
FORM send_mail .
  "Subject of the mai.
  w_document_data-obj_name  = 'MAI_TO_HEAD'.
  w_document_data-obj_descr = 'Regarding Mai Program by SAP ABAP'.

  "Body of the mai
  PERFORM build_body_of_mai
    USING:space,
          'Hi,',
          'I am fine. How are you? How are you doing ? ',
          'This program has been created to send simple mai',
          'with Subject,Body with Address of the sender. ',
          'Regards,',
          'Venkat.O,',
          'SAP HR Technical Consultant.'.

  "Write Packing List for Body
  DESCRIBE TABLE i_body_msg LINES g_tab_lines.
  w_packing_list-head_start = 1.
  w_packing_list-head_num   = 0.
  w_packing_list-body_start = 1.
  w_packing_list-body_num   = g_tab_lines.
  w_packing_list-doc_type   = 'RAW'.
  APPEND w_packing_list TO i_packing_list.
  CLEAR  w_packing_list.

  "Write Packing List for Attachment
  w_packing_list-transf_bin = 'X'.
  w_packing_list-head_start = 1.
  w_packing_list-head_num   = 1.
  w_packing_list-body_start = 1.
  DESCRIBE TABLE i_attachment LINES w_packing_list-body_num.
  w_packing_list-doc_type   = 'PDF'.
  w_packing_list-obj_descr  = 'PDF Attachment'.
  w_packing_list-obj_name   = 'PDF_ATTACHMENT'.
  w_packing_list-doc_size   = w_packing_list-body_num * 255.
  APPEND w_packing_list TO i_packing_list.
  CLEAR  w_packing_list.

  "Fill the document data and get size of attachment
  w_document_data-obj_langu  = sy-langu.
  READ TABLE i_attachment INTO w_attachment INDEX g_tab_lines.
  w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( w_attachment ).

  "Receivers List.
  w_receivers-rec_type   = 'U'.      "Internet address
  w_receivers-receiver   = p_mai_id. "here mai Id should be given
  w_receivers-com_type   = 'INT'.
  w_receivers-notif_del  = 'X'.
  w_receivers-notif_ndel = 'X'.
  APPEND w_receivers TO i_receivers .
  CLEAR:w_receivers.

  "Function module to send mai to Recipients
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = w_document_data
      put_in_outbox              = 'X'
      commit_work                = 'X'
    IMPORTING
      sent_to_all                = g_sent_to_all
    TABLES
      packing_list               = i_packing_list
      contents_bin               = i_attachment
      contents_txt               = i_body_msg
      receivers                  = i_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 .
    MESSAGE i303(me) WITH 'Mai has been Successfully Sent.'.
  ELSE.
    WAIT UP TO 2 SECONDS.
    "This program starts the SAPconnect send process.
    SUBMIT rsconn01 WITH mode = 'INT'
                    WITH output = 'X'
                    AND RETURN.
  ENDIF.


ENDFORM.                    " send_mai
*&---------------------------------------------------------------------*
*&      Form  build_body_of_mai
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->L_MESSAGE  text
*----------------------------------------------------------------------*
FORM build_body_of_mai  USING l_message.

  w_body_msg = l_message.
  APPEND w_body_msg TO i_body_msg.
  CLEAR  w_body_msg.

ENDFORM.                    " build_body_of_mai
I hope that it helps u . Regards, Venkat.O

Former Member
0 Kudos

If u want to dispaly output into pdf format use conver_otf_2_pdf Fm which will convert other text format 2 pdf