cancel
Showing results for 
Search instead for 
Did you mean: 

Smartform objects and parameters code examples

Former Member
0 Kudos

Sending Forms by E-Mail

To send forms as e-mails using SAP Smart Forms, you have to fill the e-mail parameters of the generated function module:

The parameters MAIL_SENDER and MAIL_RECIPIENT to pass the sender and the recipient of the document. To fill these parameters, you have to create the respective BOR objects of object type RECIPIENT and fill their attributes.

The parameter MAIL_APPL_OBJ, which you use to link the application object with the sent document. You have to create a BOR object for this parameter too.

To ensure that SAP Smart Forms evaluates the e-mail parameters, you have to set the DEVICE parameter of the control structure to 'MAIL'.

Has anybody got any code examples for the above problem and creating the BOR objects? I have spent some time searching and cannot find any good coding examples.

Also, how to pass the BOR objects as parameters to the smartform call.

Any help would be greatly appreciated.

Thank you in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Ronoch2 ,

Use the below function module

*Getting the device parameters and transmission mode
  CALL FUNCTION 'WFMC_PREPARE_SMART_FORM'
    EXPORTING
      pi_nast       = nast
      pi_country    = lv_dlv-land
      pi_addr_key   = lv_addr_key
      pi_repid      = sy-repid
      pi_screen     = lc_x
    IMPORTING
      pe_returncode = gv_retcode
      pe_itcpo      = lv_itcpo
      pe_device     = lv_device
      pe_recipient  = lv_recipient
      pe_sender     = lv_sender.
  IF gv_retcode = 0.
*moving the data to composer and control parameters for output
    MOVE-CORRESPONDING lv_itcpo TO lv_composer_param.
    lv_control_param-device      = lv_device.
    lv_control_param-no_dialog   = lc_x.
    lv_control_param-preview     = lc_x.
    lv_control_param-getotf      = lv_itcpo-tdgetotf.
    lv_control_param-langu       = nast-spras.
    lv_composer_param-tdnoprint = space.
  ENDIF.

Thanks

Surendra

Answers (1)

Answers (1)

Former Member
0 Kudos

Thanks for your reply, I solved this and forgot to mark as answered. the code I used to solve problem was as follows


ELSEIF l_nast-nacha = '5'. " external send/email

** General output objects declarations for email of po **
    INCLUDE: <cntn01>.
    TABLES: soud.
    DATA: p_mail_rec_obj TYPE swotobjid,
          p_mail_sen_obj TYPE swotobjid,
          p_mail_app_obj TYPE swotobjid.
    DATA: folder TYPE swc_object,
          BEGIN OF sofmfol_key,
            foldertype LIKE sofm-foltp,
            folderyear LIKE sofm-folyr,
            foldernumber LIKE sofm-folno,
            type LIKE sofm-doctp,
            year LIKE sofm-docyr,
            number LIKE sofm-docno,
            forwarder LIKE soub-usrnam,
          END OF sofmfol_key,
          bor_key LIKE swotobjid-objkey.
* *Internal table to get vendor name and address number
    DATA : BEGIN OF it_vname OCCURS 0,
           name1 LIKE lfa1-name1,
           adrnr LIKE lfa1-adrnr,
           END OF it_vname.
*Internal table to get email_if with address number
    DATA : BEGIN OF it_vemail OCCURS 0,
           email LIKE adr6-smtp_addr,
           END OF it_vemail.

*Accessing name and address number of a vendor
    SELECT SINGLE name1 adrnr FROM lfa1 INTO it_vname
      WHERE lifnr EQ l_nast-parnr.
*Accessing mail id of a vendor
    SELECT SINGLE smtp_addr FROM adr6 INTO it_vemail WHERE addrnumber EQ it_vname-adrnr.
    IF sy-subrc = 0.
      CALL FUNCTION 'CREATE_RECIPIENT_OBJ_PPF'
        EXPORTING
          ip_mailaddr     = it_vemail-email
          ip_type_id      = 'U' "'F' fax number "'U' internet address "'A' external address
        IMPORTING
          ep_recipient_id = p_mail_rec_obj.

      CALL FUNCTION 'CREATE_SENDER_OBJECT_PPF'
        EXPORTING
          ip_sender    = sy-uname
        IMPORTING
          ep_sender_id = p_mail_sen_obj.

      SELECT SINGLE * FROM soud WHERE sapnam LIKE sy-uname AND deleted = ' '.
      IF sy-subrc NE 0.
        CALL FUNCTION 'SO_USER_AUTOMATIC_INSERT'
          EXPORTING
            sapname        = sy-uname
          EXCEPTIONS
            no_insert      = 1
            sap_name_exist = 2
            x_error        = 3
            OTHERS         = 4.
        IF sy-subrc NE 0.
          CLEAR soud.
        ELSE.
          SELECT * FROM soud WHERE sapnam LIKE sy-uname AND deleted = ' '.
          ENDSELECT.
        ENDIF.
      ENDIF.

      CLEAR sofmfol_key.
      sofmfol_key-type = 'FOL'.
      sofmfol_key-year = soud-inbyr.
      sofmfol_key-number = soud-inbno.
      bor_key = sofmfol_key.
      IF NOT bor_key IS INITIAL.
        swc_create_object folder 'SOFMFOL' bor_key.
        IF sy-subrc = 0.
          swc_object_to_persistent folder p_mail_app_obj.
          IF sy-subrc NE 0.
            CLEAR p_mail_app_obj.
          ENDIF.
        ENDIF.
      ELSE.
        CLEAR p_mail_app_obj.
      ENDIF.
    ENDIF.
* sf email code ends here-------------------------------------------
  ENDIF.


 CALL FUNCTION fm_name
    EXPORTING
      gs_ekko              = gs_ekko
      gs_pekko             = gs_pekko
      gs_t024              = gs_t024
      control_parameters   = ssfctrlop
      output_options       = ssfcompop
      user_settings        = ''
      mail_appl_obj        = p_mail_app_obj
      mail_recipient       = p_mail_rec_obj
      mail_sender          = p_mail_sen_obj
*    IMPORTING
*      document_output_info = ssfcrespd
*      job_output_info      = ssfcrescl " otfdata for fax here
*      job_output_options   = ssfcresop
    TABLES
      gt_ekpo              = gt_ekpo
      gt_t001              = gt_t001
      gt_lfa1              = gt_lfa1
      gt_eket              = gt_eket
      gt_t001w             = gt_t001w
    EXCEPTIONS
      formatting_error     = 1
      internal_error       = 2
      send_error           = 3
      user_canceled        = 4
      OTHERS               = 5.