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 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 .

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       = [email protected]
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 :

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_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 [email protected]).

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

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_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_info??