Problem:

While downloading an excel attachment file sent from SAP system you will come across a strange scenario where foreign characters are displayed as a garbage value having rectangular blocks like characters.

How to avoid this ?

Following is an example that you can use. Here, we make use of ” cl_bcs_convert=>string_to_solix “.


<<<< and >>>> indicate notes. Please have a look on them carefully.

CONSTANTS: c_docd(13) TYPE VALUE ‘Document Date’,

           c_refd(25) TYPE VALUE ‘Reference Document Number’,

           c_plnt(5TYPE VALUE ‘Plant’,

           c_c1       TYPE VALUE ‘=’,

           c_c2       TYPE VALUE ‘”‘,

           c_tab      TYPE VALUE cl_bcs_convert=>gc_tab,

           c_crlf     TYPE VALUE cl_bcs_convert=>gc_crlf.

DATA: l_string       TYPE string,

       send_request   TYPE REF TO cl_bcs,

       document       TYPE REF TO cl_document_bcs,

       recipient      TYPE REF TO if_recipient_bcs,

       bcs_exception  TYPE REF TO cx_bcs,

       main_text      TYPE bcsy_text,

       binary_content TYPE solix_tab,

       size           TYPE so_obj_len,

       sent_to_all    TYPE os_boolean,

       mailto         TYPE so_obj_nam VALUE ‘ZTEST_CL_BCS’.

DATA : date TYPE sydatum.

DATA : l_recipient     TYPE REF TO if_recipient_bcs.

date = sydatum.

CONCATENATE c_docd  c_tab  date c_crlf

             c_refd  c_tab  c_c1 c_c2 ‘조광피혁(주)’   “<<<< HERE ARE SOME KOREAN CHARACTERS >>>>

             c_c2    c_crlf

             c_plnt  c_tab  c_c1 c_c2 ‘Data ‘

             c_c2    c_crlf c_crlf

             INTO l_string.

TRY.

     cl_bcs_convert=>string_to_solix(

       EXPORTING

         iv_string   = l_string

         iv_codepage = ‘4103’   “suitable for MS Excel <<<< THIS IS MANDATORY TO AVOID RECTANGULAR CHAR. >>>>

         iv_add_bom  = ‘X’      “for other doc types   <<<< ALSO THIS !! >>>>

       IMPORTING

         et_solix  = binary_content

         ev_size   = size ).

   CATCH cx_bcs.

     MESSAGE ‘Error when transfering document contents’ TYPE ‘E’.

ENDTRY.

TRY.

* create persistent send request

     send_request = cl_bcs=>create_persistent( ).

     APPEND ‘THIS IS MAIN TEXT’ TO main_text.

* create and set document with attachment

     document = cl_document_bcs=>create_document(

       i_type    = ‘RAW’

       i_text    = main_text

       i_subject = ‘This is Subject’ ).

* add the spread sheet as attachment to document object

     document->add_attachment(

       i_attachment_type    = ‘xls’

       i_attachment_subject = ‘Attat. Subject’

       i_attachment_size    = size

       i_att_content_hex    = binary_content ).

* add document object to send request

     send_request->set_document( document ).

  l_recipient = cl_cam_address_bcs=>create_internet_address(‘testmail@gmail.com).

     CALL METHOD send_request->add_recipient

       EXPORTING

         i_recipient = l_recipient ‘testmail@gmail.com

         i_express   = ‘X’.

* <<<< THE BELOW COMMENTED CODE CAN BE USED FOR DISTRIBUTION LIST >>>> *

** add recipient (e-mail address)

*    recipient = cl_distributionlist_bcs=>getu_persistent(

*      i_dliname = mailto

*      i_private = space ). ” Distribution List maintained via SO23

** add recipient object to send request

*    send_request->add_recipient( recipient ).

* <<<< TILL HERE !! >>>> *

* send document

     sent_to_all = send_request->send( i_with_error_screen = ‘X’ ).

     COMMIT WORK.

     IF sent_to_all IS INITIAL.

       MESSAGE i500(sbcoms) WITH mailto.

     ELSE.

       MESSAGE s022(so).

     ENDIF.

   CATCH cx_bcs INTO bcs_exception.

     MESSAGE i865(so) WITH bcs_exception->error_type.

ENDTRY.



And there’s the solution !!


Cheers !!


Comment if you get any issues !!

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

Comments are closed.