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 with FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'

Former Member
0 Likes
1,440

Hi experts,

I have problem with FM 'SO_NEW_DOCUMENT_ATT_SEND_API1' ,

I need send email with attachment , but FM insert all data from itab in first tab of file Excel and don't disperse it .

I build my attachment for this way :

it_objpack-head_start = 1.

it_objpack-head_num = 0.

it_objpack-body_start = 1.

it_objpack-body_num = tab_lines.

it_objpack-doc_type = 'xls'.

it_objpack-obj_descr = w_filename.

it_objpack-obj_name = c_billing.

it_objpack-doc_size = tab_lines * 255.

APPEND it_objpack.

How to solve this problem???

Thank's.

Tatiana.

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,176

>

> \[...\] FM insert all data \[...\] in first tab of file Excel and don't disperse it \[...\]

What is your original excel file format ? (when attached to the email)

1) have a Comma-Separated Values format (can be opened via notepad for example),

2) or is it a true excel file which contains several sheets ?

3) or is it just that you have a CSV file and all columns appear in the first column ?

If it's case 1), it's normal.

If it's case 2), I don't understand how it's possible to have all sheets merged into the first sheet !

If it's case 3), it's a normal excel function. When you open the file, excel normally detects file format is text (CSV) and asks the user if he wants to expand the columns, or not, and asks what character is the column separator (comma, pipe, tab, etc.) The user may also choose to expand the columns later, there is a menu in excel to do that.

Hi experts,

I have problem with FM 'SO_NEW_DOCUMENT_ATT_SEND_API1' ,

I need send email with attachment , but FM insert all data from itab in first tab of file Excel and don't disperse it .

I build my attachment for this way :

it_objpack-head_start = 1.

it_objpack-head_num = 0.

it_objpack-body_start = 1.

it_objpack-body_num = tab_lines.

it_objpack-doc_type = 'xls'.

it_objpack-obj_descr = w_filename.

it_objpack-obj_name = c_billing.

it_objpack-doc_size = tab_lines * 255.

APPEND it_objpack.

How to solve this problem???

Thank's.

Tatiana.

4 REPLIES 4
Read only

Former Member
0 Likes
1,176

DESCRIBE TABLE so_ali[] LINES lineno.

objpack-transf_bin = 'X'.----->specify it

objpack-head_start = 1.

objpack-head_num = 1.---->change it

objpack-body_start = 1.

objpack-doc_size = lineno * 255 .

objpack-body_num = lineno.

objpack-doc_type = 'XLS'.

objpack-obj_name = 'INVOICE'.

objpack-obj_descr = 'Invoice'.

objpack-obj_langu = 'E'.

APPEND objpack.

Read only

Former Member
0 Likes
1,176

Hi,

Try this code:

FORM docu_send_email USING pv_otfdata TYPE tsfotf

pv_emailid TYPE any

pv_formname TYPE any.

DATA: lv_filesize TYPE i,

lv_buffer TYPE string,

lv_attachment TYPE i,

lv_testo TYPE i.

DATA: li_pdfdata TYPE STANDARD TABLE OF tline,

li_mess_att TYPE STANDARD TABLE OF solisti1,

li_mtab_pdf TYPE STANDARD TABLE OF tline,

li_objpack TYPE STANDARD TABLE OF sopcklsti1,

li_objtxt TYPE STANDARD TABLE OF solisti1,

li_objbin TYPE STANDARD TABLE OF solisti1,

li_reclist TYPE STANDARD TABLE OF somlreci1,

li_objhead TYPE soli_tab.

DATA: lwa_pdfdata TYPE tline,

lwa_objpack TYPE sopcklsti1,

lwa_mess_att TYPE solisti1,

lwa_objtxt TYPE solisti1,

lwa_objbin TYPE solisti1,

lwa_reclist TYPE somlreci1,

lwa_doc_chng TYPE sodocchgi1.

CONSTANTS: lc_u TYPE char1 VALUE 'U',

lc_0 TYPE char1 VALUE '0',

lc_1 TYPE char1 VALUE '1',

lc_pdf TYPE char3 VALUE 'PDF',

lc_raw TYPE char3 VALUE 'RAW',

lc_ordform TYPE char15 VALUE 'ZORDCONFIRM_01',

lc_attachment TYPE char10 VALUE 'ATTACHMENT'.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = lc_pdf

max_linewidth = 132

IMPORTING

bin_filesize = lv_filesize

TABLES

otf = pv_otfdata

lines = li_pdfdata

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.

LOOP AT li_pdfdata INTO lwa_pdfdata.

TRANSLATE lwa_pdfdata USING ' ~'.

CONCATENATE lv_buffer lwa_pdfdata INTO lv_buffer.

CLEAR lwa_pdfdata.

ENDLOOP.

TRANSLATE lv_buffer USING '~ '.

DO.

lwa_mess_att = lv_buffer.

APPEND lwa_mess_att TO li_mess_att.

CLEAR lwa_mess_att.

SHIFT lv_buffer LEFT BY 255 PLACES.

IF lv_buffer IS INITIAL.

EXIT.

ENDIF.

ENDDO.

  • Object with PDF.

REFRESH li_objbin.

li_objbin[] = li_mess_att[].

DESCRIBE TABLE li_objbin LINES lv_attachment.

  • Object with main text of the mail.

lwa_objtxt = space.

APPEND lwa_objtxt TO li_objtxt.

CLEAR lwa_objtxt.

DESCRIBE TABLE li_objtxt LINES lv_testo.

  • Create the document which is to be sent

lwa_doc_chng-obj_name = text-008.

lwa_doc_chng-obj_descr = text-008.

lwa_doc_chng-sensitivty = lc_0.

lwa_doc_chng-obj_prio = lc_1.

lwa_doc_chng-doc_size = lv_testo * 225.

  • Pack to main body.

CLEAR lwa_objpack-transf_bin.

  • header

lwa_objpack-head_start = 1.

  • The document needs no header (head_num = 0)

lwa_objpack-head_num = 0.

  • body

lwa_objpack-body_start = 1.

lwa_objpack-body_num = lv_testo.

lwa_objpack-doc_type = lc_raw.

APPEND lwa_objpack TO li_objpack.

CLEAR lwa_objpack.

  • Create the attachment.

  • Fill the fields of the packing_list for the attachment:

lwa_objpack-transf_bin = gc_x .

  • header

lwa_objpack-head_start = 1.

lwa_objpack-head_num = 1.

  • body

lwa_objpack-body_start = 1.

lwa_objpack-body_num = lv_attachment.

lwa_objpack-doc_type = lc_pdf.

lwa_objpack-obj_name = lc_attachment.

lwa_objpack-obj_descr = text-008.

lwa_objpack-doc_size = lv_attachment * 255.

APPEND lwa_objpack TO li_objpack.

CLEAR lwa_objpack.

lwa_reclist-receiver = pv_emailid.

lwa_reclist-rec_type = lc_u.

lwa_reclist-notif_del = gc_x.

lwa_reclist-notif_ndel = gc_x.

APPEND lwa_reclist TO li_reclist.

IF li_reclist IS NOT INITIAL.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = lwa_doc_chng

put_in_outbox = gc_x

TABLES

packing_list = li_objpack

object_header = li_objhead

contents_bin = li_objbin

contents_txt = li_objtxt

receivers = li_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.

  • MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno

  • WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDIF.

ENDFORM. " DOCU_SEND_EMAIL

Read only

0 Likes
1,176

Hi,experts

I still have problem with build file excel,

I work with SAP 4.6 and this code doesn't work correctly ,

I still get all of data in first tab.

Thank's,

Tatiana

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,177

>

> \[...\] FM insert all data \[...\] in first tab of file Excel and don't disperse it \[...\]

What is your original excel file format ? (when attached to the email)

1) have a Comma-Separated Values format (can be opened via notepad for example),

2) or is it a true excel file which contains several sheets ?

3) or is it just that you have a CSV file and all columns appear in the first column ?

If it's case 1), it's normal.

If it's case 2), I don't understand how it's possible to have all sheets merged into the first sheet !

If it's case 3), it's a normal excel function. When you open the file, excel normally detects file format is text (CSV) and asks the user if he wants to expand the columns, or not, and asks what character is the column separator (comma, pipe, tab, etc.) The user may also choose to expand the columns later, there is a menu in excel to do that.