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

Logic header and data passing to a string

Former Member
0 Likes
883

Hi Folks,

Good Evening.

I am sending an ALV Output as excel attachment to emails using CL_BCS.

I need all your help on the below -


  • How to concatenate header with Item data?
    In my code only one line is shown from internal table  lt_sch_chlog. Header is not shown and all records from internal table are     fetched
  • In my below code - lt_sch_chlog is the internal table. But when i get email i get only one record although it has multiple records. Please assist.

Code Snippet


data :   li_contents_text LIKE solisti1 OCCURS 10 WITH HEADER LINE,
           li_contents_bin_header TYPE string,
           li_contents_bin TYPE string,
           li_contents_line type xstring.
data : c_tab type c value cl_abap_char_utilities=>horizontal_tab,
          c_ret type c value cl_abap_char_utilities=>cr_lf.

DATA: li_contents_hex TYPE STANDARD TABLE OF solix.
         
  DATA: l_send_request  TYPE REF TO cl_bcs,         " Send request
            l_body              TYPE             bcsy_text,                " Mail body
            l_document       TYPE REF TO cl_document_bcs,   " Mail body
            l_sender            TYPE REF TO if_sender_bcs,     " Sender address
            l_recipient          TYPE REF TO if_recipient_bcs" Recipient
            l_size                TYPE sood-objlen,              " Size of Attachment
            l_lines                TYPE i,                        " Lines count
            l_email               TYPE ad_smtpadr,               " Email ID
            l_extension         TYPE soodk-objtp VALUE 'RAW'" TXT format

  DATA: l_mailtext  TYPE soli_tab.

   CONCATENATE  'Sales Dist'
                'Sales Grp'
                'ISR'
                'Soldto No'
                'Soldto Name'
                'End Cust No'
                'End Cust'

                              into li_contents_bin SEPARATED BY c_tab.

   LOOP AT lt_sch_chlog INTO ls_sch_chlog.
     lv_kwmeng = ls_sch_chlog-kwmeng.
     lv_open_cnfqty = ls_sch_chlog-open_cnfqty.
     lv_bmeng_old =   ls_sch_chlog-bmeng_old .
     lv_bmeng_new = ls_sch_chlog-bmeng_new .
     lv_conf_netwr ls_sch_chlog-conf_netwr.

     CONCATENATE ls_sch_chlog-zzbzirk
                 ls_sch_chlog-zzvkgrp
                 ls_sch_chlog-isr_name
                 ls_sch_chlog-sold_to_no
                 ls_sch_chlog-sold_to_name
                 ls_sch_chlog-end_cust_no
                 ls_sch_chlog-end_cust

                                                  into li_contents_bin separated by c_tab.
   ENDLOOP.


APPEND 'Please find attached Schedule Line Change Log Report.'  TO l_body.

*Converting the table contents for attachment to xstring
     CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
       EXPORTING
         text           = li_contents_bin
       IMPORTING
         buffer         = li_contents_line
      EXCEPTIONS
        failed         = 1
        OTHERS         = 2.

*Converting the table contents from xstring to binary
     CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
       EXPORTING
         buffer                = li_contents_line
       TABLES
         binary_tab            = li_contents_hex.

* Creates persistent send request
   l_send_request = cl_bcs=>create_persistent( ).
* Craete document for mail body
   l_document = cl_document_bcs=>create_document(
                i_type    = 'RAW'
                i_text    = l_body
*               i_length  = '500'
                i_subject = 'Schedule Line Change Log' ).

* Add attchment
   CALL METHOD l_document->add_attachment
     EXPORTING
       i_attachment_type    = 'XLS'"l_extension
       i_attachment_subject = 'Schedule Line Change Log'
       i_attachment_size    = l_size
*     i_att_content_text   = it_attach.
       i_att_content_hex    = li_contents_hex.

* Add the document to send request
   CALL METHOD l_send_request->set_document( l_document ).
* Sender addess
   l_sender = cl_sapuser_bcs=>create( sy-uname ).
   CALL METHOD l_send_request->set_sender
     EXPORTING
       i_sender = l_sender.

   IF p_email[] IS NOT INITIAL.
   LOOP AT p_email.
       l_email = p_email-low.
       l_recipient = cl_cam_address_bcs=>create_internet_address( l_email ).
     ENDLOOP.
   endif.

* Add recipient address to send request
   CALL METHOD l_send_request->add_recipient
     EXPORTING
       i_recipient  = l_recipient
       i_express    = 'X'
       i_copy       = ' '
       i_blind_copy = ' '
       i_no_forward = ' '.

* Send mail
   TRY.
       CALL METHOD l_send_request->send( ).
     CATCH cx_send_req_bcs.

   ENDTRY.
   COMMIT WORK.

   IF sy-subrc EQ 0.
     MESSAGE 'Mail sent Successfully' TYPE 'S'.
   ENDIF.

Thanks for all your help.

2 REPLIES 2
Read only

naimesh_patel
Active Contributor
0 Likes
577

You are missing the Line Return addition in the String


CONCATENATE  'Sales Dist'
                'Sales Grp'
                'ISR'
                'Soldto No'
                'Soldto Name'
                'End Cust No'
                'End Cust'

                              into li_contents_bin SEPARATED BY c_tab.



CONCATENATE li_contents_bin c_ret   "<<

    into li_contents_bin.

   LOOP AT lt_sch_chlog INTO ls_sch_chlog.
     lv_kwmeng = ls_sch_chlog-kwmeng.
     lv_open_cnfqty = ls_sch_chlog-open_cnfqty.
     lv_bmeng_old =   ls_sch_chlog-bmeng_old .
     lv_bmeng_new = ls_sch_chlog-bmeng_new .
     lv_conf_netwr ls_sch_chlog-conf_netwr.

     CONCATENATE ls_sch_chlog-zzbzirk
                 ls_sch_chlog-zzvkgrp
                 ls_sch_chlog-isr_name
                 ls_sch_chlog-sold_to_no
                 ls_sch_chlog-sold_to_name
                 ls_sch_chlog-end_cust_no
                 ls_sch_chlog-end_cust

                                                  into li_contents_bin separated by c_tab.


CONCATENATE li_contents_bin c_ret   "<<

    into li_contents_bin.


   ENDLOOP.

Regards,

Naimesh Patel

Read only

Former Member
0 Likes
577

As Naimesh suggest, missing "Carriage Return and Line Feed" Character Pair.

c_ret  TYPE c VALUE cl_bcs_convert=>gc_crlf.  (ur definition is also correct)

Raju.