Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Back to Sending Mails - Home Page

Generates PDF output from pre-existing ZFHR_TRAVEL_REQUEST Adobe Form.

Error rendering macro 'code': Invalid value specified for parameter 'lang'
DATA : function TYPE funcname,
       ftype TYPE fpinterfacetype,
       fname TYPE funcname.
DATA : outputparams TYPE sfpoutputparams.

PARAMETER:      p_email   TYPE adr6-smtp_addr OBLIGATORY.

outputparams-nodialog = 'X'.
outputparams-preview = 'X'.
outputparams-dest = 'PDF1'.

outputparams-getpdf = 'X'.

DATA: fp_docparams TYPE sfpdocparams.
DATA: fp_formoutput TYPE fpformoutput.

CALL FUNCTION 'FP_JOB_OPEN'
  CHANGING
    ie_outputparams       = outputparams
* EXCEPTIONS
*   CANCEL                = 1
*   USAGE_ERROR           = 2
*   SYSTEM_ERROR          = 3
*   INTERNAL_ERROR        = 4
*   OTHERS                = 5
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
  EXPORTING
    i_name              = 'ZFHR_TRAVEL_REQUEST'
  IMPORTING
    e_funcname          = function
    e_interface_type    = ftype
    ev_funcname_inbound = fname.

fp_docparams-langu = 'E'.
fp_docparams-country = 'IN'.
fp_docparams-fillable = 'X'.

CALL FUNCTION function
 EXPORTING
   /1bcdwb/docparams        = fp_docparams
   employeename             = '00050104'
 IMPORTING
   /1bcdwb/formoutput       = fp_formoutput
* EXCEPTIONS
*   USAGE_ERROR              = 1
*   SYSTEM_ERROR             = 2
*   INTERNAL_ERROR           = 3
*   OTHERS                   = 4
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'FP_JOB_CLOSE'
* IMPORTING
*   E_RESULT             =
* EXCEPTIONS
*   USAGE_ERROR          = 1
*   SYSTEM_ERROR         = 2
*   INTERNAL_ERROR       = 3
*   OTHERS               = 4
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

************************************************************
*Download file

DATA: filename TYPE string,
 path TYPE string,
 fullpath TYPE string,
 default_extension TYPE string VALUE 'PDF'.
cl_gui_frontend_services=>file_save_dialog(
EXPORTING
default_extension = default_extension
CHANGING
filename = filename
path = path
fullpath = fullpath ).
CHECK fullpath IS NOT INITIAL.

DATA: data_tab TYPE TABLE OF x255.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
  EXPORTING
    buffer     = fp_formoutput-pdf
  TABLES
    binary_tab = data_tab.

*filename = 'E:\adobe\emptest.pdf'.

cl_gui_frontend_services=>gui_download(
EXPORTING
filename = filename
filetype = 'BIN'
CHANGING
data_tab = data_tab ).
cl_gui_frontend_services=>execute(
EXPORTING
document = filename ).

************************************************************
* Mail

* BCS data
DATA  send_request       TYPE REF TO cl_bcs.
DATA  text               TYPE bcsy_text.
DATA  document           TYPE REF TO cl_document_bcs.
DATA  recipient          TYPE REF TO if_recipient_bcs.
DATA: bcs_exception      TYPE REF TO cx_bcs.
DATA  sent_to_all        TYPE os_boolean.
DATA  pdf_content        TYPE solix_tab.
DATA  lp_pdf_size        TYPE so_obj_len.

TRY.
*   --------- create persistent send request ---------------------
    send_request = cl_bcs=>create_persistent( ).

*   --------- add document ---------------------------------------
*   get PDF xstring and convert it to BCS format
    lp_pdf_size = XSTRLEN( fp_formoutput-pdf ).

    pdf_content = cl_document_bcs=>xstring_to_solix(
        ip_xstring = fp_formoutput-pdf ).

    document = cl_document_bcs=>create_document(
          i_type    = 'PDF'
          i_hex     = pdf_content
          i_length  = lp_pdf_size
          i_subject = 'Travel Request form' ).              "#EC NOTEXT

*   add document to send request
    send_request->set_document( document ).

*   --------- add recipient (e-mail address) ---------------------
    recipient = cl_cam_address_bcs=>create_internet_address(
        i_address_string = p_email ).

*   add recipient to send request
    send_request->add_recipient( i_recipient = recipient ).

*   --------- send document --------------------------------------
    sent_to_all = send_request->send(
        i_with_error_screen = 'X' ).

    IF sent_to_all = 'X'.
      MESSAGE i022(so).
    ENDIF.

*   --------- explicit 'commit work' is mandatory! ---------------
    COMMIT WORK.

* ------------------------------------------------------------------
* *            exception handling
* ------------------------------------------------------------------
* * replace this very rudimentary exception handling
* * with your own one !!!
* ------------------------------------------------------------------
  CATCH cx_bcs INTO bcs_exception.
    WRITE: text-001.
    WRITE: text-002, bcs_exception->error_type.
    EXIT.

ENDTRY.
  • No labels