cancel
Showing results for 
Search instead for 
Did you mean: 

How to print and mail smartform automatically when hit enter

Former Member
0 Kudos

Hi Friends,

Iam looping the internal table and iam calling the smartfrom function module in the loop.

iam taking those records into a temperary table

when a particular condition is met with in the loop my smartfrom will trigger, as iam collecting those records in a temporay table when smartfrom triggered i will pass those records which are there in the tempary table to smartform..

now my problem here is when user hit execute button he should get here 2 functionalities ie: it should automatically send mail and automatically it should print the form.

iam able to supress the diolouge which will come in between using control parameters option... But how should i get both the above functionalities when user hits enter button...

Can any one suggest me...?

Regards

Kumar

Accepted Solutions (1)

Accepted Solutions (1)

venkat_o
Active Contributor
0 Kudos

Hi Kumar, Steps to achieve your requirement. <li>You need to loop your internal table two times. <li>.In first loop,call smartform and print without dialogue. <li> in second loop, call smartform to get OTF data->Convert OTF data to PDF using CONVERT_OTF ->Once pdf is ready send mail with pdf attachment using SO_NEW_DOCUMENT_ATT_SEND_API1. <li>Sample program which i tried successfully.


REPORT  ztest_smartform.
DATA:it_nfal            TYPE nfal       OCCURS 0 WITH HEADER LINE.
DATA:it_nfal_final      TYPE nfal       OCCURS 0 WITH HEADER LINE.
DATA:fm_name            TYPE rs38l_fnam.
DATA:wa_control_par     TYPE ssfctrlop.
DATA:wa_output_options  TYPE ssfcompop.
DATA:flag               TYPE c.
DATA:no_of_records      TYPE i.
DATA:it_otf_data        TYPE ssfcrescl.
DATA:it_otf_final       TYPE itcoo OCCURS 0 WITH HEADER LINE.
DATA:bin_filesize       TYPE i.
DATA:it_pdfdata         TYPE TABLE OF tline.
DATA:it_pdf             TYPE TABLE OF solisti1.
DATA :g_sent_to_all     TYPE sonv-flag.
DATA :g_tab_lines       TYPE i.
DATA :i_document_data   TYPE STANDARD TABLE OF sodocchgi1,
      i_packing_list    TYPE STANDARD TABLE OF sopcklsti1,
      i_attachment      TYPE STANDARD TABLE OF solisti1,
      i_body_msg        TYPE STANDARD TABLE OF solisti1,
      i_receivers       TYPE STANDARD TABLE OF somlreci1,
      i_pdf             TYPE STANDARD TABLE OF tline,
      w_document_data   LIKE LINE OF i_document_data,
      w_packing_list    LIKE LINE OF i_packing_list,
      w_attachment      LIKE LINE OF i_attachment,
      w_body_msg        LIKE LINE OF i_body_msg,
      w_receivers       LIKE LINE OF i_receivers,
      w_pdf             LIKE LINE OF i_pdf.

START-OF-SELECTION.
  "select data
  SELECT * FROM nfal INTO TABLE      it_nfal UP TO 10 ROWS WHERE einri = 'CGH'.
  SELECT * FROM nfal APPENDING TABLE it_nfal UP TO 10 ROWS WHERE einri = 'SGH'.
  SELECT * FROM nfal APPENDING TABLE it_nfal UP TO 10 ROWS WHERE einri = 'KKH'.
  SORT it_nfal BY einri.
  DESCRIBE TABLE it_nfal LINES no_of_records.
<b>Code Continues---</b>

Answers (4)

Answers (4)

venkat_o
Active Contributor
0 Kudos

<li> From above code

*&---------------------------------------------------------------------*
*&      Form  SEND_MAIL
*&---------------------------------------------------------------------*
FORM send_mail .
  "Subject of the mail.
  w_document_data-obj_name  = 'MAIL_TO_HEAD'.
  w_document_data-obj_descr = 'Regarding Mail Program by SAP ABAP'.
  "Body of the mail
  w_body_msg = 'This is body of mail msg.'.
  APPEND w_body_msg TO i_body_msg.
  CLEAR  w_body_msg.
  "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 it_pdf 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 it_pdf INTO w_pdf INDEX g_tab_lines.
  w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( w_attachment ).
  "Receivers List.
  w_receivers-rec_type   = 'B'."Internet address
  w_receivers-receiver   = 'IBMVENKAT'.
  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 mail 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               = it_pdf
      contents_txt               = i_body_msg
      receivers                  = i_receivers.
  IF sy-subrc = 0 .
    MESSAGE i303(me) WITH 'Mail has been Successfully Sent.'.
  ENDIF.
ENDFORM.                    " SEND_MAIL

venkat_o
Active Contributor
0 Kudos

<li>from above code

  "This loop prints the data
  LOOP AT it_nfal.
    AT FIRST.
      "Get Function module name for given smartform
      CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
        EXPORTING
          formname = 'ZTEST_SMARTFORM'
        IMPORTING
          fm_name  = fm_name.
    ENDAT.
    APPEND it_nfal TO it_nfal_final.
    AT END OF einri.
      wa_control_par-no_dialog = 'X'.   "It supresses the Printer dialog.
      wa_output_options-tddest = 'LOCL'."Set printer
      "Call Smartform function module.
      CALL FUNCTION fm_name
        EXPORTING
          control_parameters = wa_control_par
          output_options     = wa_output_options
        TABLES
          it_nfal            = it_nfal_final.
      CLEAR it_nfal_final[].
    ENDAT.
  ENDLOOP.
  CLEAR :wa_control_par,wa_output_options.
  "This loop converts otf data to pdf and sends mail
  LOOP AT it_nfal.
    AT FIRST.
      "Get Function module name for given smartform
      CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
        EXPORTING
          formname = 'ZTEST_SMARTFORM'
        IMPORTING
          fm_name  = fm_name.
    ENDAT.
    APPEND it_nfal TO it_nfal_final.
    AT END OF einri.
      wa_control_par-getotf    = 'X'.   "Set this to get OTF data
      wa_control_par-no_dialog = 'X'.   "It supresses the Printer dialog.
      wa_output_options-tddest = 'LOCL'."Set printer
      "Call Smartform function module.
      CALL FUNCTION fm_name
        EXPORTING
          control_parameters = wa_control_par
          output_options     = wa_output_options
        IMPORTING
          job_output_info    = it_otf_data
        TABLES
          it_nfal            = it_nfal_final.
      "Getting OTF data
      APPEND LINES OF it_otf_data-otfdata[] TO it_otf_final[].
      CLEAR it_nfal_final[].
    ENDAT.
    AT LAST.
      CALL FUNCTION 'CONVERT_OTF'
        EXPORTING
          format       = 'PDF'
        IMPORTING
          bin_filesize = bin_filesize
        TABLES
          otf          = it_otf_final
          lines        = it_pdfdata[].
      CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
        EXPORTING
          line_width_dst = '255'
        TABLES
          content_in     = it_pdfdata[]
          content_out    = it_pdf[].
      IF sy-subrc = 0.
        "Send mail
        PERFORM send_mail.
      ENDIF.
    ENDAT.
  ENDLOOP.

Andri
Explorer
0 Kudos

Hi,

Since you can not print both SmartForm and retrieve the binary data, you will need to get the binary data save it as pdf for emailing, and send the binary to the spool your self.

best regards,

Andri

Former Member
0 Kudos

Hi,

Use func module CONVERT_OTF_2_PDF to convert your smartforms into a PDF and use the func module: SO_NEW_DOCUMENT_ATT_SEND_API1 to send the email.

Regards,

Subramanian