Quantcast
Channel: SCN: Message List - ABAP Development
Viewing all articles
Browse latest Browse all 10425

Re: Convert Smartform output into excel format and mail

$
0
0

Hi ,

I think your requirement is smartform out put need to be converted into excel and the excel file should send  throught email to the require customer.

 

if so then follow this process.

 

 

CALL FUNCTION 'RSPO_RETURN_ABAP_SPOOLJOB'

    EXPORTING

      rqident              = tsp01-rqident                     "Spool Request Number

      first_line           = 1

    TABLES

      buffer               = it_spool_xls                            "Internal table that will have the Spool Request No data

    EXCEPTIONS

      no_such_job          = 1

      not_abap_list        = 2

      job_contains_no_data = 3

      selection_empty      = 4

      no_permission        = 5

      can_not_access       = 6

      read_error           = 7

      OTHERS               = 8.

 

CALL FUNCTION 'SO_RAW_TO_RTF'

    TABLES

      objcont_old = it_spool_xls               "Internal table having spool data

      objcont_new = it_xls_spool.           "Int table having Excel format data converted from Spool data

 

*To convert the excel format data into string

  LOOP AT it_xls_spool.

    CONCATENATE xls_string it_xls_spool INTO xls_string.           "xls_string will have the data as one string

  ENDLOOP.

*To convert the string into xstring format for mail sending

  CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

    EXPORTING

      text           = xls_string                         "String of String data type

  •   MIMETYPE       = ' '
  •   ENCODING       =

   IMPORTING     buffer         = xls_str                             "String of XString data type   EXCEPTIONS     failed         = 1     OTHERS         = 2            .  IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  •         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.*To send mail the xstring having excel format data  TRY.

  •     Create persistent send request

      send_request = cl_bcs=>create_persistent( ).

  •     Create and set document

      pdf_content = cl_document_bcs=>xstring_to_solix( xls_str ).          "String having Excel format                                                                                "Data above populated      document = cl_document_bcs=>create_document(            i_type    = 'XLS'            i_hex     = pdf_content            i_length  = pdf_size            i_subject = 'Asset Origin Details Report' ).    "#EC NOTEXT

  •     Add document object to send request

      send_request->set_document( document ).

  •     Add recipient (e-mail address)
  •     Create recipient object

      recipient = cl_cam_address_bcs=>create_internet_address( p_email ).

  •     Add recipient object to send request

      send_request->add_recipient( recipient ).

  •     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 p_email.      ELSE.        MESSAGE s022(so).      ENDIF.

  •   Exception handling
  •   replace this rudimentary exception handling with your own one

    CATCH cx_bcs INTO bcs_exception.

      MESSAGE i865 (so) WITH bcs_exception->error_type.

  ENDTRY.

 

 

 

 

Regards

 

Khaleel


Viewing all articles
Browse latest Browse all 10425

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>