cancel
Showing results for 
Search instead for 
Did you mean: 

Output thro simple mail concept

Former Member
0 Kudos

Hi

My requirement is sending invoice output to customer. I have option of sending thro' external send(5). But i am looking to use simple mail(5) concept. Can i use this. If i can use what is the program i need mentioned in the nace and also can i use smart form.

i had checked with my programmer, he had stdprogram RSNASTSO and form routine SAPOFFICE_AUFRUF_VX which is used to mail to SAP inbox , he tried to modify this program based on our requirement and add the smartform to it. we got the mail but the information in smartform did not come in the mail i.e program is not accessing the information.

Please let me know your input.

Thanks

sriram

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Sriram,

Please check the below code and take as referance


&----


*& Report ZTEST_EMAIL_SEND

*&

&----


*&for checking the mail has sent or not can be seen in tcode 'SOST'

*&

&----


REPORT ztest_email_send.

*CLASS-DEFINITIONS *

----


DATA: send_request TYPE REF TO cl_bcs.

DATA: document TYPE REF TO cl_document_bcs.

DATA: sender TYPE REF TO cl_sapuser_bcs.

DATA: recipient TYPE REF TO if_recipient_bcs.

DATA: exception_info TYPE REF TO if_os_exception_info,

bcs_exception TYPE REF TO cx_bcs.

----


  • INTERNAL TABLES *

----


DATA: l_mailtext TYPE soli_tab.

DATA: l_mailhex TYPE solix_tab.

DATA: iaddsmtp TYPE bapiadsmtp OCCURS 0 WITH HEADER LINE.

DATA: ireturn TYPE bapiret2 OCCURS 0 WITH HEADER LINE.

----


  • VARIABLES *

----


DATA: mail_line LIKE LINE OF l_mailtext.

DATA: mailx_line LIKE LINE OF l_mailhex.

DATA: bapiadsmtp TYPE bapiadsmtp.

----


  • CONSTANTS *

----


CONSTANTS:

kimball_domain(12) TYPE c VALUE '@kimball.com'.

CLASS cl_cam_address_bcs DEFINITION LOAD.

CLASS cl_abap_char_utilities DEFINITION LOAD.

DATA: control_parameters TYPE ssfctrlop,

output_options TYPE ssfcompop,

job_output_info TYPE ssfcrescl,

job_output_options TYPE ssfcresop,

otf_data TYPE tsfotf,

string_data TYPE xstring,

file_size TYPE i,

lines TYPE TABLE OF tline .

----


  • START-OF-SELECTION

----


START-OF-SELECTION.

*-- SMART FORM CODE

DATA: fm_name TYPE rs38l_fnam,

formname(30) TYPE c.

formname = 'ZTEST_SMART1'.

*--Calling smartform

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = formname

IMPORTING

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

control_parameters-no_dialog = 'X'.

control_parameters-getotf = 'X'.

control_parameters-device = 'PRINTER'.

job_output_options-tddest = 'LOC'.

*--Calling Function Module

CALL FUNCTION fm_name

EXPORTING

control_parameters = control_parameters

output_options = output_options

IMPORTING

job_output_info = job_output_info

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

ENDIF.

*--Convertion data OTF to ODF

otf_data[] = job_output_info-otfdata[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

  • MAX_LINEWIDTH = 132

  • ARCHIVE_INDEX = ' '

  • COPYNUMBER = 0

  • ASCII_BIDI_VIS2LOG = ' '

IMPORTING

bin_filesize = file_size

bin_file = string_data

TABLES

otf = otf_data[]

lines = lines

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

*--Using SOLIX Converting string data

DATA: lt_solix TYPE solix_tab.

CALL METHOD cl_document_bcs=>xstring_to_solix

EXPORTING

ip_xstring = string_data

RECEIVING

rt_solix = lt_solix.

*-- SMART FORM CODE

TRY.

*-- Create persistent send request

send_request = cl_bcs=>create_persistent( ).

DATA: first(1) TYPE c.

CLEAR first.

DATA: lt_text TYPE soli_tab.

DATA: ls_text TYPE soli.

ls_text-line = 'THIS IS TEST DATA'.

APPEND ls_text TO lt_text.

CLEAR ls_text.

ls_text-line = 'THIS IS TEST DATA'.

APPEND ls_text TO lt_text.

CLEAR ls_text.

document = cl_document_bcs=>create_document(

i_type = 'txt'

i_text = lt_text

i_subject = 'subject' ).

CALL METHOD document->add_attachment

EXPORTING

i_attachment_type = 'PDF'

i_attachment_subject = 'PDFDATA'

i_att_content_hex = lt_solix.

*--Add document to send request

CALL METHOD send_request->set_document( document ).

*-- Get sender object

sender = cl_sapuser_bcs=>create( sy-uname ).

*--Add sender

CALL METHOD send_request->set_sender

EXPORTING

i_sender = sender.

recipient = cl_cam_address_bcs=>create_internet_address( 'mail id').

*--Add recipient with its respective attributes to send request

CALL METHOD send_request->add_recipient

EXPORTING

i_recipient = recipient.

*--set send immediately flag

send_request->set_send_immediately( 'X' ).

*--Send document

CALL METHOD send_request->send( ).

COMMIT WORK.

CATCH cx_bcs INTO bcs_exception.

RAISE EXCEPTION bcs_exception.

ENDTRY.{{code}code}

Thanks,

Suma

Former Member
0 Kudos

Hi Sriram,

Please check the below code and take as referance

*&---------------------------------------------------------------------*
*& Report  ZTEST_EMAIL_SEND
*&
*&---------------------------------------------------------------------*
*&for checking the mail has sent or not can be seen in tcode 'SOST'
*&
*&---------------------------------------------------------------------*
REPORT  ztest_email_send.

*CLASS-DEFINITIONS                                                    *
*----------------------------------------------------------------------*
DATA: send_request       TYPE REF TO cl_bcs.
DATA: document           TYPE REF TO cl_document_bcs.
DATA: sender             TYPE REF TO cl_sapuser_bcs.
DATA: recipient          TYPE REF TO if_recipient_bcs.
DATA: exception_info     TYPE REF TO if_os_exception_info,
      bcs_exception      TYPE REF TO cx_bcs.

*----------------------------------------------------------------------*
* INTERNAL TABLES                                                      *
*----------------------------------------------------------------------*
DATA: l_mailtext TYPE soli_tab.
DATA: l_mailhex  TYPE solix_tab.
DATA: iaddsmtp   TYPE bapiadsmtp OCCURS 0 WITH HEADER LINE.
DATA: ireturn    TYPE bapiret2 OCCURS 0 WITH HEADER LINE.

*----------------------------------------------------------------------*
* VARIABLES                                                            *
*----------------------------------------------------------------------*
DATA: mail_line  LIKE LINE OF l_mailtext.
DATA: mailx_line LIKE LINE OF l_mailhex.
DATA: bapiadsmtp         TYPE bapiadsmtp.

*----------------------------------------------------------------------*
* CONSTANTS                                                            *
*----------------------------------------------------------------------*
CONSTANTS:
  kimball_domain(12) TYPE c VALUE '@kimball.com'.

CLASS cl_cam_address_bcs DEFINITION LOAD.
CLASS cl_abap_char_utilities DEFINITION LOAD.

DATA: control_parameters TYPE ssfctrlop,
      output_options     TYPE ssfcompop,
      job_output_info    TYPE ssfcrescl,
      job_output_options TYPE ssfcresop,
      otf_data           TYPE tsfotf,
      string_data        TYPE xstring,
      file_size          TYPE i,
      lines              TYPE TABLE OF  tline .


*-----------------------------------------------------------------------*
*                 START-OF-SELECTION
*-----------------------------------------------------------------------*
START-OF-SELECTION.

*-- SMART FORM CODE

  DATA: fm_name TYPE  rs38l_fnam,
        formname(30)  TYPE c.

  formname = 'ZTEST_SMART1'.

*--Calling smartform
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = formname
    IMPORTING
      fm_name            = 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.

  control_parameters-no_dialog = 'X'.
  control_parameters-getotf = 'X'.
  control_parameters-device = 'PRINTER'.
  job_output_options-tddest = 'LOC'.

*--Calling Function Module
  CALL FUNCTION fm_name
    EXPORTING
      control_parameters = control_parameters
      output_options     = output_options
    IMPORTING
      job_output_info    = job_output_info
      job_output_options = 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.
  ENDIF.


*--Convertion data OTF to ODF

  otf_data[] = job_output_info-otfdata[].

  CALL FUNCTION 'CONVERT_OTF'
   EXPORTING
     format                      = 'PDF'
*   MAX_LINEWIDTH               = 132
*   ARCHIVE_INDEX               = ' '
*   COPYNUMBER                  = 0
*   ASCII_BIDI_VIS2LOG          = ' '
   IMPORTING
     bin_filesize                = file_size
     bin_file                    = string_data
    TABLES
      otf                         =  otf_data[]
      lines                       =  lines
* 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.

*--Using SOLIX Converting string data

  DATA: lt_solix TYPE solix_tab.

  CALL METHOD cl_document_bcs=>xstring_to_solix
    EXPORTING
      ip_xstring = string_data
    RECEIVING
      rt_solix   = lt_solix.


*-- SMART FORM CODE

  TRY.
*-- Create persistent send request
      send_request = cl_bcs=>create_persistent( ).

      DATA: first(1) TYPE c.
      CLEAR first.
      DATA: lt_text TYPE soli_tab.
      DATA: ls_text TYPE soli.

      ls_text-line = 'THIS IS TEST DATA'.
      APPEND ls_text TO lt_text.
      CLEAR ls_text.

      ls_text-line = 'THIS IS TEST DATA'.
      APPEND ls_text TO lt_text.
      CLEAR ls_text.


      document = cl_document_bcs=>create_document(
                          i_type    = 'txt'
                          i_text    = lt_text
                          i_subject = 'subject' ).

      CALL METHOD document->add_attachment
        EXPORTING
          i_attachment_type    = 'PDF'
          i_attachment_subject = 'PDFDATA'
          i_att_content_hex    = lt_solix.

*--Add document to send request
      CALL METHOD send_request->set_document( document ).

*-- Get sender object
      sender = cl_sapuser_bcs=>create( sy-uname ).

*--Add sender
      CALL METHOD send_request->set_sender
        EXPORTING
          i_sender = sender.
      recipient = cl_cam_address_bcs=>create_internet_address( 'mail id').

*--Add recipient with its respective attributes to send request
      CALL METHOD send_request->add_recipient
        EXPORTING
          i_recipient = recipient.

*--set send immediately flag
      send_request->set_send_immediately( 'X' ).

*--Send document
      CALL METHOD send_request->send( ).

      COMMIT WORK.

    CATCH cx_bcs INTO bcs_exception.
      RAISE EXCEPTION bcs_exception.

  ENDTRY.

Thanks,

Suma

Former Member
0 Kudos

Hi Sriram,

Before calling the function module that is associated with the smartform, GETOTF fields of the control parameters should be set to 'X'. This will stop sending the external output in standard way and gives the output in OTF format which will be converted to PDF using function module 'CONVERT_OTF' and sent as PDF attachment to email using function module 'SO_DOCUMENT_SEND_API1'.

Regards,

Ram

Former Member
0 Kudos

Hi,

Try the below code.

REPORT z_sd_multi_cust_mail.

TABLES:nast,kna1,vbak.

DATA : v_vbeln LIKE vbak-vbeln,

v_ucomm LIKE sy-ucomm,

v_form_name TYPE rs38l_fnam.

START-OF-SELECTION.

&----


*& Form entry

&----


  • text

----


  • -->RETURN_CODE text

  • -->US_SCREEN text

----


FORM entry USING return_code us_screen.

CLEAR return_code.

CLEAR:v_vbeln,v_form_name.

v_vbeln = nast-objky.

v_ucomm = 'PRNT'.

IF v_ucomm = 'PRNT' ."For Mail sending

CALL FUNCTION 'Z_QUOTATION_MAIL_SEND'

EXPORTING

vbeln = nast-objky.

.

ENDIF.

CLEAR:v_ucomm.

ENDFORM. "entry

In FM 'Z_QUOTATION_MAIL_SEND'

FUNCTION Z_QUOTATION_MAIL_SEND.

*"----


""Local Interface:

*" IMPORTING

*" REFERENCE(VBELN) TYPE NAST-OBJKY

*"----


Importing Parameter is

VBELN TYPE NAST-OBJKY

TABLES: nast,

kna1,

vbak.

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,

v_vbeln TYPE vbak-vbeln.

DATA:BEGIN OF i_adr6 OCCURS 0,

addrnumber LIKE adr6-addrnumber,

consnumber LIKE adr6-consnumber,

smtp_addr LIKE adr6-smtp_addr,

END OF i_adr6.

v_vbeln = vbeln.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'Z_SD_SSF_QUOTATION'

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 "'/1BCDWB/SF00000093'

EXPORTING

control_parameters = w_ctrlop

output_options = w_compop

user_settings = 'X'

p_vbeln = v_vbeln

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 = 'PDF-Attachment Of Quotation!'.

APPEND i_objtxt.

DESCRIBE TABLE i_objtxt LINES v_lines_txt.

READ TABLE i_objtxt INDEX v_lines_txt.

DATA: v_str1 TYPE char12,

v_str2 TYPE char50.

CONCATENATE 'Quotation' '-' v_vbeln INTO v_str2 SEPARATED BY space.

wa_doc_chng-obj_name = 'smartform'.

wa_doc_chng-expiry_dat = sy-datum + 10.

wa_doc_chng-obj_descr = v_str2.

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 = 'Quotation'.

APPEND i_objpack.

SELECT SINGLE * FROM vbak WHERE vbeln = v_vbeln.

SELECT SINGLE * FROM kna1 WHERE kunnr = vbak-kunnr.

*---Getting the Multiple MAIL ID'S in this Vendor

SELECT addrnumber

consnumber

smtp_addr

FROM adr6 INTO TABLE i_adr6

WHERE addrnumber = kna1-adrnr

AND flg_nouse = space.

*---Adding the Multiple mail id into Receiptant list

LOOP AT i_adr6.

i_reclist-receiver = i_adr6-smtp_addr.

i_reclist-rec_type = 'U'.

APPEND i_reclist.

CLEAR: i_reclist,i_adr6.

ENDLOOP.

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.

ENDFUNCTION.

Former Member
0 Kudos

try to use the

code

tags for a better formatting next time

i dont really wnat to read the code in the form we have it here.

Edited by: Florian Kemmer on May 26, 2009 9:37 AM