2013 Apr 09 9:33 AM
Hi Guys,
I'm using METHOD cl_bcs_convert=>string_to_solix to convert my strint to binary so that I can use it in METHOD document->add_attachment
TYPES: BEGIN OF gty_data,
col1 TYPE c LENGTH 10,
col2 TYPE c LENGTH 10,
col3 TYPE c LENGTH 10,
END OF gty_data.
DATA: gwa_data TYPE gty_data.
DATA: gt_data TYPE STANDARD TABLE OF gty_data.
gwa_data-col1 = 'FirstName'.
gwa_data-col2 = 'MName'.
gwa_data-col3 = 'LastName'.
APPEND gwa_data TO gt_data.
CLEAR: gwa_data.
gwa_data-col1 = 'First'.
gwa_data-col2 = 'M'.
gwa_data-col3 = 'Last'.
APPEND gwa_data TO gt_data.
LOOP AT gt_data INTO gwa_data.
CONCATENATE gwa_data-col1 gwa_data-col2 gwa_data-col3 INTO lv_string SEPARATED BY lc_tabdel.
CLEAR: gwa_data.
TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = lv_string
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) INTO lv_message .
ENDTRY.
ENDLOOP.
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = 'XLS'
i_attachment_subject = 'My attachment2'
i_att_content_hex = binary_content.
How ever my file attachment always contain the last row of my internal table gt_data.
How can I pass all the values of my internal table to binary_content?
2013 Apr 09 9:46 AM
LOOP AT gt_data INTO gwa_data.
CONCATENATE gwa_data-col1 data-col2 gwa_data col3 INTO lv_string SEPERATED BY lc_tabdel.
ENDLOOP.
Hi Guys,
I'm using METHOD cl_bcs_convert=>string_to_solix to convert my strint to binary so that I can use it in METHOD document->add_attachment
TYPES: BEGIN OF gty_data,
col1 TYPE c LENGTH 10,
col2 TYPE c LENGTH 10,
col3 TYPE c LENGTH 10,
END OF gty_data.
DATA: gwa_data TYPE gty_data.
DATA: gt_data TYPE STANDARD TABLE OF gty_data.
gwa_data-col1 = 'FirstName'.
gwa_data-col2 = 'MName'.
gwa_data-col3 = 'LastName'.
APPEND gwa_data TO gt_data.
CLEAR: gwa_data.
gwa_data-col1 = 'First'.
gwa_data-col2 = 'M'.
gwa_data-col3 = 'Last'.
APPEND gwa_data TO gt_data.
LOOP AT gt_data INTO gwa_data.
CONCATENATE gwa_data-col1 gwa_data-col2 gwa_data-col3 INTO lv_string SEPARATED BY lc_tabdel.
CLEAR: gwa_data.
TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = lv_string
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) INTO lv_message .
ENDTRY.
ENDLOOP.
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = 'XLS'
i_attachment_subject = 'My attachment2'
i_att_content_hex = binary_content.
How ever my file attachment always contain the last row of my internal table gt_data.
How can I pass all the values of my internal table to binary_content?
2013 Apr 09 9:46 AM
LOOP AT gt_data INTO gwa_data.
CONCATENATE gwa_data-col1 data-col2 gwa_data col3 INTO lv_string SEPERATED BY lc_tabdel.
ENDLOOP.
2013 Apr 09 9:53 AM
Your suggestion will not work: it will only get the last row of my internal table.
LOOP AT gt_data INTO gwa_data.
CONCATENATE gwa_data-col1 gwa_data-col2 gwa_data-col3 INTO lv_string SEPARATED BY lc_tabdel.
CLEAR: gwa_data.
ENDLOOP.
TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = lv_string
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) INTO lv_message .
ENDTRY.
2013 Apr 09 10:05 AM
Hi Jun,
My reply got posted even before I completed it. Sorry for the inconvenience.
here is my idea of solution to the problem.
Inside the loop at gt_data, you are just concatenating data into lv_string and you are not appending it. As a result, after the loop execution lv_string variable will have only the data of last entry. So to avoid this, you can append data of lv_string into another string inside the loop. Use the newly created variable to create the attachment. Below is the sample code.
DATA : lv_string2 type string.
CLEAR lv_string2.
LOOP AT gt_data INTO gwa_data.
CONCATENATE gwa_data-col1 gwa_data-col2 gwa_data-col3 INTO lv_string SEPARATED BY lc_tabdel.
CONCATENATE lv_string2 lv_string INTO lv_string2.
CLEAR: gwa_data.
ENDLOOP.
TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = lv_string2
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) INTO lv_message .
ENDTRY.
Hope this helps,
~Athreya
2013 Apr 09 10:17 AM
Hi Athreya Hegde,
Thanks for your reply but the code will not work...
APPEND lv_string TO lv_string2. --> Will lead to Error since lv_string2 is not internal table
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = lv_string2 --> will lead to error, iv_string is meant for flat string only
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) INTO lv_message .
ENDTRY.
2013 Apr 09 10:29 AM
Hi,
I have edited my reply. Please take a look at the changes done.
~Athreya
2013 Apr 09 10:39 AM
Still no luck.
---------------
Full Code:
---------------
REPORT ysend_email.
* This example shows how to send
* - a simple text provided in an internal table of text lines
* - and an attached MS word document provided in internal table
* - to some internet email address.
*
* All activities done via facade CL_BCS!
DATA: send_request TYPE REF TO cl_bcs.
DATA: text TYPE bcsy_text.
DATA: binary_content TYPE solix_tab.
DATA: binary_content2 TYPE solix_tab.
DATA: document TYPE REF TO cl_document_bcs.
DATA: sender TYPE REF TO cl_sapuser_bcs.
DATA: custom_sender TYPE REF TO cl_cam_address_bcs.
DATA: lo_sender TYPE REF TO if_sender_bcs.
DATA: convert TYPE REF TO cl_bcs_convert.
DATA: recipient TYPE REF TO if_recipient_bcs.
DATA: bcs_exception TYPE REF TO cx_bcs.
DATA: sent_to_all TYPE os_boolean.
TYPES: BEGIN OF gty_data,
col1 TYPE c LENGTH 10,
col2 TYPE c LENGTH 10,
col3 TYPE c LENGTH 10,
END OF gty_data.
DATA: gwa_data TYPE gty_data.
DATA: gt_data TYPE STANDARD TABLE OF gty_data.
START-OF-SELECTION.
PERFORM main.
*---------------------------------------------------------------------*
* FORM main *
*---------------------------------------------------------------------*
FORM main.
TRY.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document with attachment ---------------
* create document from internal table with text
APPEND 'Hello world!' TO text.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = text
i_length = '12'
i_subject = 'Test Immediate' ).
* add attachment to document
* BCS expects document content here e.g. from document upload
* binary_content = ...
gwa_data-col1 = 'FirstName'.
gwa_data-col2 = 'MName'.
gwa_data-col3 = 'LastName'.
APPEND gwa_data TO gt_data.
CLEAR: gwa_data.
gwa_data-col1 = 'First'.
gwa_data-col2 = 'Middle'.
gwa_data-col3 = 'Last'.
APPEND gwa_data TO gt_data.
CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode
con_tab TYPE x VALUE '09'. "OK for non Unicode
DATA: lv_string TYPE string.
DATA: lv_string2 TYPE string.
DATA: size TYPE so_obj_len,
lv_message TYPE string.
CONSTANTS: lc_tabdel TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
lc_newline TYPE c VALUE cl_abap_char_utilities=>newline.
DATA: lv_str_line LIKE solix-line.
LOOP AT gt_data INTO gwa_data.
CONCATENATE gwa_data-col1 gwa_data-col2 gwa_data-col3 INTO lv_string SEPARATED BY lc_tabdel.
CONCATENATE lv_string2 lv_string INTO lv_string2.
CLEAR: gwa_data.
ENDLOOP.
TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = lv_string2
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) INTO lv_message .
ENDTRY.
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = 'XLS'
i_attachment_subject = 'My attachment2'
i_att_content_hex = binary_content.
* add document to send request
CALL METHOD send_request->set_document( document ).
* --------- set sender -------------------------------------------
* note: this is necessary only if you want to set the sender
* different from actual user (SY-UNAME). Otherwise sender is
* set automatically with actual user.
sender = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
* --------- add recipient (e-mail address) -----------------------
* create recipient - please replace e-mail address !!!
recipient = cl_cam_address_bcs=>create_internet_address(
'[email protected]' ).
* add recipient with its respective attributes to send request
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
send_request->set_send_immediately( 'X' ).
* ---------- send document ---------------------------------------
CALL METHOD send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
IF sent_to_all = 'X'.
WRITE text-003.
ENDIF.
COMMIT WORK.
* -----------------------------------------------------------
* * exception handling
* -----------------------------------------------------------
* * replace this very rudimentary exception handling
* * with your own one !!!
* -----------------------------------------------------------
CATCH cx_bcs INTO bcs_exception.
WRITE: 'Fehler aufgetreten.'(001).
WRITE: 'Fehlertyp:'(002), bcs_exception->error_type.
EXIT.
ENDTRY.
ENDFORM. "main
2013 Apr 09 11:21 AM
Hi Jun,
I checked the code and there is one place you need to change. Below is the changes to be done in LOOP processing.
LOOP AT gt_data INTO gwa_data.
CONCATENATE gwa_data-col1 gwa_data-col2 gwa_data-col3 INTO lv_string SEPARATED BY lc_tabdel.
IF sy-tabix EQ 1.
CONCATENATE lv_string2 lv_string INTO lv_string2.
ELSE.
CONCATENATE lv_string2 lv_string INTO lv_string2 SEPARATED BY lc_newline.
ENDIF.
CLEAR: gwa_data.
ENDLOOP.
I have made the changes and tested it. Its working now and the excelattachment has two entries in it. Try it from your end and see if works fine.
~Athreya
2013 Apr 09 4:53 PM
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |