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

CSV attachment via BCS classes

rainer_hbenthal
Active Contributor
0 Likes
4,769

I'm sending CSV data as an attachment via the BCS

i'm converting the csv data via

try.
      cl_bcs_convert=>string_to_solix(
        exporting
          iv_string   = text_content
          iv_codepage = '4103'  "suitable for MS Excel, leave empty
          iv_add_bom  = 'X'     "for other doc types
        importing
          et_solix  = binary_content
          ev_size   = size ).
    catch cx_bcs.
      message e445(so).
  endtry.

and add this with

document->add_attachment(
    i_attachment_type    = 'xls'                        "#EC NOTEXT
    i_attachment_subject = fname                        "#EC NOTEXT
    i_attachment_size    = size
    i_att_content_hex    = binary_content ).

Excel 2007 is now complaining that the extension does not match the file type, but is opening the file correctly. As i dont wanna have this complaining message, i changed the attachment type to csv. But now, the semicolon is not recognized and the wohle content is placed into column a with the semicolon left in the string. changing the delimiter to tab does not help.

How can i set the parameters in converting and attaching so that Excel 2007 is not complaining AND opens the attachment correct?

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,878

I think i found out why this is causing the problem. The when you open the attachment, the name goes something like this:

<Value in i_attachment_subject> + '_' + Date-Time Stamp + '.' + <Some Number> + '_' + 'X' + '.xls'

e.g., Myattachment_20100711050424.435_X.xls

I am not able to figure it out how to suppress the garbage characters in the filename. Will post if i find anything.

BR,

Suhas

4 REPLIES 4
Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
1,878

This sounds vaguely familiar... I haven't worked with BCS but when working with workflow attachments I had to use some secret combination to pass the file name:

* Object header
CONCATENATE '&SO_FILENAME=' lv_filename INTO wa_content
APPEND wa_content TO it_objhead.

CALL FUNCTION 'SO_OBJECT_INSERT'
EXPORTING
folder_id = ls_fol_id
object_type = 'EXT'
object_hd_change = ls_obj_data
IMPORTING
object_id = ls_obj_id
TABLES
objhead = it_objhead
objcont = it_content.

Maybe something along these lines might help?

[Source|http://friendlyabaper.blogspot.com/2009/12/office-2007-and-secret-handshake.html]

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,878

Though you tested it, I've got no issue with UTF-16LE (4103) and horizontal tabulation, which are the ones recommended, even though it's CSV. My test was with business workplace (there's no reason that it shouldn't work with internet mail), and Excel 2007 SP2, locale France.

(inspired from BCS_EXAMPLE_5)


REPORT bcs_example_5.
DATA: send_request       TYPE REF TO cl_bcs.
DATA: text               TYPE bcsy_text.
DATA: text_content       TYPE string.
DATA: size               TYPE so_obj_len.
DATA: binary_content     TYPE solix_tab.
DATA: document           TYPE REF TO cl_document_bcs.
DATA: sender             TYPE REF TO cl_sapuser_bcs.
DATA: recipient          TYPE REF TO if_recipient_bcs.
DATA: bcs_exception      TYPE REF TO cx_bcs.
TRY.
    send_request = cl_bcs=>create_persistent( ).
    APPEND 'Hello world!' TO text. "body
    document = cl_document_bcs=>create_document(
                    i_type    = 'RAW'
                    i_text    = text
                    i_length  = '12'
                    i_subject = 'test created by BCS_EXAMPLE_5' ).
    CONCATENATE
    'aaa'
    cl_abap_char_utilities=>horizontal_tab
    'bbb'
    INTO text_content.
    TRY.
        cl_bcs_convert=>string_to_solix(
          EXPORTING
            iv_string   = text_content
            iv_codepage = '4103'  "suitable for MS Excel, leave empty
            iv_add_bom  = 'X'     "for other doc types
          IMPORTING
            et_solix  = binary_content
            ev_size   = size ).
      CATCH cx_bcs.
        MESSAGE e445(so).
    ENDTRY.
    document->add_attachment(
        i_attachment_type    = 'csv'                        "#EC NOTEXT
        i_attachment_subject = 'My attachment'              "#EC NOTEXT
        i_attachment_size    = size
        i_att_content_hex    = binary_content ).
    CALL METHOD send_request->set_document( document ).
    sender = cl_sapuser_bcs=>create( sy-uname ).
    CALL METHOD send_request->set_sender
      EXPORTING
        i_sender = sender.
    recipient = cl_sapuser_bcs=>create(
          i_user = sy-uname ).
    CALL METHOD send_request->add_recipient
      EXPORTING
        i_recipient = recipient.
    CALL METHOD send_request->send( ).
    COMMIT WORK.
  CATCH cx_bcs INTO bcs_exception.
    WRITE: 'Error:', bcs_exception->error_type.
ENDTRY.

Read only

0 Likes
1,878

Nice answer ! Thank you for sharing.

Have a nice day.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,879

I think i found out why this is causing the problem. The when you open the attachment, the name goes something like this:

<Value in i_attachment_subject> + '_' + Date-Time Stamp + '.' + <Some Number> + '_' + 'X' + '.xls'

e.g., Myattachment_20100711050424.435_X.xls

I am not able to figure it out how to suppress the garbage characters in the filename. Will post if i find anything.

BR,

Suhas