Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

problem in script output sending mail

former_member203501
Active Contributor
0 Likes
652

hi ,

I have a problem sending a mail with script output as attachment . I have searched in the forum for the answers but none is solved my question.

I am sending the data to the otf and it is getting the otfdata. but it is not showing the data on the script when it is sent as an attachment to the email , but it is showing only script with null values filled.( means i am getting the mail with attachment but in that attachment there is no data filled in the script send).

the code is like this ..


here i am filling the otfdata and i am exporting the otfdata
CALL FUNCTION 'ZMM_ARRANG_ENTRY_ABR_NATRAB'
    EXPORTING
      i_nast       = nast
      i_fonam      = tnapr-fonam
      i_xscreen    = pi_xscreen
      i_arc_params = arc_params
      i_toa_dara   = toa_dara
    IMPORTING
      e_retcode    = px_retcode
    EXCEPTIONS
      OTHERS       = 1.

  IF ( sy-subrc <> 0 ).                "Fehler
    MOVE sy-subrc TO px_retcode.
    IF ( pi_xscreen = 'X' ).           "Ausgabe auf Bildschirm
      MESSAGE ID     sy-msgid
              TYPE   sy-msgty
              NUMBER sy-msgno
              WITH   sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  ELSE.
*---Import OTFDATA from the memory
    IMPORT  it_otfdata FROM MEMORY ID 'OTF'.
  ENDIF.

  wa_maildata-obj_name = 'EMAIL'.
  wa_maildata-obj_descr = 'Settlement Details'.

*-----mail contents
  it_mailtext-line = 'Sub-sequent settlement Details'.
  APPEND it_mailtext.

  DESCRIBE TABLE it_mailtext LINES v_lines.
  READ TABLE it_mailtext INDEX v_lines.
  wa_maildata-doc_size = ( v_lines - 1 ) * 255 + STRLEN( it_mailtext ).

*Creation of the entry for the compressed document
  CLEAR it_mailpack-transf_bin.
  it_mailpack-head_start = 1.
  it_mailpack-head_num   = 0.
  it_mailpack-body_start = 1.
  it_mailpack-body_num   = v_lines.
  it_mailpack-doc_type   = 'RAW'.
  APPEND it_mailpack.

*-----Get OTF data
  LOOP AT it_otfdata.
    it_mailcont-line = it_otfdata.
    APPEND it_mailcont.
  ENDLOOP.

*---Move  OTF data into binary table
  LOOP AT it_mailcont.
    MOVE-CORRESPONDING it_mailcont TO it_mailbin.
    APPEND it_mailbin.
  ENDLOOP.

*---Get no of lines in Binary data table
  DESCRIBE TABLE it_mailbin LINES v_lines.

*---Fill name of the header of email
  it_mailhead = 'Subsequent Settlement Details.OTF'.
  APPEND it_mailhead.

*---Creation of the entry for the compressed attachment
  it_mailpack-transf_bin   = 'X'.
  it_mailpack-head_start   = 1.
  it_mailpack-head_num     = 1.
  it_mailpack-body_start   = 1.
  it_mailpack-body_num     = v_lines.
  it_mailpack-doc_type     = 'OTF'.
  it_mailpack-obj_name     = 'EMAIL'.
  it_mailpack-obj_descr    = 'Settlement Details'.
  it_mailpack-doc_size     = v_lines * 255.
  APPEND it_mailpack.

*----Get email address from the address number of vendor
  CALL FUNCTION 'ADDR_GET_REMOTE'
    EXPORTING
      addrnumber = l_adrnum
    TABLES
      adsmtp     = it_adsmtp.

*----Get mail address
  READ TABLE it_adsmtp WITH KEY remark = 'AP_SUB_SETT'.
  IF sy-subrc = 0.
    it_mailrec-receiver   = it_adsmtp-smtp_addr.
    it_mailrec-rec_type   = 'U'.
    it_mailrec-com_type   = 'EXT'.
    APPEND it_mailrec.

*---Send email with PDF attachment
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
      EXPORTING
        document_data = wa_maildata
        put_in_outbox = 'X'
        COMMIT_WORK   = 'X'
      TABLES
        packing_list  = it_mailpack
        object_header = it_mailhead
        contents_bin  = it_mailbin
        contents_txt  = it_mailtext
        receivers     = it_mailrec.
  ELSE.
    MESSAGE 'No email id Exist for the vendor' TYPE 'E'.
  ENDIF.

please suggest me with your valuable answers .

Regards,

Venkat Appikonda.

3 REPLIES 3
Read only

Former Member
0 Likes
595

hi for ur query u have decl these struture in ur program.

*STRUCTURE DECLARATION

DATA: WA_DOC_DATA LIKE SODOCCHGI1.

DATA: IT_PACKING_LIST LIKE SOPCKLSTI1 OCCURS 0 WITH

HEADER LINE,

IT_OBJECT_HEADER LIKE SOLISTI1 OCCURS 0 WITH

HEADER LINE,

IT_CONTENTS_TXT LIKE SOLISTI1 OCCURS 0 WITH

HEADER LINE,

IT_CONTENTS_BIN LIKE SOLISTI1 OCCURS 0 WITH

HEADER LINE,

IT_CONTENTS_HEX LIKE SOLIX OCCURS 0 WITH

HEADER LINE,

IT_CONTENTS LIKE SOLIX OCCURS 0 WITH

HEADER LINE,

IT_RECEIVERS LIKE SOMLRECI1 OCCURS 0 WITH

HEADER LINE.

DATA: V_LINE_COUNTER TYPE I.

DATA: V_BUFFER TYPE STRING.

Edited by: dominic joe on Mar 18, 2009 6:37 AM

Read only

Former Member
0 Likes
595

Hi venkat

Just check if this helps you.

The following part of the code does exactly that.

  • Selecting details from the spool request table.

SELECT * FROM tsp01 INTO TABLE tb_spool

WHERE rqowner = sy-uname.

IF sy-subrc EQ 0.

SORT tb_spool DESCENDING BY rqcretime.

CLEAR : tb_spool.

READ TABLE tb_spool INDEX 1.

  • convert spool into PDF format.

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = tb_spool-rqident

TABLES

PDF = tb_lines.

ENDIF.

After this, on execution we get the below mentioned message.

.

This indicates that a PDF of the SAP Script has been created which is in the format u201C132-long stringsu201D.

In order to send the mail across, the mailing format of the PDF supports u201C255-long stringsu201D. So, the present u201C132-long stringsu201D needs to be converted into u201C255-long stringsu201D. This along with the mail code is mentioned below.

DATA: lv_receiver(50) TYPE c.

REFRESH: tb_obj_txt,

tb_obj_bin,

tb_obj_head,

tb_paklist,

tb_receiver.

CLEAR: tb_obj_txt,

tb_obj_bin,

tb_paklist,

tb_obj_head,

tb_receiver.

CLEAR: tb_adrc.

IF NOT tb_adrc[] IS INITIAL.

  • Reading the address table with the key as address number.

READ TABLE tb_adrc WITH KEY addrnumber = tb_kna2-adrnr.

IF sy-subrc EQ 0.

  • Vendor Email ID.

SELECT SINGLE smtp_addr

FROM adr6

INTO wf_mailaddr

WHERE addrnumber = tb_adrc-addrnumber.

IF sy-subrc EQ 0.

  • Moving the mail address to the receiver itab

MOVE wf_mailaddr TO tb_receiver-receiver.

tb_receiver-rec_type = text-011.

APPEND tb_receiver.

ELSE.

CONCATENATE text-004 tb_kna2-kunnr text-005 INTO lv_receiver

SEPARATED BY space.

  • If pa_call is initial, the receiver ID is printed; else an INVALID E-mail ID message gets flashed.

IF pa_call IS INITIAL.

WRITE 😕 lv_receiver.

ENDIF.

CLEAR: itab.

itab-kunnr = tb_kna2-kunnr.

itab-message = lv_receiver.

APPEND itab.

EXIT. u201CNo mailing for invalid Email id

ENDIF.

ENDIF.

ENDIF.

wf_name = sy-uname.

wf_year = tb_main-bldat(4).

wf_mon = tb_main-bldat+4(2).

*This FM gives the name of the months.

CALL FUNCTION 'MONTH_NAMES_GET'

EXPORTING

language = sy-langu

TABLES

month_names = tb_months.

IF sy-subrc EQ 0.

READ TABLE tb_months WITH KEY mnr = wf_mon.

IF sy-subrc EQ 0.

wf_name = tb_months-ktx.

ENDIF.

ENDIF.

CLEAR: tb_contp.

IF NOT tb_contp[] IS INITIAL.

*Reading the contp itab as per the customer entered on the selection screen.

READ TABLE tb_contp WITH KEY bukrs = pa_bukrs

kunnr = tb_kna2-kunnr.

IF sy-subrc EQ 0.

CONCATENATE text-006 text-008 tb_contp-contp text-008 tb_kna2-kunnr

text-008 wf_name text-008 wf_year INTO wf_sub.

ENDIF.

ELSE.

CONCATENATE text-006 text-008 tb_kna2-kunnr text-008 wf_name

text-008 wf_year INTO wf_sub.

ENDIF.

  • Subject and Description

CLEAR wa_docdata.

wa_docdata-obj_name = text-007.

wa_docdata-obj_descr = wf_sub.

wa_docdata-obj_langu = sy-langu.

  • Write main body

tb_obj_txt = text-009.

APPEND tb_obj_txt.

CLEAR tb_obj_txt.

CLEAR tb_paklist.

tb_paklist-head_start = 1.

tb_paklist-head_num = 3.

tb_paklist-body_start = 1.

tb_paklist-body_num = 60.

tb_paklist-doc_type = text-012.

APPEND tb_paklist.

CLEAR tb_paklist.

  • create PDF file

  • Transfer the 132-long strings to 255-long strings

LOOP AT tb_lines.

TRANSLATE tb_lines USING ' ~'.

CONCATENATE wf_buffer tb_lines INTO wf_buffer.

ENDLOOP.

TRANSLATE wf_buffer USING '~ '.

DO.

tb_obj_bin = wf_buffer.

APPEND tb_obj_bin.

SHIFT wf_buffer LEFT BY 255 PLACES.

IF wf_buffer IS INITIAL.

EXIT.

ENDIF.

ENDDO.

DESCRIBE TABLE tb_obj_bin LINES lv_lines.

READ TABLE tb_obj_bin INDEX lv_lines.

lv_size = ( lv_lines - 1 ) * 255 + STRLEN( tb_obj_bin ).

  • Create attachment notification

tb_paklist-transf_bin = co_x.

tb_paklist-head_start = 1.

tb_paklist-head_num = 0.

tb_paklist-body_start = 1.

tb_paklist-body_num = lv_lines.

tb_paklist-doc_type = text-013.

tb_paklist-obj_descr = text-010.

tb_paklist-obj_name = text-010.

tb_paklist-doc_size = lv_size.

APPEND tb_paklist.

*mail the PDF to the receiver.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = wa_docdata

sender_address = wf_name

sender_address_type = text-014

TABLES

packing_list = tb_paklist

object_header = tb_obj_head

contents_bin = tb_obj_bin

contents_txt = tb_obj_txt

receivers = tb_receiver

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.

CONCATENATE text-003 tb_kna2-kunnr text-005 INTO lv_receiver

SEPARATED BY space.

CLEAR: itab.

itab-kunnr = tb_kna2-kunnr.

itab-message = lv_receiver.

APPEND itab.

IF pa_call IS INITIAL.

WRITE 😕 lv_receiver.

ENDIF.

ELSE.

CONCATENATE text-002 tb_kna2-kunnr text-005 INTO lv_receiver

SEPARATED BY space.

CLEAR: itab.

itab-kunnr = tb_kna2-kunnr.

itab-message = lv_receiver.

APPEND itab.

IF pa_call IS INITIAL.

WRITE 😕 lv_receiver.

ENDIF.

ENDIF.

Hope this helps.

Harsh

Read only

former_member203501
Active Contributor
0 Likes
595

solved by my own