Docstoc

SmartForm_mail_as_PDF

Document Sample
SmartForm_mail_as_PDF Powered By Docstoc
					       Programme de test pour envoi d’un smartform en tant que PDF par mail

Voici le programme :
REPORT ztest_sf.

TABLES : soud.

INCLUDE <cntn01>.
INCLUDE cnt4defs.

DATA: g_mail_rec_obj TYPE swotobjid,
      g_mail_sen_obj TYPE swotobjid,
      g_mail_app_obj TYPE swotobjid,
      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,
      g_cont_par     TYPE ssfctrlop,
      g_out          TYPE STANDARD TABLE OF usr02,
      g_output       type SSFCOMPOP,
      w_ssfcrespd    TYPE ssfcrespd,
      w_ssfcrescl    TYPE ssfcrescl,
      w_ssfcresop    TYPE ssfcresop,
      i_rawdata      TYPE STANDARD TABLE OF tline,
      l_length       TYPE i,
      l_len(12)      TYPE c,
      i_otfdata      TYPE tsfotf,
      w_otf          TYPE itcoo,
      w_raw          TYPE tline.

PARAMETERS : g_mail TYPE ppfdmailad.

IF NOT g_mail IS INITIAL AND
   NOT g_mail = 'PDF'.
* Get BOR-Objects for Recipient, Sender und Applikation
  PERFORM mail_recipient_object CHANGING g_mail_rec_obj.
  PERFORM mail_sender_object    CHANGING g_mail_sen_obj.
  PERFORM mail_appl_object      CHANGING g_mail_app_obj.
  g_cont_par-device = 'MAIL'.
ELSEIF g_mail = 'PDF'.
  g_cont_par-getotf = 'X'.
  g_cont_par-no_dialog = 'X'.
ELSEIF g_mail IS INITIAL.
  g_cont_par-no_dialog = 'X'.
  g_cont_par-preview = 'X'.
ENDIF.

*--- Select data
SELECT * INTO CORRESPONDING FIELDS OF TABLE g_out
         FROM usr02.
*--- Title
g_output-tdtitle = 'Test USER'.
*--- Calling Smartform
CALL FUNCTION '/1BCDWB/SF00000068'
     EXPORTING
           control_parameters   = g_cont_par
           mail_appl_obj        = g_mail_app_obj
           mail_recipient       = g_mail_rec_obj
           mail_sender          = g_mail_sen_obj
           output_options       = g_output
           user_settings        = ' '
     IMPORTING
          document_output_info = w_ssfcrespd
          job_output_info      = w_ssfcrescl
          job_output_options   = w_ssfcresop
     TABLES
          i_out                = g_out
     EXCEPTIONS
          formatting_error     = 1
          internal_error       = 2
          send_error           = 3
          user_canceled        = 4
          OTHERS               = 5.
IF g_mail = 'PDF'.
  CLEAR i_otfdata.
  i_otfdata = w_ssfcrescl-otfdata[].
  CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'
       EXPORTING
            i_otf = i_otfdata.
ENDIF.

*&---------------------------------------------------------------------*
*& Form mail_recipient_object
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_G_MAIL_REC_OBJ text
*----------------------------------------------------------------------*
FORM mail_recipient_object CHANGING p_mail_rec_obj TYPE swotobjid.

  DATA : g_rec TYPE so_escape VALUE 'U'. "'P' "private group

  CALL FUNCTION 'CREATE_RECIPIENT_OBJ_PPF'
       EXPORTING
            ip_mailaddr       = g_mail
            ip_type_id        = g_rec
       IMPORTING
            ep_recipient_id   = p_mail_rec_obj
       EXCEPTIONS
            invalid_recipient = 1
            OTHERS            = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

ENDFORM. " mail_recipient_object

*&---------------------------------------------------------------------*
*& Form mail_sender_object
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_G_MAIL_SEN_OBJ text
*----------------------------------------------------------------------*
FORM mail_sender_object CHANGING p_mail_sen_obj TYPE swotobjid.
  CALL FUNCTION 'CREATE_SENDER_OBJECT_PPF'
       EXPORTING
            ip_sender      = sy-uname
       IMPORTING
            ep_sender_id   = p_mail_sen_obj
       EXCEPTIONS
            invalid_sender = 1
            OTHERS         = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

ENDFORM. " mail_sender_object

*&---------------------------------------------------------------------*
*& Form mail_appl_object
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_G_MAIL_APP_OBJ text
*----------------------------------------------------------------------*
FORM mail_appl_object CHANGING p_mail_app_obj TYPE swotobjid.


  SELECT * FROM soud WHERE sapnam LIKE sy-uname AND deleted = ' '.
  ENDSELECT.
  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.

ENDFORM. " mail_appl_object

Voici l’ écran de sélection pour le test :




En laissant blanc, on ouvre le smartform en print preview, en tapant PDF, on ouvre une
fenêtre PDF viewer et en donnant une adresse e-mail (valide !) on envoi le PDF par mail…

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:8
posted:4/5/2013
language:French
pages:3