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

SO_NEW_DOCUMENT_ATT_SEND_API1 - xml

Former Member
0 Likes
3,693

hi All,

kindly advise, i saw many posting on this function, but i cannot find the topic about "doc_type" ?

I am trying to generated the attachment as XML, and sent out in an email.

*-Prepare OBJPACK for the ATTACHMENT1----


DESCRIBE TABLE attachment1 LINES tab_lines.

READ TABLE attachment1 INDEX tab_lines.

objpack-doc_size = ( tab_lines - 1 ) * 255

+ STRLEN( attachment1 ).

CLEAR objpack-transf_bin.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = LINES( mailbody ) + 1 .

objpack-body_num = tab_lines.

objpack-doc_type = 'RAW'.

  • objpack-doc_type = 'xml'.

objpack-obj_descr = "myfile".

APPEND objpack.

when i use above codes, the attachment file name become "myfile.txt", but the file content is correct.

Each line there is linefeed, the length of each line varies with the content. Filesize is small.

when i change it to:

objpack-doc_type = 'XML'.

the attachement file name become "myfile.XML".

But file content is wrong. There is not linefeed for each line. Line2 is immediately append after line1. Each line's length is 255. Filesize is huge, due to those excess spaces.

I cannot send a "myfile.txt" to customer, asking him to change the extension back to ".xml".

Thanks in advance.

regards

Ee Siong

1 ACCEPTED SOLUTION
Read only

athavanraja
Active Contributor
0 Likes
3,041

i think the issue is with unicode. can you try this code.

*&---------------------------------------------------------------------*
*& Report  Y_TEST_XML_ATT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  y_test_xml_att.
DATA: xml_string TYPE string .
DATA: send_request TYPE REF TO cl_bcs.
DATA: text TYPE bcsy_text ,
text1 TYPE bcsy_text ,
text2 TYPE bcsy_text WITH HEADER LINE.
DATA: xtext TYPE STANDARD TABLE OF solix .
DATA: document TYPE REF TO cl_document_bcs.
DATA: sender TYPE REF TO if_sender_bcs.
DATA: recipient TYPE REF TO if_recipient_bcs.
DATA: bcs_exception TYPE REF TO cx_bcs.
DATA: sent_to_all TYPE os_boolean.
DATA: conlength TYPE i ,
conlengths TYPE so_obj_len ,
result_content TYPE string .
* subject TYPE so_obj_des .
DATA: e_r_page TYPE REF TO cl_rsr_www_page.
DATA: content_length TYPE w3param-cont_len ,
content_type TYPE w3param-cont_type,
return_code TYPE w3param-ret_code .

DATA: html TYPE STANDARD TABLE OF w3html .
DATA: server TYPE string ,
port TYPE string .
DATA: wa_rec TYPE ad_smtpadr .
DATA: bcs_message TYPE string .
DATA: binary_content TYPE solix_tab.
DATA: xl_content TYPE xstring .
DATA: atta_sub TYPE sood-objdes ,
      app_type(50) .
data: len type sood-objlen ,
      length type  i .
CLEAR xml_string .


CONCATENATE
 `<?xml version="1.0" encoding="utf-8" ?>`
`<XOEINSUR_04OCT2006>`
    `<order>`
        `<item1>apple</item1>`
        `<qty>10</qty>`
    `</order>`
    `<order>`
        `<item1>orange</item1>`
        `<qty>20</qty>`
    `</order>`
`</XOEINSUR_04OCT2006>`
INTO xml_string separated by CL_ABAP_CHAR_UTILITIES=>CR_LF .

app_type = 'text/xml; charset=utf-8'.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
  EXPORTING
    text     = xml_string
    mimetype = app_type
  IMPORTING
    buffer   = xl_content.


CONCATENATE  cl_abap_char_utilities=>byte_order_mark_utf8
             xl_content
             INTO xl_content IN BYTE MODE.
REFRESH binary_content .
clear:len, length .
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
  EXPORTING
    buffer     = xl_content
  importing
  OUTPUT_LENGTH = length
  TABLES
    binary_tab = binary_content.
move: length to len .

TRY.
    CLEAR send_request .

    send_request = cl_bcs=>create_persistent( ).

    CLEAR document .
    APPEND 'Test' TO text1 .
    document = cl_document_bcs=>create_document(
    i_type = 'HTM'
    i_text = text1
    i_subject = 'Test' ).

    atta_sub = 'myxmlfile' .
    CALL METHOD document->add_attachment
      EXPORTING
        i_attachment_type    = 'xml'
        i_attachment_subject = atta_sub
        I_ATTACHMENT_SIZE    = len
        i_att_content_hex    = binary_content.


* add document to send request
    CALL METHOD send_request->set_document( document ).

    CLEAR sender .
    sender = cl_cam_address_bcs=>create_internet_address( 'sender@yahoo.com' ).
    CALL METHOD send_request->set_sender
      EXPORTING
        i_sender = sender.

    recipient = cl_cam_address_bcs=>create_internet_address( 'receiver@yahoo.com' ).

* add recipient with its respective attributes to send request
    CALL METHOD send_request->add_recipient
      EXPORTING
        i_recipient = recipient
        i_express   = 'X'.
    CALL METHOD send_request->set_status_attributes
      EXPORTING
        i_requested_status = 'E'
        i_status_mail      = 'E'.

    CALL METHOD 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:/ 'Mail sent successfully '.
      WRITE:/ xml_string .

      text2[] = text[].
      LOOP AT text2.
        WRITE:/ text2-line .
      ENDLOOP.
    ENDIF.

    COMMIT WORK.

  CATCH cx_bcs INTO bcs_exception.
    bcs_message = bcs_exception->get_text( ).
    WRITE:/ bcs_message .
    EXIT.

ENDTRY.

Regards

Raja

33 REPLIES 33
Read only

anversha_s
Active Contributor
0 Likes
3,041

hi,

use this function to convert to xml format.

SAP_CONVERT_TO_XML_FORMAT

thenn send it it using email FM.

rgds

anver

if hlpe mark points

Read only

amit_khare
Active Contributor
0 Likes
3,041

Hi,

check this Forum link.

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/collaboration">https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/collaboration</a>

Regards,

Amit

Read only

Former Member
0 Likes
3,041

I was hoping someone will tell me objpack-doc_type can continue to be 'RAW', with the filename ending with any extension that the programmer specified.

Read only

Former Member
0 Likes
3,041

Hi Ee Siong,

Check with the following Classes

CL_APL_ECATT_WDR_GEN_XML-Superclass for Generation of XML

CL_APL_ECATT_XML -eCATT Basis iXML Wrapper Class

Hope this could help you.

Thanks,

Prashanth

Read only

0 Likes
3,041

if you on WAS6.10 or above its quiet simple to manipulate the file extension and email with cl_bcs classes. let me know if you need help with this.

Regards

Raja

Read only

0 Likes
3,041

hi Raja, i only know i m on ECC5.0, can i use the feature u mentioned ? how to do it ?

regards

Ee Siong

Read only

0 Likes
3,041

yes you can use it.

check this thread for code sample.

Regards

Raja

Read only

0 Likes
3,041

hi Raja / everyone.

sorry if i asked a silly questions, caused i try to follow this "/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface to create the function, but it din compile correctly.

when i try to looking into the domains for something like ZES*, I cannot find any, does it mean my SAP installation/setup does not permit me to use cl_bcs to send emails ?

Read only

0 Likes
3,041

ZES* are custom objects which the weblog author (Thomas Jung) had developed , for which he has given screen shots. for your scenario, you dont need to develope all of them.

may be check my code samples using cl_bcs that may give you some idea.

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5931ff64-0a01-0010-2bb7-ff2...

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/7f601a65-0a01-0010-16a5-c36...

also check out the demo programs in the system

BCS_EXAMPLE_1

BCS_EXAMPLE_2

BCS_EXAMPLE_3

BCS_EXAMPLE_4

BCS_EXAMPLE_5

BCS_EXAMPLE_6

Do let us know how it goes

Regards

Raja

Read only

0 Likes
3,041

hi Raja/Everyone, thanks for your replies.

Now i am able to send email thru: cl_bcs.

But my problem is exactly that same as i started.

I attached 3 files to the mail.

*attachment1

REFRESH mailbody.

CONCATENATE lf 'my att1 line 1' INTO mailbody_wa-line.

APPEND mailbody_wa TO mailbody.

CONCATENATE lf 'my att1 line 2' INTO mailbody_wa-line.

APPEND mailbody_wa TO mailbody.

<b> documents-type = 'RAW'.</b>

documents-content_text = mailbody.

documents-subject = 'my att1.xml'.

APPEND documents.

*attachment2

REFRESH mailbody.

CONCATENATE lf 'my att2 line 1' INTO mailbody_wa-line.

APPEND mailbody_wa TO mailbody.

CONCATENATE lf 'my att2 line 2' INTO mailbody_wa-line.

APPEND mailbody_wa TO mailbody.

<b> documents-type = 'TXT'.</b>

documents-content_text = mailbody.

documents-subject = 'my att2.xml'.

APPEND documents.

*attachment3

REFRESH mailbody.

CONCATENATE lf 'my att3 line 1' INTO mailbody_wa-line.

APPEND mailbody_wa TO mailbody.

CONCATENATE lf 'my att3 line 2' INTO mailbody_wa-line.

APPEND mailbody_wa TO mailbody.

<b> documents-type = 'XML'.</b>

documents-content_text = mailbody.

documents-subject = 'my att3.xml'.

APPEND documents.

....

CALL METHOD document->add_attachment

EXPORTING

i_attachment_type = documents_line-type

i_attachment_subject = documents_line-subject

i_att_content_text = documents_line-content_text.

....

resulted mail attachments:

RAW = "my att1.xml.TXT" - no extra space at each line, filesize small.

TXT = "my att2.xml.TXT" - each line exactly 255 chars, filesize big.

file3 = "my att2.xml.XML" - each line exactly 255 chars, filesize big.

Seems very difficult to send out ".xml" file as attachment. Only can send out ".txt" file.

<b>Can you advise pls ?

May i know where to find documentation on possible values for i_attachment_type ?</b>

Thanks in advance.

regards

Ee Siong

Read only

0 Likes
3,041

attachment type is simply various file externsions.

.doc, .xls, .rtf, .xml, etc.

can you post your code here i can correct it and post it back here.

(just post the xml part alone, (how you are getting the xml and how you are passing the same as attachment to mail)

Regards

Raja

Read only

0 Likes
3,041

hi Raja,

lf = cl_abap_char_utilities=>cr_lf.

REFRESH mailbody.

CONCATENATE lf '<?xml version="1.0"?>' INTO mailbody_wa-line.

APPEND mailbody_wa TO mailbody.

CONCATENATE lf '<XOEINSUR_04OCT2006>' INTO mailbody_wa-line.

APPEND mailbody_wa TO mailbody.

CONCATENATE lf '<order>' INTO mailbody_wa-line.

APPEND mailbody_wa TO mailbody.

CONCATENATE lf '<item1>apple</item1>' INTO mailbody_wa-line.

APPEND mailbody_wa TO mailbody.

CONCATENATE lf '<qty>10</qty>' INTO mailbody_wa-line.

APPEND mailbody_wa TO mailbody.

CONCATENATE lf '</order>' INTO mailbody_wa-line.

APPEND mailbody_wa TO mailbody.

CONCATENATE lf '<order>' INTO mailbody_wa-line.

APPEND mailbody_wa TO mailbody.

CONCATENATE lf '<item1>orange</item1>' INTO mailbody_wa-line.

APPEND mailbody_wa TO mailbody.

CONCATENATE lf '<qty>20</qty>' INTO mailbody_wa-line.

APPEND mailbody_wa TO mailbody.

CONCATENATE lf '</order>' INTO mailbody_wa-line.

APPEND mailbody_wa TO mailbody.

CONCATENATE lf '</XOEINSUR_04OCT2006>' INTO mailbody_wa-line.

APPEND mailbody_wa TO mailbody.

documents-type = 'XML'.

documents-content_text = mailbody.

documents-subject = 'my att5'.

APPEND documents.

LOOP AT documents INTO documents_line.

document = cl_document_bcs=>create_document(

i_type = documents_line-type

i_text = documents_line-content_text

i_subject = documents_line-subject ).

....

Thanks & regards

Ee Siong

Read only

0 Likes
3,041

just create a report program and copy paste the following code and change the sender and receiver email address. save/activate and run the program.

*&---------------------------------------------------------------------*
*& Report  Y_TEST_XML_ATT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  y_test_xml_att.
DATA: xml_string TYPE string .
DATA: send_request       TYPE REF TO cl_bcs.
DATA: text               TYPE bcsy_text ,
      text1              TYPE bcsy_text .
DATA: xtext TYPE STANDARD TABLE OF solix .
DATA: document           TYPE REF TO cl_document_bcs.
DATA: sender             TYPE REF TO if_sender_bcs.
DATA: recipient          TYPE REF TO if_recipient_bcs.
DATA: bcs_exception      TYPE REF TO cx_bcs.
DATA: sent_to_all        TYPE os_boolean.
DATA: conlength TYPE i ,
      conlengths TYPE so_obj_len ,
      result_content TYPE string .
*      subject TYPE so_obj_des .
DATA: e_r_page TYPE REF TO cl_rsr_www_page.
DATA: content_length	TYPE	w3param-cont_len ,
      content_type	TYPE	w3param-cont_type,
      return_code	TYPE	w3param-ret_code .

DATA: html TYPE STANDARD TABLE OF w3html .
DATA: server TYPE string ,
      port TYPE string .
DATA: wa_rec TYPE ad_smtpadr .
DATA: bcs_message TYPE string .
DATA: binary_content     TYPE solix_tab.
DATA: xl_content TYPE xstring .
DATA: atta_sub TYPE sood-objdes .


CLEAR xml_string .


CONCATENATE '<?xml version="1.0"?>'  '<XOEINSUR_04OCT2006>' '<order>' '<item1>apple</item1>' '<qty>10</qty>' '</order>' '<order>'  '<item1>orange</item1>'
 '<qty>20</qty>' '</order>' '</XOEINSUR_04OCT2006>' INTO xml_string .

CALL FUNCTION 'SCMS_STRING_TO_FTEXT'
  EXPORTING
    text      = xml_string
  TABLES
    ftext_tab = text.

TRY.
    CLEAR send_request .

    send_request = cl_bcs=>create_persistent( ).

    CLEAR document .
    APPEND 'Test' TO text1 .
    document = cl_document_bcs=>create_document(
                    i_type    = 'HTM'
                    i_text    = text1
                    i_subject = 'Test' ).

    atta_sub = 'myxmlfile' .
    CALL METHOD document->add_attachment
      EXPORTING
        i_attachment_type    = 'xml'
        i_attachment_subject = atta_sub
        i_att_content_text   = text.

*     add document to send request
    CALL METHOD send_request->set_document( document ).

    CLEAR sender .
    sender = cl_cam_address_bcs=>create_internet_address( 'xxxx@yahoo.com' ).
    CALL METHOD send_request->set_sender
      EXPORTING
        i_sender = sender.

    recipient = cl_cam_address_bcs=>create_internet_address( 'yyyy@yahoo.com' ).

*     add recipient with its respective attributes to send request
    CALL METHOD send_request->add_recipient
      EXPORTING
        i_recipient = recipient
        i_express   = 'X'.
    CALL METHOD send_request->set_status_attributes
      EXPORTING
        i_requested_status = 'E'
        i_status_mail      = 'E'.

    CALL METHOD 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:/  'Mail sent successfully '.
    ENDIF.

    COMMIT WORK.

  CATCH cx_bcs INTO bcs_exception.
    bcs_message = bcs_exception->get_text( ).
    write:/ bcs_message .
    EXIT.

ENDTRY.

Do let me know how it goes.

Regards

Raja

Read only

Former Member
0 Likes
3,041

hi Raja,

I created a new program using the exact codes.

the xml file produced, when view in notpad:

< ? x m l v e r s i o n = " 1 . 0 " ? > < X O E I N S U R _ 0 4 O C T 2 0 0 6 > < o r d e r > < i t e m 1 > a p p l e < / i t e m 1 > < q t y > 1 0 < / q t

regards

Ee Siong

Read only

0 Likes
3,041

why do you want to view that in notepad? if you view the xml in internet explorer, you will see the exact hierarchy.

if you are still interested in viewing in notedpad with the line breaks, like in your code add cl_abap_char_utilities=>cr_lf between the elements.

Regards

Raja

Read only

0 Likes
3,041

hi Raja, the file cannot be opened with IE.

The whole file only contain these:

< ? x m l v e r s i o n = " 1 . 0 " ? > < X O E I N S U R _ 0 4 O C T 2 0 0 6 > < o r d e r > < i t e m 1 > a p p l e < / i t e m 1 > < q t y > 1 0 < / q t

thanks & regards

Ee Siong

Read only

0 Likes
3,041

did you change anything in the code i have posted, i have tested the code before posting and it works fine.

after concatenation can you check whether the variable xml_string contains the whole xml?

Regards

Raja

Read only

0 Likes
3,041

hi Raja,

thanks in advance. I used below code to output the variables to screen, the concatenation seems ok.

text2 TYPE bcsy_text with header line.

text2[] = text[].

WRITE:/ xml_string .

loop at text2.

WRITE:/ text2-line .

endloop.

<?xml version="1.0"?><XOEINSUR_04OCT2006><order><item1>apple</item1><qty>10</qty></order><order><item1>orange</item1><qty>20</qty></order></XOEINSUR_04OCT2006>

<?xml version="1.0"?><XOEINSUR_04OCT2006><order><item1>apple</item1><qty>10</qty></order><order><item1>orange</item1><qty>20</qty></order></XOEINSUR_04OCT2006>

But mail attachment received:

< ? x m l v e r s i o n = " 1 . 0 " ? > < X O E I N S U R _ 0 4 O C T 2 0 0 6 > < o r d e r > < i t e m 1 > a p p l e < / i t e m 1 > < q t y > 1 0 < / q t

Even in SCOT, in overview of send orders, when i export the attachment, the file is also truncated as above.

regards

ee siong

Read only

0 Likes
3,041

did you just copy paste my code or made some modifications?

generally the kind of error which you are experiencing will happen if you passed a wrong values to I_ATTACHMENT_SIZE parameter of add attachment method.

also check the itab (after converting the string to table) whether its ok.

Regards

Raja

Read only

0 Likes
3,041

hi Raja, i did not make any modifications besides the output to screen.

the code did not contains I_ATTACHMENT_SIZE ? what value should i assign to it ?

regards

ee siong

Read only

0 Likes
3,041

hi Raja, below are exact codes used.

&----


*& Report ZSDEESIONG12

*&

REPORT zsdeesiong12

NO STANDARD PAGE HEADING LINE-SIZE 300.

DATA: xml_string TYPE string .

DATA: send_request TYPE REF TO cl_bcs.

DATA: text TYPE bcsy_text ,

text1 TYPE bcsy_text ,

text2 TYPE bcsy_text with header line.

DATA: xtext TYPE STANDARD TABLE OF solix .

DATA: document TYPE REF TO cl_document_bcs.

DATA: sender TYPE REF TO if_sender_bcs.

DATA: recipient TYPE REF TO if_recipient_bcs.

DATA: bcs_exception TYPE REF TO cx_bcs.

DATA: sent_to_all TYPE os_boolean.

DATA: conlength TYPE i ,

conlengths TYPE so_obj_len ,

result_content TYPE string .

  • subject TYPE so_obj_des .

DATA: e_r_page TYPE REF TO cl_rsr_www_page.

DATA: content_length TYPE w3param-cont_len ,

content_type TYPE w3param-cont_type,

return_code TYPE w3param-ret_code .

DATA: html TYPE STANDARD TABLE OF w3html .

DATA: server TYPE string ,

port TYPE string .

DATA: wa_rec TYPE ad_smtpadr .

DATA: bcs_message TYPE string .

DATA: binary_content TYPE solix_tab.

DATA: xl_content TYPE xstring .

DATA: atta_sub TYPE sood-objdes .

CLEAR xml_string .

CONCATENATE '<?xml version="1.0"?>' '<XOEINSUR_04OCT2006>' '<order>'

'<item1>apple</item1>' '<qty>10</qty>' '</order>' '<order>'

'<item1>orange</item1>'

'<qty>20</qty>' '</order>' '</XOEINSUR_04OCT2006>' INTO xml_string .

CALL FUNCTION 'SCMS_STRING_TO_FTEXT'

EXPORTING

text = xml_string

TABLES

ftext_tab = text.

TRY.

CLEAR send_request .

send_request = cl_bcs=>create_persistent( ).

CLEAR document .

APPEND 'Test' TO text1 .

document = cl_document_bcs=>create_document(

i_type = 'HTM'

i_text = text1

i_subject = 'Test' ).

atta_sub = 'myxmlfile' .

CALL METHOD document->add_attachment

EXPORTING

i_attachment_type = 'xml'

i_attachment_subject = atta_sub

i_att_content_text = text.

  • add document to send request

CALL METHOD send_request->set_document( document ).

CLEAR sender .

sender = cl_cam_address_bcs=>create_internet_address(

'xxxx@yahoo.com' ).

CALL METHOD send_request->set_sender

EXPORTING

i_sender = sender.

recipient = cl_cam_address_bcs=>create_internet_address(

'xxxxx@yyyy.com' ).

  • add recipient with its respective attributes to send request

CALL METHOD send_request->add_recipient

EXPORTING

i_recipient = recipient

i_express = 'X'.

CALL METHOD send_request->set_status_attributes

EXPORTING

i_requested_status = 'E'

i_status_mail = 'E'.

CALL METHOD 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:/ 'Mail sent successfully '.

WRITE:/ xml_string .

text2[] = text[].

loop at text2.

WRITE:/ text2-line .

endloop.

ENDIF.

COMMIT WORK.

CATCH cx_bcs INTO bcs_exception.

bcs_message = bcs_exception->get_text( ).

WRITE:/ bcs_message .

EXIT.

ENDTRY.

Read only

0 Likes
3,041

i really dont know the issue, the same code works in my system.

Regards

Raja

Read only

0 Likes
3,041

hi Raja,

in BCSY_TEXT, i see line type SOLI.

in SOLI, i see component LINE, which is char length 255.

Can this be the cause ?

regards

Ee Siong

Read only

0 Likes
3,041

no it cannot be as the total length of the text itself is less than 200

Read only

0 Likes
3,041

sorry missed page 2...

Message was edited by: F.J. Brandelik

Read only

0 Likes
3,041

Hi F.J. Brandelik

Can you copy/paste the code and try in your system and tell us the results.

Thanks in advance.

Regards

Raja

Read only

0 Likes
3,041

hi Raja, thanks for all your helps.

I tried your code in another SAP system 4.7C.

It is working perfectly.

Now, i really do not noe why it do not work in my company system, ECC5.0. As i mentioned, the xml attachment mail out is trucated and look more like a binary file.

While on the other system the xml file is perfect as required.

This is very difficult, do you know how to find out what is wrong with my system? some patches not done ?

Thanks & regards

Ee Siong

Read only

0 Likes
3,041

hi Raja and Everyone,

today i tried the same code on a third system.

Again, the email attachment is correct, while it is wrong in my main system.

Is there some patches that my company system is lacking?

I need some clues to tell my basis guy.

Thanks in advance.

(3rd system) System Component Info:

SAP_BASIS 620 0055 SAPKB62055

SAP_ABA 620 0055 SAPKA62055

SAP_APPL 470 0022 SAPKH47022

SAP_HR 470 0050 SAPKE47050

EA-IPPE 110 0006 SAPKGPIA06

PI 2002_1_470 0003 SAPKIPZF53

PI_BASIS 2002_1_620 0006 SAPKIPYF56

EA-APPL 110 0006 SAPKGPAA06

(Main system having attachment error)

System Component Info:

SAP_BASIS 640 0009 SAPKB64009

SAP_ABA 640 0009 SAPKA64009

ST-PI 003C_640 0001 SAPKITLPS1

PI_BASIS 2004_1_640 0006 SAPKIPYI66

SAP_BW 350 0009 SAPKW35009

SAP_HR 500 0005 SAPKE50005

SAP_APPL 500 0005 SAPKH50005

PI 2004_1_500 0004 SAPKIPZI64

Read only

Former Member
0 Likes
3,041

hi you have read the documentation for the function carefully.

the tables parameter 'OBJPACK' IS IMPORTANT TO DEFINE THE TYPES OF DOCUMENT AND THE ATTACHMENTS.

NOTE: THE MAIL ITSELEFT REPRESENTS A DOCUMENT. THE FIRST ENTRY IN THE OBJPACK IS RELATING TO THIS. YOU CAN DEFINE THE ATTACHMENTS AND IT'S PROPERTIES FROM SECOND ENTRY ONWARDS.

SO PLEASE FIRST FILL THE FIRST ROW AS BELOW.

THE BELOW ENTRY REPRESENTS THE DOCUMENT IE MAIL ITSELF.

objpack-head_start = 1. * THESE ARE OPTIONAL

objpack-head_num = 0. * THESE ARE OPTIONAL

objpack-body_start = 1

objpack-body_num = tab_lines.

objpack-doc_type = 'RAW'.

objpack-obj_descr = "mail ".

APPEND objpack.

the below secondentry belongs to the attachment.

objpack-body_start = LINES( mailbody ) + 1 .

objpack-body_num = tab_lines.

objpack-doc_type = 'xml'.

objpack-obj_descr = "myfile".

APPEND objpack.

this will work.

jaffer vali shaik

Read only

0 Likes
3,041

hi Jaffer,

Raja have since taught me to use class cl_bcs to send email with attachments.

My problem now is the codes is not working in my system, but is working on 2 other system i tested.

And the differences between the system seems to be mine is Ecc5.0 while the other 2 is 4.7.

Can u advise?

regards

Ee Siong

Read only

athavanraja
Active Contributor
0 Likes
3,042

i think the issue is with unicode. can you try this code.

*&---------------------------------------------------------------------*
*& Report  Y_TEST_XML_ATT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  y_test_xml_att.
DATA: xml_string TYPE string .
DATA: send_request TYPE REF TO cl_bcs.
DATA: text TYPE bcsy_text ,
text1 TYPE bcsy_text ,
text2 TYPE bcsy_text WITH HEADER LINE.
DATA: xtext TYPE STANDARD TABLE OF solix .
DATA: document TYPE REF TO cl_document_bcs.
DATA: sender TYPE REF TO if_sender_bcs.
DATA: recipient TYPE REF TO if_recipient_bcs.
DATA: bcs_exception TYPE REF TO cx_bcs.
DATA: sent_to_all TYPE os_boolean.
DATA: conlength TYPE i ,
conlengths TYPE so_obj_len ,
result_content TYPE string .
* subject TYPE so_obj_des .
DATA: e_r_page TYPE REF TO cl_rsr_www_page.
DATA: content_length TYPE w3param-cont_len ,
content_type TYPE w3param-cont_type,
return_code TYPE w3param-ret_code .

DATA: html TYPE STANDARD TABLE OF w3html .
DATA: server TYPE string ,
port TYPE string .
DATA: wa_rec TYPE ad_smtpadr .
DATA: bcs_message TYPE string .
DATA: binary_content TYPE solix_tab.
DATA: xl_content TYPE xstring .
DATA: atta_sub TYPE sood-objdes ,
      app_type(50) .
data: len type sood-objlen ,
      length type  i .
CLEAR xml_string .


CONCATENATE
 `<?xml version="1.0" encoding="utf-8" ?>`
`<XOEINSUR_04OCT2006>`
    `<order>`
        `<item1>apple</item1>`
        `<qty>10</qty>`
    `</order>`
    `<order>`
        `<item1>orange</item1>`
        `<qty>20</qty>`
    `</order>`
`</XOEINSUR_04OCT2006>`
INTO xml_string separated by CL_ABAP_CHAR_UTILITIES=>CR_LF .

app_type = 'text/xml; charset=utf-8'.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
  EXPORTING
    text     = xml_string
    mimetype = app_type
  IMPORTING
    buffer   = xl_content.


CONCATENATE  cl_abap_char_utilities=>byte_order_mark_utf8
             xl_content
             INTO xl_content IN BYTE MODE.
REFRESH binary_content .
clear:len, length .
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
  EXPORTING
    buffer     = xl_content
  importing
  OUTPUT_LENGTH = length
  TABLES
    binary_tab = binary_content.
move: length to len .

TRY.
    CLEAR send_request .

    send_request = cl_bcs=>create_persistent( ).

    CLEAR document .
    APPEND 'Test' TO text1 .
    document = cl_document_bcs=>create_document(
    i_type = 'HTM'
    i_text = text1
    i_subject = 'Test' ).

    atta_sub = 'myxmlfile' .
    CALL METHOD document->add_attachment
      EXPORTING
        i_attachment_type    = 'xml'
        i_attachment_subject = atta_sub
        I_ATTACHMENT_SIZE    = len
        i_att_content_hex    = binary_content.


* add document to send request
    CALL METHOD send_request->set_document( document ).

    CLEAR sender .
    sender = cl_cam_address_bcs=>create_internet_address( 'sender@yahoo.com' ).
    CALL METHOD send_request->set_sender
      EXPORTING
        i_sender = sender.

    recipient = cl_cam_address_bcs=>create_internet_address( 'receiver@yahoo.com' ).

* add recipient with its respective attributes to send request
    CALL METHOD send_request->add_recipient
      EXPORTING
        i_recipient = recipient
        i_express   = 'X'.
    CALL METHOD send_request->set_status_attributes
      EXPORTING
        i_requested_status = 'E'
        i_status_mail      = 'E'.

    CALL METHOD 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:/ 'Mail sent successfully '.
      WRITE:/ xml_string .

      text2[] = text[].
      LOOP AT text2.
        WRITE:/ text2-line .
      ENDLOOP.
    ENDIF.

    COMMIT WORK.

  CATCH cx_bcs INTO bcs_exception.
    bcs_message = bcs_exception->get_text( ).
    WRITE:/ bcs_message .
    EXIT.

ENDTRY.

Regards

Raja

Read only

Former Member
0 Likes
3,041

hi Raja,

You have solved my problem! Your codes is working in my unicode system!

I tried many times to assign points to your last post but:

"Error:

Rewarding the message failed. "

thanks!!

regards.

Read only

0 Likes
3,041

Glad to hear its solved. Looks like the points system is down. check back later to close the thread

Regards

Raja