Skip to Content
Author's profile photo Frederic Girod

Sending Mail using Oo (2) – Smartforms

Creation of a simple Smartform

Import of a logo

Transaction SE78

SE78_1.png

Double-click on the line BMAP

/wp-content/uploads/2013/05/se78_2_224441.png

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

SE78_3.png

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

Smartforms_1.png

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

Enter a text ..

Smartforms_2.png

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

/wp-content/uploads/2013/05/smartforms_3_224450.png

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 sysubrc EQ space.

* Set the parameters of the forms.
   MOVE : ‘X’            TO is_control_paramno_dialog ,
          ‘X’            TO is_control_parampreview ,
          ‘ ‘            TO is_control_paramgetotf ,
          sylangu        TO is_control_paramlangu .

   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 sysubrc EQ space.

* Set the parameters of the forms.
   MOVE : ‘X’            TO is_control_paramno_dialog ,
          ‘ ‘            TO is_control_parampreview ,
          ‘ ‘            TO is_control_paramgetotf ,
          sylangu        TO is_control_paramlangu ,
          ‘MAIL’          TO is_control_paramdevice.

* 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      = syuname
     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 syuname.
   CHECK sysubrc EQ space.
   MOVE : ‘FOL’    TO is_sofmkdoctp ,
          w_number TO is_sofmkdocyr ,
          w_year   TO is_sofmkdocno .
   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 sysubrc 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 :

SOST_6.png

And the mail :

Capture d’écran 2013-05-31 à 09.17.19.png

The attachment :

Capture d’écran 2013-05-31 à 09.17.49.png

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_infoxmloutputtrfresultcontent ,
        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 sysubrc EQ space.

* Set the parameters of the forms.
   MOVE : ‘X’        TO is_control_paramno_dialog ,
          ‘ ‘        TO is_control_parampreview ,
          ‘X’        TO is_control_paramgetotf ,
          sylangu   TO is_control_paramlangu ,
          ‘PRINTER’  TO is_control_paramdevice ,
          ‘X’        TO is_composer_paramtdnoprint ,
          ‘X’        TO is_composer_paramtdnoprev ,
          ‘X’        TO is_composer_paramtdfinal ,
          ‘X’        TO is_composer_paramxdfcmode ,
          ‘ ‘        TO is_composer_paramxdf ,
          ‘X’        TO is_composer_paramxsfcmode ,
          ‘X’        TO is_composer_paramxsf ,
          ‘ ‘        TO is_composer_paramxsfoutdev ,
          ‘A’        TO is_composer_paramxsfoutmode ,
          ‘X’        TO is_composer_paramxsfformat ,
          ‘My Mail’  TO is_composer_paramtdtitle.

* For the Graphics
   MOVE : ‘GRAPHICS’           TO is_xfsparamname ,
          ‘EXTRACT’            TO is_xfsparamvalue.
   APPEND is_xfsparam TO is_composer_paramxsfpars.
   MOVE : ‘GRAPHICS-DIRECTORY’ TO is_xfsparamname ,
          ‘MyDirY           TO is_xfsparamvalue.
   APPEND is_xfsparam TO is_composer_paramxsfpars.
   MOVE : ‘CONTENT-ID’         TO is_xfsparamname ,
          ‘ENABLE’             TO is_xfsparamvalue.
   APPEND is_xfsparam TO is_composer_paramxsfpars.

* 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_infoxmloutputtrfresultcontent
        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_infoxmloutputtrfresultlength).
   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_infoxmloutputxsfgr[].
   LOOP AT it_graphics
        INTO is_graphic.
     CLEAR w_gr_xtxt.
     LOOP AT is_graphiccontent
          INTO is_gr_raw.
       CONCATENATE w_gr_xtxt
                   is_gr_rawline
                   INTO w_gr_xtxt
                   IN BYTE MODE.
     ENDLOOP.
     w_gr_xtxt = w_gr_xtxt(is_graphiclength).
     w_offset = 0.
     w_len    = 255.
     CLEAR it_solix[].
     WHILE w_offset < is_graphiclength.
       w_diff = is_graphiclength w_offset.
       IF w_diff > w_len.
         is_solixline = w_gr_xtxt+w_offset(w_len).
       ELSE.
         is_solixline = w_gr_xtxt+w_offset(w_diff).
       ENDIF.
       APPEND is_solix TO it_solix.
       ADD w_len TO w_offset.
     ENDWHILE.
     CONCATENATE ‘MyDir’
                 is_graphicgraphics
                 ‘.bmp’
                 INTO w_file.
     CONCATENATE ‘MyDir’
                 is_graphicgraphics
                 ‘.bmp’
                 INTO w_content_id.
     w_content_type = is_graphichttptype.
     w_obj_len      = is_graphiclength.
     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_soliline = w_html_txt+w_offset(w_len).
     ELSE.
       is_soliline = 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_paramtdtitle 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 sysubrc 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

Capture d’écran 2013-05-31 à 10.15.57.png

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.

/wp-content/uploads/2013/05/smartforms_4_224647.png

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_infoxmloutputtrfresultcontent ,
        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 sysubrc EQ space.

* Set the parameters of the forms.
   MOVE : ‘X’        TO is_control_paramno_dialog ,
          ‘ ‘        TO is_control_parampreview ,
          ‘X’        TO is_control_paramgetotf ,
          sylangu   TO is_control_paramlangu ,
          ‘PRINTER’  TO is_control_paramdevice ,
          ‘X’        TO is_composer_paramtdnoprint ,
          ‘X’        TO is_composer_paramtdnoprev ,
          ‘X’        TO is_composer_paramtdfinal ,
          ‘X’        TO is_composer_paramxdfcmode ,
          ‘ ‘        TO is_composer_paramxdf ,
          ‘X’        TO is_composer_paramxsfcmode ,
          ‘X’        TO is_composer_paramxsf ,
          ‘ ‘        TO is_composer_paramxsfoutdev ,
          ‘A’        TO is_composer_paramxsfoutmode ,
          ‘X’        TO is_composer_paramxsfformat ,
          ‘My Mail’  TO is_composer_paramtdtitle.

* For the Graphics
   MOVE : ‘GRAPHICS’           TO is_xfsparamname ,
          ‘EXTRACT’            TO is_xfsparamvalue.
   APPEND is_xfsparam TO is_composer_paramxsfpars.
   MOVE : ‘GRAPHICS-DIRECTORY’ TO is_xfsparamname ,
          ‘MyDirY           TO is_xfsparamvalue.
   APPEND is_xfsparam TO is_composer_paramxsfpars.
   MOVE : ‘CONTENT-ID’         TO is_xfsparamname ,
          ‘ENABLE’             TO is_xfsparamvalue.
   APPEND is_xfsparam TO is_composer_paramxsfpars.

* 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_infoxmloutputtrfresultcontent
        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_infoxmloutputtrfresultlength).
   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_infoxmloutputxsfgr[].
   LOOP AT it_graphics
        INTO is_graphic.
     CLEAR w_gr_xtxt.
     LOOP AT is_graphiccontent
          INTO is_gr_raw.
       CONCATENATE w_gr_xtxt
                   is_gr_rawline
                   INTO w_gr_xtxt
                   IN BYTE MODE.
     ENDLOOP.
     w_gr_xtxt = w_gr_xtxt(is_graphiclength).
     w_offset = 0.
     w_len    = 255.
     CLEAR it_solix[].
     WHILE w_offset < is_graphiclength.
       w_diff = is_graphiclength w_offset.
       IF w_diff > w_len.
         is_solixline = w_gr_xtxt+w_offset(w_len).
       ELSE.
         is_solixline = w_gr_xtxt+w_offset(w_diff).
       ENDIF.
       APPEND is_solix TO it_solix.
       ADD w_len TO w_offset.
     ENDWHILE.
     CONCATENATE ‘MyDir’
                 is_graphicgraphics
                 ‘.bmp’
                 INTO w_file.
     CONCATENATE ‘MyDir’
                 is_graphicgraphics
                 ‘.bmp’
                 INTO w_content_id.
     w_content_type = is_graphichttptype.
     w_obj_len      = is_graphiclength.
     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_soliline = w_html_txt+w_offset(w_len).
     ELSE.
       is_soliline = 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_paramtdtitle 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 sysubrc EQ space.

* Set the parameters of the forms.
   CLEAR : is_control_param, is_composer_param.
   MOVE : ‘X’        TO is_control_paramno_dialog ,
          ‘ ‘        TO is_control_parampreview ,
          ‘X’        TO is_control_paramgetotf ,
          sylangu   TO is_control_paramlangu ,
          ‘PRINTER’  TO is_control_paramdevice ,
          ‘X’        TO is_composer_paramtdnoprint ,
          ‘X’        TO is_composer_paramtdnoprev ,
          ‘X’        TO is_composer_paramtdfinal.

* 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_infootfdata
       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_solixline = w_gr_xtxt+w_offset(w_len).
     ELSE.
       is_solixline = 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 sysubrc 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

Capture d’écran 2013-05-31 à 11.05.44.png

Capture d’écran 2013-05-31 à 11.11.48.png

(next step : result of a report ..)

Fred

Assigned Tags

      30 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Gaurab Banerji
      Gaurab Banerji

      useful share.. thanks !!!!

      Author's profile photo zafar karnalkar
      zafar karnalkar

      Hi,

      Nice document, very helpful, Just want to know I want to display SF in the email body as the concept is shown above, but in my SF there are tables , How to include th tables with header and item details with all the borders and color as per we have design in SF.

      Author's profile photo Frederic Girod
      Frederic Girod
      Blog Post Author

      Hi Zafar,

      I'm surpris you have problem with tables & headers .. it works fine for me for all the smart forms .. could you give us more input ?

      regards

      Fred

      Author's profile photo zafar karnalkar
      zafar karnalkar

      Hellow Sir,

         I have created the SF with one simple table and send the email with SF in the email Body but the table which I can see in normal print preview of SF with all the data and table borders, that is not coming in the email body, only the table text are there without the table borders.

      There previous comment I have mention 'header'  that is not the problem actually, borders are not coming.

      Author's profile photo Frederic Girod
      Frederic Girod
      Blog Post Author

      I will try to make a complex test.

      regards

      Fred

      Author's profile photo Krishna K
      Krishna K

      Hi Frederic,

         can we send a mail with password protection(without storing into local system).

      if yes how can we do the validation.

      Thanks in advance,

      Krishna

      Author's profile photo Gurunath Kumar Dadamu
      Gurunath Kumar Dadamu

      Hi,

      This is very useful document.all this scenarios will be useful mostly in all project.Thanks for your effort on this document.

      Regards,

      Gurunath

      Author's profile photo Former Member
      Former Member

      Well... Thats nicely put... All together....

      Can make a utility for mails like this 🙂 nice idea

      Thanks.

      Author's profile photo Ramesh T
      Ramesh T

      Hi Fedric,

      Very user full document.... Thank for posting...

      Regards,

      Ramesh.T

      Author's profile photo Former Member
      Former Member

      Thanks Fedric,

      Good Document 🙂 .

      Regard's

      Smruti

      Author's profile photo Former Member
      Former Member

      Hi Fred,

      Gr8 work man, real effort appreciate it keep up the good work.

      Regards

      Author's profile photo Former Member
      Former Member

      Very Nice.......Learn lot in single document....Thanks

      Author's profile photo Sijin Chandran
      Sijin Chandran

      Very thanks for this Informative Innovative Document 🙂

      Author's profile photo Former Member
      Former Member

      very nice document..thanks for sharing .....

      Author's profile photo Former Member
      Former Member

      Hi Frederic

      Very useful document.

      Thanks for sharing the document. 😎

      Author's profile photo Former Member
      Former Member

      nice document.

      Thanks for Sharing..

      Author's profile photo Former Member
      Former Member

      Hi Frederic ,

      Thanks for sharing this document .

      I am doing send the smartform by email case .I copied your code and just changed two things in it :

      1. Smartform name

      2. reciver email address.

      Now on executing this print program , it is not giving any error but it is not sending the email .I checked in sost transaction .

      Can you please suggest the solution?

      Thanks

      Author's profile photo Frederic Girod
      Frederic Girod
      Blog Post Author

      Hi,

      Did you see something in the SOST trans. ?

      regards

      Fred

      Author's profile photo Former Member
      Former Member

      Hi Frederic ,

      I checked in sost transaction . Nothing is there related to my form .Just now i discussed with Basis people , there might be some problem in SCOT configuration .
      I ll get back to you after getting response from their side .

      Thanks for the reply .

      Author's profile photo Ahmad Feisal Abdul Halim
      Ahmad Feisal Abdul Halim

      Hi,

      very useful document

      regards,

      Feisal

      Author's profile photo Arnab Das
      Arnab Das

      awesome ..... 😀

      Author's profile photo José Guadalupe Saldivar Veloz
      José Guadalupe Saldivar Veloz

      Excelent!!!

      Very helpful

      Thanks Frederic

      Author's profile photo Thangam Perumal
      Thangam Perumal

      Hi Frederic,

                        Nice post... Keep posting........

      Regards,

      Thangam.P

      Author's profile photo Ranjit Kumar
      Ranjit Kumar

      Hi Frederic,

      Nice document. Share your knowledge to help us.

      Regards,

      Ranjit Kumar.

      Author's profile photo Former Member
      Former Member

      Great post ..

        Thanks

      Author's profile photo Former Member
      Former Member

      Hello,

      Getting error

      The type "SWC_OBJECT" is unknown, but there is a type with the similar name "OBJECT". "OBJECT".
      Author's profile photo Sandra Rossi
      Sandra Rossi

      You forgot to include the line INCLUDE <CNTN01> which is mentioned at the beginning of the code.

      Author's profile photo Former Member
      Former Member

      Dear Sandra,

      After adding line for include it gives error.

      OTF end command // missing in OTF Data

      Author's profile photo Sandra Rossi
      Sandra Rossi

      Not enough information. You should open a thread and mention both this document, and attach the full short dump.

      Author's profile photo Rodrigo Nucci Aoki
      Rodrigo Nucci Aoki

      Hi, Frédéric.

      In the case 'Send the Smartform in PDF attachment with a text message',

      'First part, create the mail with the text message', is it necessary to create another smartforms ('ZMY_SMARTFORMS_002'), with the text message (Hello, Please the attachment ...)?

          

      Or, is it possible "write" the text (e-mail body) in another way?

       

      Thanks