cancel
Showing results for 
Search instead for 
Did you mean: 

Send E-mail with Body (text) using the FM CONVERT_COMM_TYPE_DATA

Former Member
0 Kudos

Hi Experts,

I am using the FMs ADDR_GET_NEXT_COMM_TYPE and CONVERT_COMM_TYPE_DATA to send my sapscript (ZMEDRUCK) as an e-mail. My requirement is to change the body of the e-mail but i cannot find any parameter in this FM where i can add or edit body of the e-mail.

Can someone please help me?.

Thanks and Regards.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi

solved my problem, this is the solution I found:


itcpo-tdgetotf = 'X'. "This convert the sapscript of PO in OTF format

CALL FUNCTION 'OPEN_FORM'
    EXPORTING
      form            = xformular
      language        = ekko-spras
      OPTIONS         = itcpo
      archive_index   = toa_dara
.........

CALL FUNCTION 'CLOSE_FORM'
    IMPORTING
      RESULT     = RESULT
      rdi_result = rdi_result
    TABLES
      otfdata    = otfdata.
.........

"Extraemos la tabla OTF que se generó en CLOSE_FORM:
  it_otf[] = otfdata[].

*calling function module to convert otf format of smartform to pdf format
  CALL FUNCTION 'CONVERT_OTF'
   EXPORTING
     format                      = 'PDF'
     max_linewidth               = 132
*     ARCHIVE_INDEX              =
*     COPYNUMBER                 =
*     ASCII_BIDI_VIS2LOG         =
*     PDF_DELETE_OTFTAB          =
   IMPORTING
     bin_filesize                = v_len_in
*     BIN_FILE                   =
    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.
  ENDIF.

* Subject mail
  w_doc_chng-obj_descr = itcpo-tdtitle.

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

it_objtxt-line = ' Texto del correo electrónico (Body mail)'.
  APPEND it_objtxt.

  DESCRIBE TABLE it_objtxt LINES v_lines_txt.


* 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 = 'RAW'.        "RAW
  APPEND wa_it_objpack TO it_objpack.

* Packing as PDF.
  wa_it_objpack-transf_bin = 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 = 'PDF'.        "PDF
  "wa_it_objpack-obj_name = 'ZMEDRUCK'.        "SmartForm
  CONCATENATE itcpo-tdtitle '.pdf' INTO wa_it_objpack-obj_descr.
  wa_it_objpack-doc_size = v_lines_bin * 255.
  APPEND wa_it_objpack TO it_objpack.

it_reclist-express = 'X'. "Enviar: En forma de documento urgente
it_reclist-to_answer = 'X'. "Es obligatorio responder este objeto
it_reclist-receiver = 'correo electronico'.
append it_reclist.

* Sending Mail
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
   EXPORTING
    document_data                  = w_doc_chng
    put_in_outbox                  = X
*     COMMIT_WORK                    =
*    IMPORTING
*     SENT_TO_ALL                    =
*     NEW_OBJECT_ID                  =
   TABLES
    packing_list                   = it_objpack
    object_header                  = wa_objhead
    contents_bin                   = it_objbin
    contents_txt                   = it_objtxt
*     CONTENTS_HEX                   =
*     OBJECT_PARA                    =
*     OBJECT_PARB                    =
      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 .

former_member361845
Participant
0 Kudos

Hi

Use Cl_BCS Class as it has good methods to implment.

document = cl_document_bcs=>create_document(

i_type = 'RAW' "documents_line-type

i_text = l_mailtext "documents_line-content_text

i_subject = l_mailsub ). "documents_line-subject ).

CALL METHOD document->add_attachment

EXPORTING

i_attachment_type = 'PDF' "documents_line-type

i_attachment_subject = l_file "documents_line-subject

i_att_content_hex = it_pdf. "documents_line-content_text.

ENDIF.

Try it will be very helpful.

Former Member
0 Kudos

Hi Shihin11

The variable "document", what type is defined?

This is the my source code:

CASE nast-nacha.

..........

...........

WHEN '5'.

xdevice = 'MAIL'.

xdialog = space.

CALL FUNCTION 'ADDR_GET_NEXT_COMM_TYPE'

EXPORTING

strategy = c_cstrategy

address_number = lfa1-adrnr

IMPORTING

comm_type = lvs_comm_type

comm_values = lvs_comm_values

EXCEPTIONS

address_not_exist = 1

person_not_exist = 2

no_comm_type_found = 3

internal_error = 4

parameter_error = 5

OTHERS = 6.

IF sy-subrc = 0.

MOVE-CORRESPONDING nast TO w_snast.

CLEAR w_smtp_addr.

w_smtp_addr = lvs_comm_values-adsmtp-smtp_addr.

CALL FUNCTION 'CONVERT_COMM_TYPE_DATA'

EXPORTING

pi_comm_type = lvs_comm_type

pi_comm_values = lvs_comm_values

pi_country = nast-tland

pi_repid = sy-repid

pi_snast = w_snast

IMPORTING

pe_itcpo = lvs_itcpo

pe_mail_recipient = w_mail_recipient

pe_mail_sender = w_mail_sender

EXCEPTIONS

comm_type_not_supported = 1

recipient_creation_failed = 2

sender_creation_failed = 3

OTHERS = 4.

IF sy-subrc = 0.

ENDIF.

ENDIF.

WHEN OTHERS.

xdevice = 'PRINTER'.

IF nast-ldest EQ space.

xdialog = 'X'.

ELSE.

itcpo-tddest = nast-ldest.

ENDIF.

ENDCASE.

IF xscreen NE space.

itcpo-tdpreview = 'X'.

ENDIF.

  • Bei Probedruck, wenn das Medium keine Drucker ist.

IF nast-sndex EQ 'X' AND nast-nacha NE '1'.

xdevice = 'PRINTER'.

IF nast-ldest EQ space.

xdialog = 'X'.

ELSE.

itcpo-tddest = nast-ldest.

ENDIF.

ENDIF.

itcpo-tdnoprint = 'X'.

itcpo-tdcover = nast-tdocover.

itcpo-tdcopies = nast-anzal.

IF sy-ucomm EQ 'DRPR' OR

nast-sndex EQ 'X'.

itcpo-tdnoprint = ' '.

itcpo-tdnoprev = 'X'.

itcpo-tdcopies = 1.

ENDIF.

*} REPLACE

itcpo-tddataset = nast-dsnam.

itcpo-tdsuffix1 = nast-dsuf1.

itcpo-tdsuffix2 = nast-dsuf2.

itcpo-tdimmed = nast-dimme.

itcpo-tddelete = nast-delet.

itcpo-tdsenddate = nast-vsdat.

itcpo-tdsendtime = nast-vsura.

itcpo-tdprogram = sy-repid.

*{ INSERT PROK900574 8

itcpo-tdnewid = 'X'.

*} INSERT

CALL FUNCTION 'OPEN_FORM'

EXPORTING

form = xformular

language = ekko-spras

OPTIONS = itcpo

archive_index = toa_dara

archive_params = arc_params

  • ARCHIVE_PARAMS = ALARC_PAR1

device = xdevice

dialog = xdialog

*{ INSERT PROK900574 3

mail_sender = w_mail_sender

mail_recipient = w_mail_recipient

*} INSERT

EXCEPTIONS

canceled = 01.

IF sy-subrc NE 0.

*{ REPLACE PROK900574 9

*\ PERFORM PROTOCOL_UPDATE USING '142' EKKO-EBELN SPACE SPACE SPACE.

*\ RETCO = SY-SUBRC.

retco = sy-subrc.

PERFORM protocol_update USING '142' ekko-ebeln space space space.

*} REPLACE

EXIT.

ENDIF.

Thanks

Former Member
0 Kudos

External send for SAP Scripts calls function module CONVERT_OTF_AND_MAIL internally to send the document as an attachment to email. I do not see any way to change the email contents in this FM.