Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Import parameters

Param name      Type     associated type                                short text 
I_TID                    LIKE       THEAD-TDID                          Text ID of text to be read

I_LAN                   LIKE       THEAD-TDSPRAS                    Language of text to be read

I_L_NAME            LIKE        THEAD-TDNAME                  Name of text to be read

I_OID                   LIKE        THEAD-TDOBJECT                Object of text to be read

W_RETURN         TYPE      SSFCRESCL                              Smart Forms: Return value at end of form printing

I_POTITLE           TYPE      EBELN                                     purchase order number

W_DOC_CHNG   TYPE      SODOCCHGI1                         Data of an object which can be changed

I_ADDRNUM       LIKE        ADR6-ADDRNUMBER            Address number of Vendor    

Source code :

* PROGRAM TITLE          : MAIL SEND
* AUTHOR                        : K PRASHANTI
* DATE                              : 08/08/2008
* DESCRIPTION              : This function module helps in converting the smart form to
*                                        pdf format and sends mail with proper text in mail body

*--------------------------------------------------------------------------------------------------------------------------------------                                                                                ""Local Interface:*"  IMPORTING
*"     REFERENCE(I_TID) LIKE  THEAD-TDID
*"     REFERENCE(I_LAN) LIKE  THEAD-TDSPRAS
*"     REFERENCE(I_L_NAME) LIKE  THEAD-TDNAME
*"     REFERENCE(I_OID) LIKE  THEAD-TDOBJECT
*"     REFERENCE(W_RETURN) TYPE  SSFCRESCL
*"     REFERENCE(I_POTITLE) TYPE  EBELN
*"     REFERENCE(W_DOC_CHNG) TYPE  SODOCCHGI1
*"     REFERENCE(I_ADDRNUM) LIKE  ADR6-ADDRNUMBER
*"----------------------------------------------------------------------
*----------------------------------------------------------------------------------*
*data declaration
*----------------------------------------------------------------------------------*
*Internal Table declaration
DATA: it_otf     TYPE STANDARD TABLE OF  itcoo ,
      it_tline   TYPE STANDARD TABLE OF  tline ,
      it_record  TYPE STANDARD TABLE OF  solisti1,
      it_objpack TYPE STANDARD TABLE OF  sopcklsti1,
      it_objtxt  TYPE STANDARD TABLE OF  solisti1 ,
      it_objbin  TYPE STANDARD TABLE OF  solisti1 ,
      it_reclist TYPE STANDARD TABLE OF  somlreci1 ,
      it_tdline  TYPE STANDARD TABLE OF  tline,
*Work Area declarations
      wa_objhead     TYPE  soli_tab,
      wa_buffer      TYPE  string,       "To convert from 132 to 255
      wa_it_objtxt   TYPE  solisti1,
      wa_it_objpack  TYPE  sopcklsti1,
      wa_it_record   TYPE  solisti1,
      wa_it_reclist  TYPE  somlreci1,
      wa_it_tline    TYPE  tline,
      wa_tdline      TYPE  tline,
*variable declaration
      v_lines_bin    TYPE  i,
      v_lines_txt    TYPE  i,
      v_len_in       TYPE  sood-objlen,                     "#EC NEEDED
      v_mailaddr     TYPE  adr6-smtp_addr.
*constant declaration
CONSTANTS : c_msgtype TYPE c VALUE 'E',    " for declaring masseage type as error msg
            c_x TYPE c VALUE 'X',
            c_u TYPE c VALUE 'U'.
it_otf[] = w_return-otfdata[].
*calling function module to convert otf format of smartform to pdf format
CALL FUNCTION 'CONVERT_OTF'
  EXPORTING
    format
    ='PDF'
    max_linewidth         = 132
  IMPORTING
    bin_filesize          = v_len_in
  TABLES
    otf                   = it_otf
    lines                 = it_tline
  EXCEPTIONS
    err_max_linewidth     = 1
    err_format            = 2
    err_conv_not_possible = 3
    err_bad_otf           = 4
    OTHERS                = 5.
IF sy-subrc NE 0.
  sy-msgid = text-002.     "Vendor creation failed
  sy-msgty = c_msgtype.    " E
  sy-msgno = 040.
  sy-msgv1 = ' '.
  sy-msgv2 = ' '.
  sy-msgv3 = ' '.
  sy-msgv4 = ' '.
  EXIT.
ELSE.
* Convert PDF from 132 to 255.
  LOOP AT it_tline INTO wa_it_tline.
    TRANSLATE wa_it_tline USING ' ~'.      " Replacing space by ~
    CONCATENATE wa_buffer wa_it_tline INTO wa_buffer.
  ENDLOOP.
  TRANSLATE wa_buffer USING '~ '.         " Replacing space by ~
  DO.
    wa_it_record = wa_buffer.
    APPEND wa_it_record TO it_record.     " Appending 255 characters as a record
    SHIFT wa_buffer LEFT BY 255 PLACES.
    IF wa_buffer IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.
  REFRESH:it_objbin.
  CLEAR wa_objhead.
* Object with PDF.
  it_objbin[] = it_record[].
  DESCRIBE TABLE it_objbin LINES v_lines_bin.
*calling a function module read_text to get the text for the mail body
  CALL FUNCTION 'READ_TEXT'
    EXPORTING
      id                      = i_tid
      language                = i_lan
      name                    = i_l_name
      object                  = i_oid
    TABLES
      lines                   = it_tdline
    EXCEPTIONS
      id                      = 1
      language                = 2
      name                    = 3
      not_found               = 4
      object                  = 5
      reference_check         = 6
      wrong_access_to_archive = 7
      OTHERS                  = 8.
  IF sy-subrc <> 0.                                         "#EC
  ENDIF.
  IF it_tdline IS NOT INITIAL.
    LOOP AT it_tdline INTO wa_tdline.
      wa_it_objtxt = wa_tdline-tdline.
      APPEND wa_it_objtxt TO it_objtxt.
      CLEAR: wa_tdline,
      wa_it_objtxt.
    ENDLOOP.
    DESCRIBE TABLE it_objtxt LINES v_lines_txt.
  ENDIF.
* Pack to main body as RAW.
  CLEAR wa_it_objpack-transf_bin.        "Obj. to be transported not in binary form
  wa_it_objpack-head_start = 1.          "Start line of object header in transport packet
  wa_it_objpack-head_num = 0.            "Number of lines of an object header in object packet
  wa_it_objpack-body_start = 1.          "Start line of object contents in an object packet
  wa_it_objpack-body_num = v_lines_txt.  "Number of lines of the object contents in an object packet
* Code for document class
  wa_it_objpack-doc_type = text-004.        "RAW
  APPEND wa_it_objpack TO it_objpack.
* Packing as PDF.
  wa_it_objpack-transf_bin = c_x.           " X
  wa_it_objpack-head_start = 1.
  wa_it_objpack-head_num = 1.
  wa_it_objpack-body_start = 1.
  wa_it_objpack-body_num = v_lines_bin.
  wa_it_objpack-doc_type = text-001.        "PDF
  wa_it_objpack-obj_name = text-006.        "SmartForm
  CONCATENATE i_potitle '.pdf' INTO wa_it_objpack-obj_descr.
  wa_it_objpack-doc_size = v_lines_bin * 255.
  APPEND wa_it_objpack TO it_objpack.
* Document information.
  CLEAR wa_it_reclist.
* e-mail receivers... puting a select on adr6 to get mail id on basis of address number which is getting from adrc table based on your requiremnt .
  SELECT SINGLE smtp_addr FROM adr6 INTO v_mailaddr         "#EC *
  WHERE addrnumber = i_addrnum.
  wa_it_reclist-receiver = v_mailaddr.
  wa_it_reclist-express = c_x.                        " X
  wa_it_reclist-rec_type = c_u.                       "U -> Internet address
  APPEND wa_it_reclist TO it_reclist.
* Sending Mail
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = w_doc_chng
      put_in_outbox              = c_x            "X
    TABLES
      packing_list               = it_objpack
      object_header              = wa_objhead
      contents_bin               = it_objbin
      contents_txt               = it_objtxt
      receivers                  = it_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.
    sy-msgid = text-008.      "The entered value is not a valid Storage Location
    sy-msgty = c_msgtype.     " E
    sy-msgno = 041.      sy-msgv1 = ' '.
    sy-msgv2 = ' '.
    sy-msgv3 = ' '.
    sy-msgv4 = ' '.
    EXIT.
  ENDIF.
ENDIF.
*ENDFUNCTION.