cancel
Showing results for 
Search instead for 
Did you mean: 

AR Invoice to be generated for Print as well in PDF for email ,

0 Kudos

Hi Gurus

Plz let me know how can we convert a smartform to PDF and send a email .

what are the possibilities of doing the same as Adobe forms and where can we do that

Pol

Accepted Solutions (1)

Accepted Solutions (1)

former_member196280
Active Contributor
0 Kudos

Answers (2)

Answers (2)

Former Member
0 Kudos

Here You can find the sample of working code.

Just change come parameters in order to suit You.

*some data
*please check which You need there is some thing that is not *usefull
 
data lv_string type string.
 
data main_text      type bcsy_text.
data binary_content type solix_tab.
data size           type so_obj_len.
 
* event handler for data retrieval
data: l_devtype              type rspoptype,
      l_function_module_name type rs38l_fnam.
data: ls_output_options     type ssfcompop,
      ls_control_parameters type ssfctrlop.
 
data: ls_output_data type ssfcrescl.
 
* generated result: HTML with embedded CSS
data: ls_xmloutput type ssfxmlout,
      lt_html_raw  type tsfixml.
data: l_xstring    type xstring,    "needed for HTTP response
      l_xlength    type i,
      l_html_xstring   type xstring.
data: l_pdf_xstring  type xstring,
      lt_lines       type table of tline,
      ls_line        type tline,
      l_pdf_len      type i.
 
data:
      solix TYPE solix,
      soli type soli.
 
DATA  send_request       TYPE REF TO cl_bcs.
DATA  text               TYPE bcsy_text.
DATA  document           TYPE REF TO cl_document_bcs.
DATA  recipient          TYPE REF TO if_recipient_bcs.
DATA  sent_to_all        TYPE os_boolean.
DATA  pdf_content        TYPE solix_tab.
DATA  lp_pdf_size        TYPE so_obj_len.
 
 
*here we make the smartform and convert it to pdf
 
    ls_control_parameters-no_dialog = 'X'.
    ls_control_parameters-getotf    = 'X'.
 
    CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
      EXPORTING
        i_language                   = sy-langu
*       i_application                = 'SAPDEFAULT'
      IMPORTING
        e_devtype                    = l_devtype
      EXCEPTIONS
        no_language                  = 1
        language_not_installed       = 2
        no_devtype_found             = 3
        system_error                 = 4
        others                       = 5.
    IF sy-subrc NE 0.
      MESSAGE ID sy-msgid type sy-msgty number sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
 
    ls_output_options-tdprinter = l_devtype.
 
    CALL FUNCTION l_function_module_name
         EXPORTING
*                 archive_index        =
*                 archive_parameters   =
                  control_parameters   = ls_control_parameters
*                  mail_appl_obj        = APPL_OBJECT_ID
*                  mail_recipient       = RECIPIENT_ID
*                  mail_sender          = SENDER_ID
                  output_options       = ls_output_options
                  user_settings        = space
                  iv_werks              = i_werks
                  iv_datum              = i_date
         IMPORTING
*                 document_output_info =
                    job_output_info      = ls_output_data
*                 job_output_options   =
         TABLES
                    im_matnr          = application->IT_MATERIAL
         EXCEPTIONS
                    formatting_error     = 1
                    internal_error       = 2
                    send_error           = 3
                    user_canceled        = 4
                    others               = 5.
    IF sy-subrc NE 0.
      MESSAGE ID sy-msgid type sy-msgty number sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
 
    CALL FUNCTION 'CONVERT_OTF'
         EXPORTING
           format                      = 'PDF'
*            MAX_LINEWIDTH               = 132
*            ARCHIVE_INDEX               = ' '
*            COPYNUMBER                  = 0
         IMPORTING
           bin_filesize                = l_pdf_len
           bin_file                    = l_pdf_xstring       " binary file
         TABLES
           otf                         = ls_output_data-otfdata
           lines                       = lt_lines
         EXCEPTIONS
           err_max_linewidth           = 1
           err_format                  = 2
           err_conv_not_possible       = 3
           err_bad_otf                 = 4
           others                      = 5.
    IF sy-subrc NE 0.
      MESSAGE ID sy-msgid type sy-msgty number sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
 
*and here we mail it
 
      send_request = cl_bcs=>create_persistent( ).
 
      lp_pdf_size = XSTRLEN( l_pdf_xstring ).
      pdf_content = cl_document_bcs=>xstring_to_solix( ip_xstring = l_pdf_xstring ).
 
      document = cl_document_bcs=>create_document( i_type    = 'PDF'
                                                   i_hex     = pdf_content
                                                   i_length  = lp_pdf_size
                                                   i_subject = 'Test Message' ).
      send_request->set_document( document ).
 
      recipient = cl_cam_address_bcs=>create_internet_address(
              i_address_string = 'YOUR-EMAIL-HERE' ).
 
 
      send_request->add_recipient( i_recipient = recipient ).
 
      sent_to_all = send_request->send( i_with_error_screen = 'X' ).
 
      COMMIT WORK.

former_member181995
Active Contributor
0 Kudos

pols,

there is lots of thread on same topic.

just refer:

[Pls use|;

[SDN search Option|https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6301] [original link is broken] [original link is broken] [original link is broken];