Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
FredericGirod
Active Contributor

Creation of a simple Smartform

Import of a logo

Transaction SE78

Double-click on the line BMAP

Enter a name for your logo, select the color BitMap Image and press the Import button.

Enter the file name, and press Enter.

Smartform creation

Transaction SmartForms

Enter a name and press the button Create

Select the Main Window, click on the right button, select Create --> Graphic

Enter the graphic name, the object and the ID (GRAPHICS / BMAP), select the Color BitMap Image

Select the main window, click on the right button, select Create --> Text

Enter a text ..

Press the Activate icon.

Now we could test our Smartform, press the Test button (F8).

SAP launch the SE37 transaction (Function module) with the function generated by the Smartforms.

Press again the test button (F8)

Press now execute (F8)

Choose a printer and press the button Print Preview

It works !

Creation of a simple calling program for the Smartform.



DATA : w_formname        TYPE tdsfname ,
        w_funcname        TYPE tdsfname ,

        is_control_param  TYPE ssfctrlop ,
        is_params         TYPE pri_params.



START-OF-SELECTION.


* My Smartforms.
   MOVE 'ZMY_SMARTFORMS' TO w_formname.


* Get the function module name corresponding of the Smartform.
   CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
     EXPORTING
       formname = w_formname
     IMPORTING
       fm_name  = w_funcname
     EXCEPTIONS
       OTHERS  = 3.
   CHECK sy-subrc EQ space.


* Set the parameters of the forms.
   MOVE : 'X'            TO is_control_param-no_dialog ,
          'X'            TO is_control_param-preview ,
          ' '            TO is_control_param-getotf ,
          sy-langu        TO is_control_param-langu .


   CALL FUNCTION w_funcname
     EXPORTING
*     ARCHIVE_INDEX              =
*     ARCHIVE_INDEX_TAB          =
*     ARCHIVE_PARAMETERS         =
       control_parameters         = is_control_param
*     MAIL_APPL_OBJ              =
*     MAIL_RECIPIENT             =
*     MAIL_SENDER                =
*     output_options             =
       USER_SETTINGS              = ' '
*   IMPORTING
*     DOCUMENT_OUTPUT_INFO       =
*     JOB_OUTPUT_INFO            =
*     JOB_OUTPUT_OPTIONS         =
     EXCEPTIONS
       formatting_error           = 1
       internal_error             = 2
       send_error                 = 3
       user_canceled              = 4
       OTHERS                    = 5.



END-OF-SELECTION.

With this code you could print or preview the form.

Send the Smartform by email


* Need for the macro to build Mail_Appl_Obj.
INCLUDE <cntn01>.



DATA : w_formname        TYPE tdsfname ,
        w_funcname        TYPE tdsfname ,
        w_borkey          TYPE swo_typeid ,
        w_year            TYPE so_doc_yr ,
        w_number          TYPE so_doc_no ,

        is_control_param  TYPE ssfctrlop ,
        is_params         TYPE pri_params ,
        is_recipient      TYPE swotobjid ,
        is_sender         TYPE swotobjid ,
        is_mailobj        TYPE swotobjid ,
        is_folder         TYPE swc_object ,
        is_sofmk          TYPE sofmk .



START-OF-SELECTION.


* My Smartforms.
   MOVE 'ZMY_SMARTFORMS' TO w_formname.


* Get the function module name corresponding of the Smartform.
   CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
     EXPORTING
       formname = w_formname
     IMPORTING
       fm_name  = w_funcname
     EXCEPTIONS
       OTHERS  = 3.
   CHECK sy-subrc EQ space.


* Set the parameters of the forms.
   MOVE : 'X'            TO is_control_param-no_dialog ,
          ' '            TO is_control_param-preview ,
          ' '            TO is_control_param-getotf ,
          sy-langu        TO is_control_param-langu ,
          'MAIL'          TO is_control_param-device.

* Create the Recipient.
   CALL FUNCTION 'CREATE_RECIPIENT_OBJ_PPF'
     EXPORTING
       ip_mailaddr       = 'frederic.girod@everywhere.com'
     IMPORTING
       ep_recipient_id   = is_recipient
     EXCEPTIONS
       invalid_recipient = 1
       OTHERS            = 2.

* Create the Sender
   CALL FUNCTION 'CREATE_SENDER_OBJECT_PPF'
     EXPORTING
       ip_sender      = sy-uname
     IMPORTING
       ep_sender_id   = is_sender
     EXCEPTIONS
       invalid_sender = 1
       OTHERS        = 2.

* Create the Mail Obj.
   SELECT SINGLE inbyr inbno
          INTO (w_year, w_number)
          FROM soud
          WHERE sapnam EQ sy-uname.
   CHECK sy-subrc EQ space.
   MOVE : 'FOL'    TO is_sofmk-doctp ,
          w_number TO is_sofmk-docyr ,
          w_year   TO is_sofmk-docno .
   MOVE is_sofmk TO w_borkey.
   swc_create_object is_folder 'SOFMFOL' w_borkey.
   swc_object_to_persistent is_folder is_mailobj.



   CALL FUNCTION w_funcname
     EXPORTING
*     ARCHIVE_INDEX              =
*     ARCHIVE_INDEX_TAB          =
*     ARCHIVE_PARAMETERS         =
       control_parameters         = is_control_param
       mail_appl_obj              = is_mailobj
       mail_recipient             = is_recipient
       mail_sender                = is_sender
*     output_options             =
       user_settings              = ' '
*   IMPORTING
*     DOCUMENT_OUTPUT_INFO       =
*     JOB_OUTPUT_INFO            =
*     JOB_OUTPUT_OPTIONS         =
     EXCEPTIONS
       formatting_error           = 1
       internal_error             = 2
       send_error                 = 3
       user_canceled              = 4
       OTHERS                    = 5.

   IF sy-subrc EQ space.
     COMMIT WORK AND WAIT.
   ENDIF.


END-OF-SELECTION.

If you haven't entry in the SOUD table you could add-it dynamically with the function SO_USER_AUTOMATIC_INSERT.

If you use an entry of the NAST table (configuration with the NACE transaction ..), instead of creating manually the MAIL_APPL_OBJ, MAIL_RECIPIENT, MAIL_SENDER, you only have to use the function WFMC_PREPARE_SMART_FORM.

Result

In the SOST transaction :

And the mail :

The attachment :

Each time I show that to my users, they didn't want to use that for external mails.

Send the Smartform inside the email.

Code



DATA : w_formname        TYPE tdsfname ,
        w_funcname        TYPE tdsfname ,
        w_status          TYPE bcs_rqst ,
        w_html_xtxt       TYPE xstring ,
        w_html_txt        TYPE string ,
        w_html_len        TYPE i ,
        w_gr_xtxt         TYPE xstring ,
        w_offset          TYPE i ,
        w_len             TYPE i ,
        w_diff            TYPE i ,
        w_file            TYPE string ,
        w_content_type    TYPE w3conttype ,
        w_obj_len         TYPE so_obj_len ,
        w_content_id      TYPE string ,
        w_title           TYPE so_obj_des ,
        w_docno           TYPE so_obj_no ,

        is_control_param  TYPE ssfctrlop ,
        is_composer_param TYPE ssfcompop ,
        is_soli           TYPE soli ,
        is_job_info       TYPE ssfcrescl ,
        is_xfsparam       TYPE ssfxsfp ,
        is_html_raw       LIKE LINE OF is_job_info-xmloutput-trfresult-content ,
        is_graphic        TYPE ssf_xsf_gr ,
        is_gr_raw         TYPE bapiconten ,
        is_solix          TYPE solix ,

        it_soli           TYPE TABLE OF soli ,
        it_graphics       TYPE tsf_xsf_gr ,
        it_solix          TYPE solix_tab ,

        obj_mime_helper   TYPE REF TO cl_gbt_multirelated_service ,
        obj_bcs           TYPE REF TO cl_bcs ,
        obj_doc_bcs       TYPE REF TO cl_document_bcs ,
        obj_recipient     TYPE REF TO if_recipient_bcs .







START-OF-SELECTION.


* My Smartforms.
   MOVE 'ZMY_SMARTFORMS' TO w_formname.


* Get the function module name corresponding of the Smartform.
   CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
     EXPORTING
       formname = w_formname
     IMPORTING
       fm_name  = w_funcname
     EXCEPTIONS
       OTHERS   = 3.
   CHECK sy-subrc EQ space.


* Set the parameters of the forms.
   MOVE : 'X'        TO is_control_param-no_dialog ,
          ' '        TO is_control_param-preview ,
          'X'        TO is_control_param-getotf ,
          sy-langu   TO is_control_param-langu ,
          'PRINTER'  TO is_control_param-device ,
          'X'        TO is_composer_param-tdnoprint ,
          'X'        TO is_composer_param-tdnoprev ,
          'X'        TO is_composer_param-tdfinal ,
          'X'        TO is_composer_param-xdfcmode ,
          ' '        TO is_composer_param-xdf ,
          'X'        TO is_composer_param-xsfcmode ,
          'X'        TO is_composer_param-xsf ,
          ' '        TO is_composer_param-xsfoutdev ,
          'A'        TO is_composer_param-xsfoutmode ,
          'X'        TO is_composer_param-xsfformat ,
          'My Mail'  TO is_composer_param-tdtitle.


* For the Graphics
   MOVE : 'GRAPHICS'           TO is_xfsparam-name ,
          'EXTRACT'            TO is_xfsparam-value.
   APPEND is_xfsparam TO is_composer_param-xsfpars.
   MOVE : 'GRAPHICS-DIRECTORY' TO is_xfsparam-name ,
          'MyDirY           TO is_xfsparam-value.
   APPEND is_xfsparam TO is_composer_param-xsfpars.
   MOVE : 'CONTENT-ID'         TO is_xfsparam-name ,
          'ENABLE'             TO is_xfsparam-value.
   APPEND is_xfsparam TO is_composer_param-xsfpars.


* Call the Smartforms
   CALL FUNCTION w_funcname
     EXPORTING
*     ARCHIVE_INDEX        =
*     ARCHIVE_INDEX_TAB    =
*     ARCHIVE_PARAMETERS   =
       control_parameters   = is_control_param
*     MAIL_APPL_OBJ        =
*     MAIL_RECIPIENT       =
*     MAIL_SENDER          =
       output_options       = is_composer_param
       user_settings        = ' '
     IMPORTING
*     DOCUMENT_OUTPUT_INFO =
       job_output_info      = is_job_info
*     JOB_OUTPUT_OPTIONS   =
     EXCEPTIONS
       formatting_error     = 1
       internal_error       = 2
       send_error           = 3
       user_canceled        = 4
       OTHERS               = 5.




* Conversion du HTML Hex en Text.
   LOOP AT is_job_info-xmloutput-trfresult-content
        INTO is_html_raw.
     CONCATENATE w_html_xtxt
                 is_html_raw
                 INTO w_html_xtxt
                 IN BYTE MODE.
   ENDLOOP.
   w_html_xtxt = w_html_xtxt(is_job_info-xmloutput-trfresult-length).
   CALL FUNCTION 'SCP_TRANSLATE_CHARS'
     EXPORTING
       inbuff       = w_html_xtxt
       incode       = '4110'
       outcode      = '0000'
       csubst       = 'X'
       substc_space = 'X'
     IMPORTING
       outbuff      = w_html_txt
       outused      = w_html_len
     EXCEPTIONS
       OTHERS       = 5.
   REPLACE ALL OCCURRENCES OF 'utf-8' IN w_html_txt WITH 'latin1'.
   w_html_len = strlen( w_html_txt ).


* Creation objet pour mail.
   CREATE OBJECT obj_mime_helper.


* Récupère les graphiques.
   it_graphics = is_job_info-xmloutput-xsfgr[].
   LOOP AT it_graphics
        INTO is_graphic.
     CLEAR w_gr_xtxt.
     LOOP AT is_graphic-content
          INTO is_gr_raw.
       CONCATENATE w_gr_xtxt
                   is_gr_raw-line
                   INTO w_gr_xtxt
                   IN BYTE MODE.
     ENDLOOP.
     w_gr_xtxt = w_gr_xtxt(is_graphic-length).
     w_offset = 0.
     w_len    = 255.
     CLEAR it_solix[].
     WHILE w_offset < is_graphic-length.
       w_diff = is_graphic-length - w_offset.
       IF w_diff > w_len.
         is_solix-line = w_gr_xtxt+w_offset(w_len).
       ELSE.
         is_solix-line = w_gr_xtxt+w_offset(w_diff).
       ENDIF.
       APPEND is_solix TO it_solix.
       ADD w_len TO w_offset.
     ENDWHILE.
     CONCATENATE 'MyDir'
                 is_graphic-graphics
                 '.bmp'
                 INTO w_file.
     CONCATENATE 'MyDir'
                 is_graphic-graphics
                 '.bmp'
                 INTO w_content_id.
     w_content_type = is_graphic-httptype.
     w_obj_len      = is_graphic-length.
     CALL METHOD obj_mime_helper->add_binary_part
       EXPORTING
         content      = it_solix
         filename     = w_file
         extension    = 'BMP'
         description  = 'Graphic in BMP format'
         content_type = w_content_type
         length       = w_obj_len
         content_id   = w_content_id.
   ENDLOOP.

   w_offset = 0.
   w_len    = 255.
   WHILE w_offset < w_html_len.
     w_diff = w_html_len - w_offset.
     IF w_diff > w_len.
       is_soli-line = w_html_txt+w_offset(w_len).
     ELSE.
       is_soli-line = w_html_txt+w_offset(w_diff).
     ENDIF.
     APPEND is_soli TO it_soli.
     ADD w_len TO w_offset.
   ENDWHILE.


* Ajoute le corps.
   CALL METHOD obj_mime_helper->set_main_html
     EXPORTING
       content     = it_soli
       filename    = ''
       description = 'My mail'.


* Ajoute le titre
   MOVE is_composer_param-tdtitle TO w_title.
   obj_doc_bcs = cl_document_bcs=>create_from_multirelated(
                   i_subject          = w_title
                   i_importance       = '9'                " 1 / 5 / 9
                   i_multirel_service = obj_mime_helper ).


   CALL METHOD obj_doc_bcs->get_docno
     RECEIVING
       result = w_docno.


   obj_bcs = cl_bcs=>create_persistent( ).
   obj_bcs->set_document( i_document = obj_doc_bcs ).


* add the email address.
   obj_recipient = cl_cam_address_bcs=>create_internet_address(
                     i_address_string 'frederic.girod@everywhere.com' ).

   obj_bcs->add_recipient( i_recipient = obj_recipient ).


* Statut change
   MOVE 'N' TO w_status.
   CALL METHOD obj_bcs->set_status_attributes
     EXPORTING
       i_requested_status = w_status.


* Send the mail.
   obj_bcs->send( ).


* Commit Work.
   IF sy-subrc EQ space.
     COMMIT WORK AND WAIT.
   ELSE.
     ROLLBACK WORK.
   ENDIF.



END-OF-SELECTION.

The code is little more complex.

First, we need to execute the Smartform, but without printing it. We asked SAP to create XDF and XSF, the result was store in the JOB_OUTPUT_INFO.

The form is in Hex format, we used the function SCP_TRANSLATE_CHARS to convert to a text format.

We need also to include the logo in the mail, but not as attachment, so we used the ADD_BINARY_PART method instead of ADD_ATTACHMENT.

Result

Send the Smartform in PDF attachment with a text message.

Create a new Smartform

I need a simple Smartform to put-it in the text message of the email.

The code need to be organized ...

The data :



TYPES : tt_docs TYPE TABLE OF docs.


DATA : w_formname        TYPE tdsfname ,
        w_funcname        TYPE tdsfname ,
        w_status          TYPE bcs_rqst ,
        w_html_xtxt       TYPE xstring ,
        w_html_txt        TYPE string ,
        w_html_len        TYPE i ,
        w_gr_xtxt         TYPE xstring ,
        w_offset          TYPE i ,
        w_len             TYPE i ,
        w_diff            TYPE i ,
        w_file            TYPE string ,
        w_content_type    TYPE w3conttype ,
        w_obj_len         TYPE so_obj_len ,
        w_content_id      TYPE so_obj_des ,
        w_content_id2     TYPE string ,
        w_title           TYPE so_obj_des ,
        w_docno           TYPE so_obj_no ,
        w_doc_size        TYPE i ,
        w_xtxt            TYPE xstring ,

        is_control_param  TYPE ssfctrlop ,
        is_composer_param TYPE ssfcompop ,
        is_soli           TYPE soli ,
        is_job_info       TYPE ssfcrescl ,
        is_xfsparam       TYPE ssfxsfp ,
        is_html_raw       LIKE LINE OF is_job_info-xmloutput-trfresult-content ,
        is_graphic        TYPE ssf_xsf_gr ,
        is_gr_raw         TYPE bapiconten ,
        is_solix          TYPE solix ,
        is_tline          TYPE tline ,

        it_soli           TYPE TABLE OF soli ,
        it_graphics       TYPE tsf_xsf_gr ,
        it_solix          TYPE solix_tab ,
        it_docs           TYPE tt_docs ,
        it_tline          TYPE tline_tab ,

        obj_mime_helper   TYPE REF TO cl_gbt_multirelated_service ,
        obj_bcs           TYPE REF TO cl_bcs ,
        obj_doc_bcs       TYPE REF TO cl_document_bcs ,
        obj_recipient     TYPE REF TO if_recipient_bcs ,
        obj_conv          TYPE REF TO cl_abap_conv_obj.




First part, create the mail with the text message :

START-OF-SELECTION.

*---------------------------------------------------------------------*
*   Create the text message                                           *
*---------------------------------------------------------------------*
* My Smartforms.
   MOVE 'ZMY_SMARTFORMS_002' TO w_formname.


* Get the function module name corresponding of the Smartform.
   CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
     EXPORTING
       formname = w_formname
     IMPORTING
       fm_name  = w_funcname
     EXCEPTIONS
       OTHERS   = 3.
   CHECK sy-subrc EQ space.


* Set the parameters of the forms.
   MOVE : 'X'        TO is_control_param-no_dialog ,
          ' '        TO is_control_param-preview ,
          'X'        TO is_control_param-getotf ,
          sy-langu   TO is_control_param-langu ,
          'PRINTER'  TO is_control_param-device ,
          'X'        TO is_composer_param-tdnoprint ,
          'X'        TO is_composer_param-tdnoprev ,
          'X'        TO is_composer_param-tdfinal ,
          'X'        TO is_composer_param-xdfcmode ,
          ' '        TO is_composer_param-xdf ,
          'X'        TO is_composer_param-xsfcmode ,
          'X'        TO is_composer_param-xsf ,
          ' '        TO is_composer_param-xsfoutdev ,
          'A'        TO is_composer_param-xsfoutmode ,
          'X'        TO is_composer_param-xsfformat ,
          'My Mail'  TO is_composer_param-tdtitle.


* For the Graphics
   MOVE : 'GRAPHICS'           TO is_xfsparam-name ,
          'EXTRACT'            TO is_xfsparam-value.
   APPEND is_xfsparam TO is_composer_param-xsfpars.
   MOVE : 'GRAPHICS-DIRECTORY' TO is_xfsparam-name ,
          'MyDirY           TO is_xfsparam-value.
   APPEND is_xfsparam TO is_composer_param-xsfpars.
   MOVE : 'CONTENT-ID'         TO is_xfsparam-name ,
          'ENABLE'             TO is_xfsparam-value.
   APPEND is_xfsparam TO is_composer_param-xsfpars.


* Call the Smartforms
   CALL FUNCTION w_funcname
     EXPORTING
       control_parameters = is_control_param
       output_options     = is_composer_param
       user_settings      = ' '
     IMPORTING
       job_output_info    = is_job_info
     EXCEPTIONS
       formatting_error   = 1
       internal_error     = 2
       send_error         = 3
       user_canceled      = 4
       OTHERS             = 5.


* Conversion du HTML Hex en Text.
   LOOP AT is_job_info-xmloutput-trfresult-content
        INTO is_html_raw.
     CONCATENATE w_html_xtxt
                 is_html_raw
                 INTO w_html_xtxt
                 IN BYTE MODE.
   ENDLOOP.
   w_html_xtxt = w_html_xtxt(is_job_info-xmloutput-trfresult-length).
   CALL FUNCTION 'SCP_TRANSLATE_CHARS'
     EXPORTING
       inbuff       = w_html_xtxt
       incode       = '4110'
       outcode      = '0000'
       csubst       = 'X'
       substc_space = 'X'
     IMPORTING
       outbuff      = w_html_txt
       outused      = w_html_len
     EXCEPTIONS
       OTHERS       = 5.
   REPLACE ALL OCCURRENCES OF 'utf-8' IN w_html_txt WITH 'latin1'.
   w_html_len = strlen( w_html_txt ).


* Creation objet pour mail.
   CREATE OBJECT obj_mime_helper.


* Récupère les graphiques.
   it_graphics = is_job_info-xmloutput-xsfgr[].
   LOOP AT it_graphics
        INTO is_graphic.
     CLEAR w_gr_xtxt.
     LOOP AT is_graphic-content
          INTO is_gr_raw.
       CONCATENATE w_gr_xtxt
                   is_gr_raw-line
                   INTO w_gr_xtxt
                   IN BYTE MODE.
     ENDLOOP.
     w_gr_xtxt = w_gr_xtxt(is_graphic-length).
     w_offset = 0.
     w_len    = 255.
     CLEAR it_solix[].
     WHILE w_offset < is_graphic-length.
       w_diff = is_graphic-length - w_offset.
       IF w_diff > w_len.
         is_solix-line = w_gr_xtxt+w_offset(w_len).
       ELSE.
         is_solix-line = w_gr_xtxt+w_offset(w_diff).
       ENDIF.
       APPEND is_solix TO it_solix.
       ADD w_len TO w_offset.
     ENDWHILE.
     CONCATENATE 'MyDir'
                 is_graphic-graphics
                 '.bmp'
                 INTO w_file.
     CONCATENATE 'MyDir'
                 is_graphic-graphics
                 '.bmp'
                 INTO w_content_id.
     w_content_type = is_graphic-httptype.
     w_obj_len      = is_graphic-length.
     CALL METHOD obj_mime_helper->add_binary_part
       EXPORTING
         content      = it_solix
         filename     = w_file
         extension    = 'BMP'
         description  = 'Graphic in BMP format'
         content_type = w_content_type
         length       = w_obj_len
         content_id   = w_content_id2.
   ENDLOOP.

   w_offset = 0.
   w_len    = 255.
   WHILE w_offset < w_html_len.
     w_diff = w_html_len - w_offset.
     IF w_diff > w_len.
       is_soli-line = w_html_txt+w_offset(w_len).
     ELSE.
       is_soli-line = w_html_txt+w_offset(w_diff).
     ENDIF.
     APPEND is_soli TO it_soli.
     ADD w_len TO w_offset.
   ENDWHILE.


* Ajoute le corps.
   CALL METHOD obj_mime_helper->set_main_html
     EXPORTING
       content     = it_soli
       filename    = ''
       description = 'My mail'.


* Ajoute le titre
   MOVE is_composer_param-tdtitle TO w_title.
   obj_doc_bcs = cl_document_bcs=>create_from_multirelated(
                   i_subject          = w_title
                   i_importance       = '9'                " 1 / 5 / 9
                   i_multirel_service = obj_mime_helper ).


   CALL METHOD obj_doc_bcs->get_docno
     RECEIVING
       result = w_docno.


   obj_bcs = cl_bcs=>create_persistent( ).
   obj_bcs->set_document( i_document = obj_doc_bcs ).

Second part, create the PDF and add in attachment of the mail.


*---------------------------------------------------------------------*
*   Create the attachment.                                            *
*---------------------------------------------------------------------*

* My Smartforms.
   MOVE 'ZMY_SMARTFORMS' TO w_formname.


* Get the function module name corresponding of the Smartform.
   CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
     EXPORTING
       formname = w_formname
     IMPORTING
       fm_name  = w_funcname
     EXCEPTIONS
       OTHERS   = 3.
   CHECK sy-subrc EQ space.


* Set the parameters of the forms.
   CLEAR : is_control_param, is_composer_param.
   MOVE : 'X'        TO is_control_param-no_dialog ,
          ' '        TO is_control_param-preview ,
          'X'        TO is_control_param-getotf ,
          sy-langu   TO is_control_param-langu ,
          'PRINTER'  TO is_control_param-device ,
          'X'        TO is_composer_param-tdnoprint ,
          'X'        TO is_composer_param-tdnoprev ,
          'X'        TO is_composer_param-tdfinal.


* Call the Smartforms
   CALL FUNCTION w_funcname
     EXPORTING
       control_parameters = is_control_param
       output_options     = is_composer_param
       user_settings      = ' '
     IMPORTING
       job_output_info    = is_job_info
     EXCEPTIONS
       formatting_error   = 1
       internal_error     = 2
       send_error         = 3
       user_canceled      = 4
       OTHERS             = 5.

   break fgi.
* Convert the OTF to PDF.
   CALL FUNCTION 'CONVERT_OTF_2_PDF'
     IMPORTING
       bin_filesize   = w_doc_size
     TABLES
       otf            = is_job_info-otfdata
       doctab_archive = it_docs
       lines          = it_tline
     EXCEPTIONS
       OTHERS         = 3.
   CLEAR w_gr_xtxt.
   CREATE OBJECT obj_conv.

* Change the output format.
   LOOP AT it_tline
        INTO is_tline.
     CALL METHOD obj_conv->convert
       EXPORTING
         inbuff    = is_tline
         outbufflg = 2500
       IMPORTING
         outbuff   = w_xtxt.
     CONCATENATE w_gr_xtxt
                 w_xtxt
                 INTO w_gr_xtxt
                 IN BYTE MODE.
   ENDLOOP.
   w_gr_xtxt = w_gr_xtxt(w_doc_size).
   w_offset = 0.
   w_len    = 255.
   CLEAR it_solix[].
   WHILE w_offset < w_doc_size.
     w_diff = w_doc_size - w_offset.
     IF w_diff > w_len.
       is_solix-line = w_gr_xtxt+w_offset(w_len).
     ELSE.
       is_solix-line = w_gr_xtxt+w_offset(w_diff).
     ENDIF.
     APPEND is_solix TO it_solix.
     ADD w_len TO w_offset.
   ENDWHILE.

   MOVE : 'Attachment'     TO w_title ,
          'Attachment.pdf' TO w_content_id.
   w_content_type = '  '.
   w_obj_len      = w_doc_size.


* Add as attachment the PDF
   CALL METHOD obj_doc_bcs->add_attachment
     EXPORTING
       i_attachment_type    = 'PDF'
       i_attachment_subject = w_content_id
       i_attachment_size    = w_obj_len
       i_att_content_hex    = it_solix.

And finaly send the mail.


* add the email address.
   obj_recipient = cl_cam_address_bcs=>create_internet_address(
                     i_address_string 'frederic.girod@sap.com' ).

   obj_bcs->add_recipient( i_recipient = obj_recipient ).


* Statut change
   MOVE 'N' TO w_status.
   CALL METHOD obj_bcs->set_status_attributes
     EXPORTING
       i_requested_status = w_status.


* Send the mail.
   obj_bcs->send( ).


* Commit Work.
   IF sy-subrc EQ space.
     COMMIT WORK AND WAIT.
   ELSE.
     ROLLBACK WORK.
   ENDIF.



END-OF-SELECTION.

It's a little bit long, but the result is better for the end user.

Result

(next step : result of a report ..)

Fred

30 Comments