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

RC 6 (x_error) at function SO_DOCUMENT_SEND_API1 (XLS attachment)

Former Member
0 Likes
5,510

Hi at all,

I've a problem with sending an e-mail with an attached XLS file.

I want to generate the XLS directly from SAP no download solution or anything else. I searched the threads for any solution, but nothing works. With the implemented code below I get the exception x_error and I don't what it means.

I have another program where I can send txt files as attachment, but no excel. Can somebody helps me?

I work on an Unicode System.

Thanks for your help.

Regards, Markus

&----


*& Report ZTEST_XLS_ATT

*&

&----


*&

*&

&----


REPORT ztest_xls_att.

PARAMETERS: p_email TYPE somlreci1-receiver

DEFAULT 'test(at)test.de'.

TYPES: BEGIN OF sol,

text(35),

END OF sol.

DATA: BEGIN OF it001 OCCURS 0,

bukrs TYPE pa0001-bukrs,

ename TYPE pa0001-ename,

END OF it001.

DATA: imessage TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE,

iattach TYPE STANDARD TABLE OF sol WITH HEADER LINE,

ipacking_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

ireceivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

iattachment LIKE solisti1 OCCURS 0 WITH HEADER LINE.

START-OF-SELECTION.

SELECT bukrs ename INTO TABLE it001 FROM pa0001 WHERE pernr = 'XXXXXX'.

  • Populate table with details to be entered into .xls file

PERFORM build_xls_data .

  • Populate message body text

CLEAR imessage.

REFRESH imessage.

imessage = 'Please find attached excel file'.

APPEND imessage.

  • Send file by email as .xls spreadsheet

PERFORM send_email_with_xls TABLES imessage

iattach

USING p_email

'Example Excel Attachment'

'XLS'

'TestFileName'

'CompanyCodes'.

IF sy-subrc = 0.

MESSAGE i000(zsai).

ENDIF.

************************************************************************

  • Form BUILD_XLS_DATA

************************************************************************

FORM build_xls_data .

  • constants: con_cret(2) type C value '0D', "OK for non Unicode

  • con_tab(2) type C value '09'. "OK for non Unicode

*If you have Unicode check active in program attributes then you will

*need to declare constants as follows

CLASS cl_abap_char_utilities DEFINITION LOAD.

CONSTANTS:

con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,

con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.

CONCATENATE 'BUKRS' 'BUTXT'

INTO iattach SEPARATED BY con_tab.

CONCATENATE con_cret iattach INTO iattach.

APPEND iattach.

LOOP AT it001.

CONCATENATE it001-bukrs it001-ename

INTO iattach SEPARATED BY con_tab.

CONCATENATE con_cret iattach INTO iattach.

  • iattach = iattach(30).

APPEND iattach.

ENDLOOP.

ENDFORM. "build_xls_data

************************************************************************

  • Form SEND_EMAIL_WITH_XLS

************************************************************************

  • Send file by email as .xls spreadsheet

  • perform send_email_with_xls tables imessage

  • iattach

  • using p_email

  • 'Example Excel Attachment'

  • 'XLS'

  • 'TestFileName'

  • 'CompanyCodes'.

FORM send_email_with_xls TABLES pit_message

pit_attach

USING p_email

p_mtitle

p_format

p_filename

p_attdescription.

DATA: xdocdata LIKE sodocchgi1,

xcnt TYPE i.

  • Fill the document data.

xdocdata-doc_size = 1.

  • Populate the subject/generic message attributes

xdocdata-obj_langu = sy-langu.

xdocdata-obj_name = 'SAPRPT'.

xdocdata-obj_descr = p_mtitle .

  • Fill the document data and get size of attachment

CLEAR xdocdata.

READ TABLE iattach INDEX xcnt.

xdocdata-doc_size =

( xcnt - 1 ) * 255 + STRLEN( iattach ).

xdocdata-obj_langu = sy-langu.

xdocdata-obj_name = 'SAPRPT'.

xdocdata-obj_descr = p_mtitle.

CLEAR iattachment.

REFRESH iattachment.

iattachment[] = pit_attach[].

  • Describe the body of the message

CLEAR ipacking_list.

REFRESH ipacking_list.

ipacking_list-transf_bin = space.

ipacking_list-head_start = 1.

ipacking_list-head_num = 0.

ipacking_list-body_start = 1.

DESCRIBE TABLE imessage LINES ipacking_list-body_num.

ipacking_list-doc_type = 'RAW'.

APPEND ipacking_list.

  • Create attachment notification

ipacking_list-transf_bin = 'X'.

ipacking_list-head_start = 1.

ipacking_list-head_num = 1.

ipacking_list-body_start = 1.

DESCRIBE TABLE iattachment LINES ipacking_list-body_num.

ipacking_list-doc_type = p_format. "XLS

ipacking_list-obj_descr = p_attdescription.

ipacking_list-obj_name = p_filename.

ipacking_list-doc_size = ipacking_list-body_num * 255.

APPEND ipacking_list.

  • Add the recipients email address

CLEAR ireceivers. REFRESH ireceivers.

ireceivers-receiver = p_email.

ireceivers-rec_type = 'U'.

ireceivers-com_type = 'INT'.

ireceivers-notif_del = 'X'.

ireceivers-notif_ndel = 'X'.

APPEND ireceivers.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = xdocdata

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = ipacking_list

contents_bin = iattachment

contents_txt = imessage

receivers = ireceivers

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.

SUBMIT rsconn01 WITH mode EQ 'INT' AND RETURN.

COMMIT WORK .

ENDIF.

ENDFORM. "send_email_with_xls

1 ACCEPTED SOLUTION
Read only

LucianoBentiveg
Active Contributor
0 Likes
2,110

Try this:


* Mail's body
  DESCRIBE TABLE i_texto LINES v_lineas.
  REFRESH i_objpack.
  CLEAR i_objpack.
  v_indice = 1.
  i_objpack-transf_bin = ' '.
  i_objpack-head_start = v_indice.
  i_objpack-body_start = 1.
  i_objpack-body_num = v_lineas.
  i_objpack-doc_type = 'RAW'.
  APPEND i_objpack.

* append lines of attach to body's mail
  APPEND LINES OF i_anexo TO i_texto.
  v_indice = v_indice + 1.
  i_objpack-transf_bin = ' '.
  i_objpack-head_start = v_indice.
  i_objpack-body_start = v_lineas + 1.
  i_objpack-obj_descr = v_descr_file.
  DESCRIBE TABLE i_anexo LINES v_lineas.
  i_objpack-body_num = v_lineas.
  i_objpack-doc_type = v_tipo_file.
  APPEND i_objpack.

* Information about attach
  CLEAR e_datos_doc.
  e_datos_doc-obj_descr = v_titulo.
  e_datos_doc-doc_size = ( v_lineas - 1 ) * 255 + STRLEN( i_cont_bin ).
  e_datos_doc-obj_langu  = sy-langu.
  e_datos_doc-obj_name   = 'SAPRPT'.
  e_datos_doc-sensitivty = 'F'.

* Information of receiver
  REFRESH i_destinatario.
  CLEAR i_destinatario.
  i_destinatario-receiver = v_destinatario.
  i_destinatario-rec_type = v_tipo.
  i_destinatario-com_type = 'INT'.
  i_destinatario-notif_del = 'X'.
  i_destinatario-notif_ndel = 'X'.
  APPEND i_destinatario.

* Envio del mail
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = e_datos_doc
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list               = i_objpack
      contents_bin               = i_cont_bin
      contents_txt               = i_texto
      receivers                  = i_destinatario
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      operation_no_authorization = 4
      OTHERS                     = 99.

Regards

5 REPLIES 5
Read only

LucianoBentiveg
Active Contributor
0 Likes
2,111

Try this:


* Mail's body
  DESCRIBE TABLE i_texto LINES v_lineas.
  REFRESH i_objpack.
  CLEAR i_objpack.
  v_indice = 1.
  i_objpack-transf_bin = ' '.
  i_objpack-head_start = v_indice.
  i_objpack-body_start = 1.
  i_objpack-body_num = v_lineas.
  i_objpack-doc_type = 'RAW'.
  APPEND i_objpack.

* append lines of attach to body's mail
  APPEND LINES OF i_anexo TO i_texto.
  v_indice = v_indice + 1.
  i_objpack-transf_bin = ' '.
  i_objpack-head_start = v_indice.
  i_objpack-body_start = v_lineas + 1.
  i_objpack-obj_descr = v_descr_file.
  DESCRIBE TABLE i_anexo LINES v_lineas.
  i_objpack-body_num = v_lineas.
  i_objpack-doc_type = v_tipo_file.
  APPEND i_objpack.

* Information about attach
  CLEAR e_datos_doc.
  e_datos_doc-obj_descr = v_titulo.
  e_datos_doc-doc_size = ( v_lineas - 1 ) * 255 + STRLEN( i_cont_bin ).
  e_datos_doc-obj_langu  = sy-langu.
  e_datos_doc-obj_name   = 'SAPRPT'.
  e_datos_doc-sensitivty = 'F'.

* Information of receiver
  REFRESH i_destinatario.
  CLEAR i_destinatario.
  i_destinatario-receiver = v_destinatario.
  i_destinatario-rec_type = v_tipo.
  i_destinatario-com_type = 'INT'.
  i_destinatario-notif_del = 'X'.
  i_destinatario-notif_ndel = 'X'.
  APPEND i_destinatario.

* Envio del mail
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = e_datos_doc
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list               = i_objpack
      contents_bin               = i_cont_bin
      contents_txt               = i_texto
      receivers                  = i_destinatario
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      operation_no_authorization = 4
      OTHERS                     = 99.

Regards

Read only

0 Likes
2,110

Thank Peluka for your quick reply,

but I think your solution can not help. I think your sourcecode is the same than mine.

Any other ideas???

Regards, Markus

Read only

0 Likes
2,110

I've this code working in a lot of programs.

Regards

Read only

0 Likes
2,110

Ok Peluka,

can you say me, how your variables are filled. I can not see any differences.... Perhaps, my tables packing_list or iattach are wrong. I don't know. I don't see the mistakes in my coding and the exception x_error does not really, helps me.

Thanks for your help.

Regards, Markus

Read only

0 Likes
2,110

Hi Pekula,

I checked your code with small modifications:


* Mail's body
  DESCRIBE TABLE imessage LINES v_lines.
  REFRESH i_objpack.
  CLEAR i_objpack.
  v_indice = 1.
  i_objpack-transf_bin = ' '.
  i_objpack-head_start = v_indice.
  i_objpack-body_start = 1.
  i_objpack-body_num = v_lines.
  i_objpack-doc_type = 'RAW'.
  APPEND i_objpack.

* append lines of attach to body's mail
  APPEND LINES OF iattachment TO imessage.
  v_indice = v_indice + 1.
  i_objpack-transf_bin = ' '.
  i_objpack-head_start = v_indice.
  i_objpack-body_start = v_lines + 1.
  i_objpack-obj_descr = p_attdescription. "CompanyCodes
  DESCRIBE TABLE iattachment LINES v_lines.
  i_objpack-body_num = v_lines.
  i_objpack-doc_type = p_format. "XLS
  APPEND i_objpack.

* Information about attach
  CLEAR e_datos_doc.
  e_datos_doc-obj_descr = p_mtitle. "'Example Excel Attachment'
  e_datos_doc-doc_size = ( v_lines - 1 ) * 255 + STRLEN( iattach ).
  e_datos_doc-obj_langu  = sy-langu.
  e_datos_doc-obj_name   = 'SAPRPT'.
  e_datos_doc-sensitivty = 'F'.

* Information of receiver
  REFRESH i_destinatario.
  CLEAR i_destinatario.
  i_destinatario-receiver = p_email. "test[at]test.de
  i_destinatario-rec_type = 'U'.
  i_destinatario-com_type = 'INT'.
  i_destinatario-notif_del = 'X'.
  i_destinatario-notif_ndel = 'X'.
  APPEND i_destinatario.


* Envio del mail
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = e_datos_doc
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list               = i_objpack
      contents_bin               = iattachment
      contents_txt               = imessage
      receivers                  = i_destinatario
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      operation_no_authorization = 4
      OTHERS                     = 99.

I think, my iattachment or i_objpack is not correct. Can you help me?

Whats about your i_cont_bin? I think there can be my problem.

Regards, Markus

Edited by: Markus Rodehutskors on Mar 13, 2009 9:12 AM