2008 Aug 04 11:33 PM
Hi,
I have a requirement to send the details of an internal table to External mail as an attachment. I have used fn.module 'SO_NEW_DOCUMENT_ATT_SEND_API1' to do so. I am getting the attachment but the data is stored in only one row when we checked it in SAP outbox. This is irrespective of TXT, XLS etc. I can not check the exact file in my external mail inbox as the connection is not established in dev & Quality systems. This question was raised earlier by other guys and there was no correct answer provided. If any of you encountered this type of problem & got the solution please help.
Thanks,
Ashok
Hi,
I have a requirement to send the details of an internal table to External mail as an attachment. I have used fn.module 'SO_NEW_DOCUMENT_ATT_SEND_API1' to do so. I am getting the attachment but the data is stored in only one row when we checked it in SAP outbox. This is irrespective of TXT, XLS etc. I can not check the exact file in my external mail inbox as the connection is not established in dev & Quality systems. This question was raised earlier by other guys and there was no correct answer provided. If any of you encountered this type of problem & got the solution please help.
Thanks,
Ashok
2008 Aug 05 2:17 AM
You need to add the New line indicator after each record of your internal table.
Like:
LOOP AT ITAB.
MOVE ITAB TO OBJ_ATTACH
APPEND OBJ_ATTACH
MOVE CL_ABAP_CHAR_UTILITIES=>NEWLINE TO OBJ_ATTACH.
APPEND OBJ_ATTACH.
ENDLOOP.
Regards,
Naimesh Patel
2008 Aug 05 4:02 AM
Hi Buddy,
Hope this piece of code will definately help you out, Its working at my end.
Thanks,
Krishna..
FORM p_send_email .
FIELD-SYMBOLS: <field> TYPE ANY.
DATA : BEGIN OF i_dload OCCURS 0 ,
dload(1000) ,
END OF i_dload .
DATA: it_receivers LIKE somlreci1 OCCURS 1 WITH HEADER LINE,
w_object_content LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: w_doc_data LIKE sodocchgi1 OCCURS 0 WITH HEADER LINE.
DATA :w_records TYPE zres_records.
DATA: w_rsnum(10),
w_bdmng(14),
w_meins(4).
DATA: ws_email LIKE adr6-smtp_addr. "for internal e_mail address
DATA: ws_email1 LIKE adr6-smtp_addr. "for external e_mail address
*--Internal table declaration
DATA: it_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: it_objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: it_objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: it_objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: it_reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
DATA: doc_chng LIKE sodocchgi1.
DATA: tab_lines LIKE sy-tabix.
DATA: w_longtext(500) TYPE c.
DATA: v_date(10) TYPE c.
DATA: text(200) TYPE c.
DATA: w_text(50) TYPE c.
*--Get receipient address
CLEAR it_reclist.
*--To send error to internal mail
ws_email = p_email.
*--To send error to external mail
ws_email1 = p_email1.
*---setting name of file for csv
CONCATENATE text-003 p_bdoc text-004 INTO w_filename.
CONDENSE w_filename NO-GAPS.
IF flag <> 1.
IF p_email1 IS NOT INITIAL.
build body of message
CONCATENATE 'disply message ' ' ' INTO it_objtxt
SEPARATED BY space.
APPEND it_objtxt.
CLEAR it_objtxt.
it_reclist-receiver = ws_email1.
it_reclist-rec_type = c_u.
it_reclist-express = ' '.
it_reclist-com_type = 'INT'.
APPEND it_reclist.
Set title of object and email
CLEAR: w_text.
CONCATENATE 'Greenheck Packing List Data'
INTO w_text SEPARATED BY space.
doc_chng-obj_descr = text-005. "w_text.
doc_chng-obj_name = 'Inbound EDI'.
DESCRIBE TABLE it_objtxt LINES tab_lines.
READ TABLE it_objtxt INDEX tab_lines.
doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_objtxt ).
*--Move the Report Name as the Heading line for email file
CLEAR: w_longtext.
MOVE: text-012 TO w_longtext.
w_longtext = 'name of report for testing'.
it_objbin = w_longtext.
APPEND it_objbin. CLEAR it_objbin.
*--Append Blank Lines
APPEND it_objbin. CLEAR it_objbin.
APPEND it_objbin. CLEAR it_objbin.
*User name
CLEAR text.
MOVE: 'User:' TO text,
sy-uname TO text+6.
it_objbin = text.
APPEND it_objbin. CLEAR it_objbin.
---appending heading to Internal table of Email
CLEAR: w_longtext, w_xblnr_1 , w_aubel_1, w_vemng_1,
w_matnr_1, w_harmdesc_1, w_hc_1, w_cooland1_1,
w_brgew_1, w_tknum_1, w_vbeln_1, w_vbeln1_1,
w_exidv_1, w_vhilm_1, w_pack_no_1,
w_brgew1_1, w_laeng_1, w_breit_1,
w_hoehe_1, w_vol_1.
w_xblnr_1 = 'Cust PO No.'.
w_aubel_1 = 'Sal Order'.
w_vemng_1 = 'Pack Qty'.
w_matnr_1 = 'Model no.'.
w_harmdesc_1 = 'Hrm Desc'.
w_hc_1 = 'Hrm Code'.
w_cooland1_1 = 'Country of Origin'.
w_brgew_1 = 'Net Wt.'.
w_tknum_1 = 'Shipment'.
w_vbeln_1 = 'Billing Doc'.
w_vbeln1_1 = 'Delivery'.
w_exidv_1 = 'Pkg ID'.
w_vhilm_1 = 'Pkg Desc'.
w_pack_no_1 = 'Pkg No.'.
w_brgew1_1 = 'Gross Wt'.
w_laeng_1 = 'Length'.
w_breit_1 = 'Width'.
w_hoehe_1 = 'Height'.
w_vol_1 = 'Cubic Mtr'.
CONCATENATE w_xblnr_1 w_aubel_1 w_vemng_1
w_matnr_1 w_harmdesc_1 w_hc_1 w_cooland1_1
w_brgew_1 w_tknum_1 w_vbeln_1 w_vbeln1_1
w_exidv_1 w_vhilm_1 w_pack_no_1
w_brgew1_1 w_laeng_1 w_breit_1
w_hoehe_1 w_vol_1
INTO w_longtext SEPARATED BY ','.
it_objbin = w_longtext.
APPEND it_objbin. CLEAR it_objbin.
LOOP AT it_tab.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE it_tab TO <field>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
Look for Commas in the field value. If it exists, put quotes around
value so that the file opens correctly with all the columns aligned
in Excel.
SEARCH <field> FOR ',' IN CHARACTER MODE.
If search for commas was successful.
IF sy-subrc = 0.
CONCATENATE '"' <field> '"' INTO <field> IN CHARACTER MODE.
ENDIF.
IF sy-index = 1.
i_dload-dload = <field>.
SHIFT: i_dload-dload LEFT DELETING LEADING space.
ELSE.
Put Comma as a separator for values in IT_DLOAD internal table
SHIFT: i_dload-dload LEFT DELETING LEADING space.
CONCATENATE i_dload-dload <field> INTO i_dload-dload
SEPARATED BY ',' IN CHARACTER MODE.
ENDIF.
ENDDO.
it_objbin = i_dload-dload.
APPEND it_objbin. CLEAR it_objbin.
ENDLOOP.
flag = 1.
endif.
ENDIF.
---if to send error file.
IF p_email IS NOT INITIAL.
build body of message
CONCATENATE 'Errors in file ' ' ' INTO it_objtxt
SEPARATED BY space.
APPEND it_objtxt.
CLEAR it_objtxt.
it_reclist-receiver = ws_email.
it_reclist-rec_type = c_u.
it_reclist-express = ' '.
it_reclist-com_type = 'INT'.
APPEND it_reclist.
Set title of object and email
CLEAR: w_text.
CONCATENATE 'Greenheck Packing List Data'
INTO w_text SEPARATED BY space.
doc_chng-obj_descr = text-005.
doc_chng-obj_name = 'Inbound EDI'.
DESCRIBE TABLE it_objtxt LINES tab_lines.
READ TABLE it_objtxt INDEX tab_lines.
doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_objtxt ).
*--Move the Report Name as the Heading line for email file
CLEAR: w_longtext.
MOVE: text-012 TO w_longtext.
w_longtext = 'name of report for testing'.
it_objbin = w_longtext.
APPEND it_objbin. CLEAR it_objbin.
*--Append Blank Lines
APPEND it_objbin. CLEAR it_objbin.
APPEND it_objbin. CLEAR it_objbin.
*User name
CLEAR text.
MOVE: 'User:' TO text,
sy-uname TO text+6.
it_objbin = text.
APPEND it_objbin. CLEAR it_objbin.
---appending heading to Internal table of Email
CLEAR: w_longtext, w_xblnr_1 , w_aubel_1, w_vemng_1,
w_matnr_1, w_harmdesc_1, w_hc_1, w_cooland1_1,
w_brgew_1, w_tknum_1, w_vbeln_1, w_vbeln1_1,
w_exidv_1, w_vhilm_1, w_pack_no_1,
w_brgew1_1, w_laeng_1, w_breit_1,
w_hoehe_1, w_vol_1, w_error.
w_xblnr_1 = 'Cust PO No.'.
w_aubel_1 = 'Sal Order'.
w_vemng_1 = 'Pack Qty'.
w_matnr_1 = 'Model no.'.
w_harmdesc_1 = 'Hrm Desc'.
w_hc_1 = 'Hrm Code'.
w_cooland1_1 = 'Counrty of Origin'.
w_brgew_1 = 'Net Wt.'.
w_tknum_1 = 'Shipment'.
w_vbeln_1 = 'Billing doc'.
w_vbeln1_1 = 'Delivery'.
w_exidv_1 = 'Pkg ID'.
w_vhilm_1 = 'Pkg Desc'.
w_pack_no_1 = 'Pkg No.'.
w_brgew1_1 = 'Gross Wt'.
w_laeng_1 = 'Length'.
w_breit_1 = 'Width'.
w_hoehe_1 = 'Height'.
w_vol_1 = 'Cubic Mtr'.
w_error = 'Error'.
CONCATENATE w_xblnr_1 w_aubel_1 w_vemng_1
w_matnr_1 w_harmdesc_1 w_hc_1 w_cooland1_1
w_brgew_1 w_tknum_1 w_vbeln_1 w_vbeln1_1
w_exidv_1 w_vhilm_1 w_pack_no_1
w_brgew1_1 w_laeng_1 w_breit_1
w_hoehe_1 w_vol_1 w_error
INTO w_longtext SEPARATED BY ','.
it_objbin = w_longtext.
APPEND it_objbin. CLEAR it_objbin.
*--Append the details to Internal table of Email
LOOP AT it_tab.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE it_tab TO <field>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
Look for Commas in the field value. If it exists, put quotes around
value so that the file opens correctly with all the columns aligned
in Excel.
SEARCH <field> FOR ',' IN CHARACTER MODE.
If search for commas was successful.
IF sy-subrc = 0.
CONCATENATE '"' <field> '"' INTO <field> IN CHARACTER MODE.
ENDIF.
IF sy-index = 1.
i_dload-dload = <field>.
SHIFT: i_dload-dload LEFT DELETING LEADING space.
ELSE.
Put Comma as a separator for values in IT_DLOAD internal table
SHIFT: i_dload-dload LEFT DELETING LEADING space.
CONCATENATE i_dload-dload <field> INTO i_dload-dload
SEPARATED BY ',' IN CHARACTER MODE.
ENDIF.
ENDDO.
it_objbin = i_dload-dload.
APPEND it_objbin. CLEAR it_objbin.
ENDLOOP.
flag = 0.
endif.
-Convert to correct format----
CALL FUNCTION 'SO_RAW_TO_RTF'
TABLES
objcont_old = it_objbin
objcont_new = it_objbin.
create the control table entry for the main email
DESCRIBE TABLE it_objtxt LINES tab_lines.
CLEAR it_objpack-transf_bin.
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 = 'RAW'.
APPEND it_objpack.
DESCRIBE TABLE it_objbin LINES tab_lines.
it_objpack-head_start = 1.
it_objpack-head_num = 0.
it_objpack-body_start = 1.
it_objpack-body_num = tab_lines.
it_objpack-transf_bin = c_x.
it_objpack-doc_type = 'CSV'.
it_objpack-obj_descr = w_filename. "'billing doc no.csv'.
it_objpack-obj_name = 'Billing Doc'.
it_objpack-doc_size = tab_lines * 255.
APPEND it_objpack.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc_chng
PUT_IN_OUTBOX = c_x
commit_work = c_x
TABLES
packing_list = it_objpack
object_header = it_objhead
contents_bin = it_objbin
contents_txt = it_objtxt
receivers = it_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
IF sy-subrc <> 0.
WRITE: / 'failure in sending mail'.
ELSE.
if flag = 0.
MESSAGE s999(pp) WITH text-007.
endif.
if flag = 1.
MESSAGE s999(pp) WITH text-006.
endif.
WRITE: / 'success in sending mail'.
ENDIF.
ENDFORM. " p_send_email
2008 Aug 29 11:57 PM