Convertion of Smart form to pdf and sending mail to vendor for Invoice

Hi All...
now I am getting the output form of Invoice by the T-code  VF02
here Im using Zreport & Zform...
my requirment is to convert smartform output to PDF and send as an e-mail attachment on my Existing report
where I  use the FM - CONVERT_OTF_2_PDF ..
here my code
REPORT  yinvoice_is.
TABLES: vbrk,vbrp, vbak, vbap, vbkd .
DATA : it_vbap TYPE STANDARD TABLE OF vbap WITH HEADER LINE ,
       it_vbrk LIKE STANDARD TABLE OF vbrk with header line,
       it_vbkd TYPE STANDARD TABLE OF vbkd WITH HEADER LINE ,
       it_vbrp TYPE STANDARD TABLE OF vbrp WITH HEADER LINE ,
       it_vbrp1 TYPE STANDARD TABLE OF vbrp WITH HEADER LINE ,
       it_vbfa TYPE STANDARD TABLE OF vbfa WITH HEADER LINE ,
       it_adrc1 TYPE STANDARD TABLE OF adrc WITH HEADER LINE,
       it_adrc2 TYPE STANDARD TABLE OF adrc WITH HEADER LINE.
DATA: sum TYPE vbrp-kzwi5.
DATA: v_vkbur  TYPE vkbur,
      v_adrnr1 TYPE adrnr,
      v_adrnr2 TYPE adrnr,
      v_vbelv  TYPE vbelv,
      v_delch  TYPE vbeln,
      v_bstkd  TYPE bstkd,
      v_kdmat  TYPE kdmat,
      v_kwert  TYPE kwert.
DATA : fm_name TYPE rs38l_fnam.
PARAMETER p_inv_no LIKE vbrk-vbeln OBLIGATORY  .
Selecting Data
SELECT VBELN
        ERDAT
        VKORG
        KUNRG
        STCEG
        NETWR
        MWSBK
        KNUMV
        KUNAG
        REGIO
  FROM vbrk
  INTO CORRESPONDING FIELDS OF TABLE it_vbrk
  WHERE vbeln = p_inv_no .
SELECT matnr
       kzwi1
       kzwi2
       kzwi3
       kzwi4
       kzwi5
       netwr
       mwsbp
       meins
       fklmg
       arktx
       FROM vbrp
  INTO CORRESPONDING FIELDS OF TABLE it_vbrp
  WHERE vbeln = p_inv_no .
Selecting Sales Order No.
SELECT  SINGLE vbelv
  FROM  vbfa
  INTO  v_vbelv
  WHERE vbeln = p_inv_no
  AND   vbtyp_v = 'C'.
IF sy-subrc = 0.
Selecting Delivery Challan...
  SELECT  SINGLE vbeln
    FROM  vbfa
    INTO  v_delch
    WHERE vbelv = v_vbelv
    AND   vbtyp_n = 'J'.
  SELECT SINGLE bstkd
    FROM vbkd
    INTO v_bstkd
    WHERE vbeln = v_vbelv .
  SELECT matnr kdmat
    FROM vbap
    INTO CORRESPONDING FIELDS OF TABLE it_vbap
    WHERE vbeln = v_vbelv.
ENDIF.
READ TABLE it_vbrk INDEX 1.
IF sy-subrc = 0.
  SELECT SINGLE kwert
    FROM konv
    INTO v_kwert
    WHERE knumv = iT_vbrk-knumv
    AND   kschl = 'HD00'.
ENDIF.
Selecting From Address
SELECT SINGLE vkbur
  FROM vbak
  INTO v_vkbur
  WHERE vbeln = v_vbelv.
IF sy-subrc = 0.
  SELECT SINGLE adrnr
    FROM tvbur
    INTO v_adrnr1
    WHERE vkbur = v_vkbur.
  IF sy-subrc = 0.
    SELECT SINGLE *
      FROM adrc
      INTO CORRESPONDING FIELDS OF it_adrc1
      WHERE addrnumber = v_adrnr1.
      APPEND it_adrc1.
  ENDIF.
ENDIF.
APPEND it_adrc.
Selecting TO Address
SELECT SINGLE adrnr
  FROM vbpa
  INTO v_adrnr2
  WHERE vbeln = p_inv_no
  AND   parvw = 'RE'.
IF sy-subrc = 0.
  SELECT SINGLE *
    FROM adrc
    INTO CORRESPONDING FIELDS OF it_adrc2
    WHERE addrnumber = v_adrnr2.
    APPEND it_adrc2.
ENDIF.
Calling Function Module
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  EXPORTING
    formname                 = 'YINVOICE_IS'
  VARIANT                  = ' '
  DIRECT_CALL              = ' '
IMPORTING
   fm_name                  = fm_name
EXCEPTIONS
  NO_FORM                  = 1
  NO_FUNCTION_MODULE       = 2
  OTHERS                   = 3
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Calling Function Module
CALL FUNCTION fm_name
*'/1BCDWB/SF00000496'
  EXPORTING
  ARCHIVE_INDEX              =
  ARCHIVE_INDEX_TAB          =
  ARCHIVE_PARAMETERS         =
  CONTROL_PARAMETERS         =
  MAIL_APPL_OBJ              =
  MAIL_RECIPIENT             =
  MAIL_SENDER                =
  OUTPUT_OPTIONS             =
  USER_SETTINGS              = 'X'
    i_vbelv                    = v_vbelv
    i_bstkd                    = v_bstkd
    i_kdmat                    = v_kdmat
    i_kwert                    = v_kwert
    i_delch                    = v_delch
IMPORTING
  DOCUMENT_OUTPUT_INFO       =
  JOB_OUTPUT_INFO            =
  JOB_OUTPUT_OPTIONS         =
  TABLES
    it_vbrk                    = it_vbrk
    it_vbrp                    = it_vbrp
    it_vbap                    = it_vbap
    it_adrc1                   = it_adrc1
    it_adrc2                   = it_adrc2
EXCEPTIONS
  FORMATTING_ERROR           = 1
  INTERNAL_ERROR             = 2
  SEND_ERROR                 = 3
  USER_CANCELED              = 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.
ENDFORM.                    "ENTRY

hi,
use this code..
DATA: i_otf    TYPE itcoo OCCURS 0 WITH HEADER LINE,
      i_tline  TYPE TABLE OF tline WITH HEADER LINE,
      i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
Objects to send mail.
      i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
      i_objtxt  LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      i_objbin  LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
Variables declarations
      v_len_in LIKE sood-objlen,                            "#EC NEEDED
      v_lines_txt TYPE i,
      v_lines_bin TYPE i,
Work Area declarations
      w_ctrlop    TYPE ssfctrlop,
      w_return    TYPE ssfcrescl,
      w_compop    TYPE ssfcompop,
      wa_objhead  TYPE soli_tab,
      wa_doc_chng TYPE sodocchgi1,
      wa_buffer   TYPE string.            "To convert from 132 to 255
Put a IF ELSE condition whether u want form output or E-mail output..
if it is a E-mail.. then call a small Sub-routine within your program..
FORM f_email .
  w_ctrlop-getotf    = 'X'.
  w_ctrlop-no_dialog = 'X'.
  w_compop-tdnoprev  = 'X'.
  CALL FUNCTION fnam
    EXPORTING
      control_parameters = w_ctrlop
      output_options     = w_compop
      nast               = nast
      v_tcode            = v_tcode
    IMPORTING
      job_output_info    = w_return
    TABLES
      it_vbdkr           = it_tvbdkr[]
      it_vbdpr           = tvbdpr[]
      it_zglentitycode   = it_zglentitycode[]
      it_vttk            = it_vttk[]
      it_kna1            = it_kna1[]
      it_t005            = it_t005[]
      it_adrc            = it_adrc[]
      it_ekpo            = it_ekpo[]
      it_ekko            = it_ekko[]
      it_vbrp            = it_vbrp[]
      it_mara            = it_mara[]
      it_vbrk            = it_vbrk[]
      it_likp            = it_likp[]
      it_vttp            = it_vttp[]
      it_t001            = it_t001[]
      it_zlogdely        = it_zlogdely[]
      it_prod            = it_prod[]
      it_lineitems       = it_lineitems[]
      it_tvzbt           = it_tvzbt[]
      it_t173t           = it_t173t[]
      it_t005t           = it_t005t[]
      it_zplant          = it_zplant[]
      it_stxbitmaps      = it_stxbitmaps[]
      it_prod_desc       = it_prod_desc[].
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  i_otf[] = w_return-otfdata[].
*Converting the  OFT format data  to  PDf format
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format        = 'PDF'
      max_linewidth = 132
    IMPORTING
      bin_filesize  = v_len_in
    TABLES
      otf           = i_otf
      lines         = i_tline.
  LOOP AT i_tline.
    TRANSLATE i_tline USING '~'.
    CONCATENATE wa_buffer i_tline INTO wa_buffer.
  ENDLOOP.
  TRANSLATE wa_buffer USING '~'.
  DO.
    i_record = wa_buffer.
    APPEND i_record.
    SHIFT wa_buffer LEFT BY 255 PLACES.
    IF wa_buffer IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.
Attachment
  REFRESH:
    i_reclist,
    i_objtxt,
    i_objbin,
    i_objpack.
  CLEAR wa_objhead.
  i_objbin[] = i_record[].
Create Message Body
Title and Description
  i_objtxt = 'COMMERCIAL INVOICE'.
  APPEND i_objtxt.
  DESCRIBE TABLE i_objtxt LINES v_lines_txt.
  READ TABLE i_objtxt INDEX v_lines_txt.
  wa_doc_chng-obj_name   = 'COMMERCIAL INVOICE'.
  wa_doc_chng-expiry_dat = sy-datum + 10.
  wa_doc_chng-obj_descr  = 'COMMERCIAL INVOICE'.
  wa_doc_chng-sensitivty = 'F'.
  wa_doc_chng-doc_size   = v_lines_txt * 255.
  CLEAR i_objpack-transf_bin.
  i_objpack-head_start = 1.
  i_objpack-head_num   = 0.
  i_objpack-body_start = 1.
  i_objpack-body_num   = v_lines_txt.
  i_objpack-doc_type   = 'RAW'.
  APPEND i_objpack.
Attachment
(pdf-Attachment)
  i_objpack-transf_bin = 'X'.
  i_objpack-head_start = 1.
  i_objpack-head_num   = 0.
  i_objpack-body_start = 1.
  DESCRIBE TABLE i_objbin LINES v_lines_bin.
  READ TABLE i_objbin INDEX v_lines_bin.
  i_objpack-doc_size =  v_lines_bin * 255 .
  i_objpack-body_num  = v_lines_bin.
  i_objpack-doc_type  = 'PDF'.
  i_objpack-obj_name  = 'COMMERCIAL INVOICE'.
  i_objpack-obj_descr = 'COMMERCIAL INVOICE'.
  APPEND i_objpack.
  IF it_adr6[] IS NOT INITIAL.
    LOOP AT it_adr6 INTO wa_adr6.
      CLEAR i_reclist.
      i_reclist-receiver = wa_adr6-smtp_addr.
      i_reclist-rec_type = 'U'.
      i_reclist-com_type = 'INT'.
      APPEND i_reclist.
    ENDLOOP.
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
      EXPORTING
        document_data = wa_doc_chng
        put_in_outbox = 'X'
      TABLES
        packing_list  = i_objpack
        object_header = wa_objhead
        contents_bin  = i_objbin
        contents_txt  = i_objtxt
        receivers     = i_reclist.
  ENDIF.
ENDFORM.                    " f_email
regards
vijay

Similar Messages

  • Convertion of Smart form to pdf and sending mail to vendor for PO

    Hello all,
    I have modified a standard PO Smartform and running it through ME23N.
    In this i have to convert it to a pdf file and then send it through mail to the vendor.
    I have found out FMs'CONVERT_OTF'and
    'SO_NEW_DOCUMENT_ATT_SEND_API1'
    to convert it and send mail. But can u tell me how to go about using it.
    As i am using a standard program do i have to copy this prog to zprog and then call the fm out there. I am not sure.
    Thanks
    Salil

    Hi,
    Here is the sample code.If you find this as useful,kindly reward points by clicking the star on the left of reply.
    Internal Table declarations
    DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
          i_tline TYPE TABLE OF tline WITH HEADER LINE,
          i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
          i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    Objects to send mail.
          i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
          i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
    Work Area declarations
          w_objhead TYPE soli_tab,
          w_ctrlop TYPE ssfctrlop,
          w_compop TYPE ssfcompop,
          w_return TYPE ssfcrescl,
          w_doc_chng typE sodocchgi1,
          w_data TYPE sodocchgi1,
          w_buffer TYPE string,"To convert from 132 to 255
    Variables declarations
          v_form_name TYPE rs38l_fnam,
          v_len_in LIKE sood-objlen,
          v_len_out LIKE sood-objlen,
          v_len_outn TYPE i,
          v_lines_txt TYPE i,
          v_lines_bin TYPE i.
    call function 'SSF_FUNCTION_MODULE_NAME'
         exporting
              formname           = 'ZZZ_TEST2'
         importing
              fm_name            = v_form_name
         exceptions
              no_form            = 1
              no_function_module = 2
              others             = 3.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    w_ctrlop-getotf = 'X'.
    w_ctrlop-no_dialog = 'X'.
    w_compop-tdnoprev = 'X'.
    CALL FUNCTION v_form_name
         EXPORTING
              control_parameters = w_ctrlop
              output_options     = w_compop
              user_settings      = 'X'
         IMPORTING
              job_output_info    = w_return
         EXCEPTIONS
              formatting_error   = 1
              internal_error     = 2
              send_error         = 3
              user_canceled      = 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.
    i_otf[] = w_return-otfdata[].
    CALL FUNCTION 'CONVERT_OTF'
         EXPORTING
              format                = 'PDF'
              max_linewidth         = 132
         IMPORTING
              bin_filesize          = v_len_in
         TABLES
              otf                   = i_otf
              lines                 = i_tline
         EXCEPTIONS
              err_max_linewidth     = 1
              err_format            = 2
              err_conv_not_possible = 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.
    Convert PDF from 132 to 255.
    LOOP AT i_tline.
    Replacing space by ~
      TRANSLATE i_tline USING ' ~'.
      CONCATENATE w_buffer i_tline INTO w_buffer.
    ENDLOOP.
    Replacing ~ by space
    TRANSLATE w_buffer USING '~ '.
    DO.
      i_record = w_buffer.
    Appending 255 characters as a record
      APPEND i_record.
      SHIFT w_buffer LEFT BY 255 PLACES.
      IF w_buffer IS INITIAL.
        EXIT.
      ENDIF.
    ENDDO.
    Refresh: i_reclist,
             i_objtxt,
             i_objbin,
             i_objpack.
    clear    w_objhead.
    Object with PDF.
    i_objbin[] = i_record[].
    DESCRIBE TABLE i_objbin LINES v_lines_bin.
    Object with main text of the mail.
    i_objtxt = 'Find attached the output of the smart form.'.
    APPEND i_objtxt.
    i_objtxt = 'Regards,'.
    APPEND i_objtxt.
    i_objtxt = 'J.Jayanthi'.
    APPEND i_objtxt.
    DESCRIBE TABLE i_objtxt LINES v_lines_txt.
    Document information.
    w_doc_chng-obj_name = 'Smartform'.
    w_doc_chng-expiry_dat = sy-datum + 10.
    w_doc_chng-obj_descr = 'Smart form output'.
    w_doc_chng-sensitivty = 'F'. "Functional object
    w_doc_chng-doc_size = v_lines_txt * 255.
    Pack to main body as RAW.
    Obj. to be transported not in binary form
    CLEAR i_objpack-transf_bin.
    Start line of object header in transport packet
    i_objpack-head_start = 1.
    Number of lines of an object header in object packet
    i_objpack-head_num = 0.
    Start line of object contents in an object packet
    i_objpack-body_start = 1.
    Number of lines of the object contents in an object packet
    i_objpack-body_num = v_lines_txt.
    Code for document class
    i_objpack-doc_type = 'RAW'.
    APPEND i_objpack.
    Packing as PDF.
    i_objpack-transf_bin = 'X'.
    i_objpack-head_start = 1.
    i_objpack-head_num = 1.
    i_objpack-body_start = 1.
    i_objpack-body_num = v_lines_bin.
    i_objpack-doc_type = 'PDF'.
    i_objpack-obj_name = 'Smartform'.
    CONCATENATE 'Smartform_output' '.pdf'
    INTO i_objpack-obj_descr.
    i_objpack-doc_size = v_lines_bin * 255.
    APPEND i_objpack.
    Document information.
    CLEAR i_reclist.
    e-mail receivers.
    i_reclist-receiver = '[email protected]'.
    i_reclist-express = 'X'.
    i_reclist-rec_type = 'U'. "Internet address
    APPEND i_reclist.
    Sending mail.
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
         EXPORTING
              document_data              = w_doc_chng
              put_in_outbox              = 'X'
         TABLES
              packing_list               = i_objpack
              object_header              = w_objhead
              contents_hex               = i_objbin
              contents_txt               = i_objtxt
              receivers                  = i_reclist
         EXCEPTIONS
              too_many_receivers         = 1
              document_not_sent          = 2
              document_type_not_exist    = 3
              operation_no_authorization = 4
              parameter_error            = 5
              x_error                    = 6
              enqueue_error              = 7
              OTHERS                     = 8.
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

  • Smart form to PDF and send it by mail

    Hi ,
    I have smartform whihc i have to conver into pdf and send by mail. nay inputs is higghly appreciated

    Hi,
    You call the smartform-function module from within your printprogram.
    That smartform-function module has some standard import en export
    parameters(tables).
    One of the parameters (OTF) you have to mark (X).
    Than after the processing of the smartform(-function module) you get your
    otf back in an internal table.
    You have to convert this table to pdf with FM convert_to_pdf (or something
    like that).
    The output of this FM can be downloaded to the presentation server (pc) (FM
    gui_download) or written to the application server (SAP server) (transfer
    statement).
    Then use this link to send mail
    http://www.sap-img.com/abap/sending-email-with-attachment.htm
    Reward if useful!

  • Convert sap script to pdf and send mail before close_form

    hi experts,
    I am converting a sap script to PDF and then sending that pdf to vendor mail ids.
    I am getting the Data for the conversion of pdf From close_form.But it contains the data for all the vendors . But i have to Send the mail to the specific vendors.For ex if my script output has 5 sheets each with different vendors . I have to send  1 sheet as a pdf mail for that particular vendor. so,1 sheet each for 5 differrent vendors . But the data i get from close_form is the data for all the 5 vendors. How to split the data ?. can any one help me on this issue.
    with thanks in advance,
    syed

    Hi,
        Change your driver program so that it calls the script n no of times .. and every time send mail to particular vendor ..
        Loop at vendors.
         call the form ...
         send mail ...
        endloop ...
    Regards,
    Srini.

  • Reg: Converting Standard Payslip (PC00_M99_CEDT) to PDF and send via email

    Dear Experts,
    Please provide me a solution to convert the standard Pay slip (PC00_M99_CEDT) Remuneration statement to PDF and send it via email to individual employee by fetching the email ids through the info types.
    I checked the forum, few answers our complete but they have not given the solution.
    Thanks in advance
    Abdur
    Moderator message: moved to requirements forum (points-free!)
    Edited by: Thomas Zloch on Feb 7, 2011 11:53 AM
    Moderator message: moved back to ABAP General.
    Edited by: Thomas Zloch on Feb 9, 2011 1:03 PM

    Dear Experts,
    As suggested, I have written the below code.
    REPORT  ztest_period.
    DATA : td_listobject LIKE abaplist OCCURS 0 WITH HEADER LINE.
    DATA: txtlines(1024) TYPE c OCCURS 0 WITH HEADER LINE.
    DATA: list_tab TYPE TABLE OF abaplist,
          lt_objbin TYPE TABLE OF solisti1 WITH HEADER LINE.
    SUBMIT rpcedtx0 VIA SELECTION-SCREEN EXPORTING LIST TO MEMORY AND RETURN.
    CLEAR td_listobject. REFRESH td_listobject.
    CALL FUNCTION 'LIST_FROM_MEMORY'
      TABLES
        listobject = td_listobject
      EXCEPTIONS
        not_found  = 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.
    CHECK sy-subrc = 0.
    CALL FUNCTION 'TABLE_COMPRESS'
    TABLES
    in = td_listobject
    out = lt_objbin
    EXCEPTIONS
    compress_error = 1
    OTHERS = 2.
    &code&
    I'm getting the raw data from FM 'LIST_FROM_MEMORY' Please tell me how should i convert it to normal data.
    Once i get the data, I need to send an email for individual personnel number for the respective month.
    Please advice me the next step.
    Thanks and Regards,
    Abdur Rafique
    Edited by: abdur rafique on Feb 21, 2011 11:39 AM

  • How to create job to run daily based on form values entered and send mail.

    Hi,
    In DB we have 3 columns: creation_date, name, approved_or_not. Default for approved_or_not is 'No'.
    In the application form page suppose I fill in sysdate for creation_date and leave default for approved_or_not and click [create] button.
    Now a job should run everyday and check for where (approved_or_not='No' & creation_date = 'sysdate - 1') and send mail to the person in 'name' field mentioning: 'Approval pending. click on link <some_link> for details on approval'.
    Could anyone give me pointers to example on such job? (Working on APEX 3.0)
    Thanks,
    Priyanka

    create a DBMS JOB
    check out this forum link.
    dbms_job

  • Convert pdf and send mail

    after sending mail ,the attachment doesnt conatin any pdf data.
    code is as follows.............
    LOOP AT IT_PDF.
    TRANSLATE IT_PDF USING ' ~'.
    CONCATENATE GD_BUFFER IT_PDF
    INTO GD_BUFFER.
    ENDLOOP.
    TRANSLATE GD_BUFFER USING '~ '.
    DO.
    I_OBJBIN = GD_BUFFER.
    APPEND I_OBJBIN.
    SHIFT GD_BUFFER LEFT BY 100 PLACES.
    IF GD_BUFFER IS INITIAL.
    EXIT.
    ENDIF.
    ENDDO.
    LOOP AT IT_PDF.
       TRANSLATE IT_PDF USING '~'.
    ENDLOOP.
      REFRESH:
          I_RECLIST,
          I_OBJTXT,
          I_OBJBIN,
          I_OBJPACK.
      CLEAR I_OBJPACK-TRANSF_BIN.
      I_OBJPACK-HEAD_START = 1.
      I_OBJPACK-HEAD_NUM = 0.
      I_OBJPACK-BODY_START = 1.
      I_OBJPACK-BODY_NUM = V_LINES_TXT.
      I_OBJPACK-DOC_TYPE = 'RAW'.
      APPEND I_OBJPACK.
    Attachment  (pdf-Attachment)
      I_OBJPACK-TRANSF_BIN = 'X'.
      I_OBJPACK-HEAD_START = 1.
      I_OBJPACK-HEAD_NUM = 0.
      I_OBJPACK-BODY_START = 1.
      DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.
      READ TABLE I_OBJBIN INDEX V_LINES_BIN.
      I_OBJPACK-DOC_SIZE =  V_LINES_BIN * 550 .
      I_OBJPACK-BODY_NUM = V_LINES_BIN.
      I_OBJPACK-DOC_TYPE = 'PDF'.
      I_OBJPACK-OBJ_NAME = 'purchase order'.
      I_OBJPACK-OBJ_DESCR = 'purchase order'.
      APPEND I_OBJPACK.
      clear WA_OBJHEAD.
      CLEAR I_RECLIST.
      I_RECLIST-RECEIVER = P_EMAIL.
      I_RECLIST-EXPRESS = 'X'.
      I_RECLIST-REC_TYPE = 'U'.
      I_CC-COPY = I_CC.
      APPEND I_RECLIST.
      I_OBJTXT = 'Hi'.
      APPEND I_OBJTXT.
      I_OBJTXT = ' '.
      APPEND I_OBJTXT.
      I_OBJTXT = 'Please find the purchase order as an attachment'.
      APPEND I_OBJTXT.
      I_OBJTXT = 'from meda'.
      APPEND I_OBJTXT.
      I_OBJTXT = ' '.
      APPEND I_OBJTXT.
      I_OBJTXT = 'Thanks'.
      APPEND I_OBJTXT.
      I_OBJTXT = 'purcahse order'.
      APPEND I_OBJTXT.
      DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.
      READ TABLE I_OBJTXT INDEX V_LINES_TXT.
      WA_DOC_CHNG-OBJ_NAME = 'purcahse order'.
      WA_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.
      WA_DOC_CHNG-OBJ_DESCR = 'Mail from meda'.
      WA_DOC_CHNG-SENSITIVTY = 'F'.
      WA_DOC_CHNG-DOC_SIZE = V_LINES_TXT * 2255.
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          DOCUMENT_DATA              = WA_DOC_CHNG
          PUT_IN_OUTBOX              = 'X'
          COMMIT_WORK                = 'X'
        TABLES
          PACKING_LIST               = I_OBJPACK
          OBJECT_HEADER              = WA_OBJHEAD
          CONTENTS_BIN               = I_OBJBIN
          CONTENTS_TXT               = I_OBJTXT
          RECEIVERS                  = I_RECLIST
        EXCEPTIONS
          TOO_MANY_RECEIVERS         = 1
          DOCUMENT_NOT_SENT          = 2
          DOCUMENT_TYPE_NOT_EXIST    = 3
          OPERATION_NO_AUTHORIZATION = 4
          PARAMETER_ERROR            = 5
          X_ERROR                    = 6
          ENQUEUE_ERROR              = 7
          OTHERS                     = 8.
      IF SY-SUBRC EQ 0.
        WRITE : / 'email sent over' .
      ENDIF.
    ENDFORM.                    " EMAIL_DISPLAY

    hi check this....
    *& Report  ZSPOOLTOPDF                                                 *
    *& Converts spool request into PDF document and emails it to           *
    *& recipicant.                                                         *
    *& Execution                                                           *
    *& This program must be run as a background job in-order for the write *
    *& commands to create a Spool request rather than be displayed on      *
    *& screen                                                              *
    REPORT  zspooltopdf.
    PARAMETER: p_email1 LIKE somlreci1-receiver,
                         p_sender LIKE somlreci1-receiver ,
                          p_delspl  AS CHECKBOX.
    *DATA DECLARATION
    DATA: gd_recsize TYPE i.
    Spool IDs
    TYPES: BEGIN OF t_tbtcp.
            INCLUDE STRUCTURE tbtcp.
    TYPES: END OF t_tbtcp.
    DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
          wa_tbtcp TYPE t_tbtcp.
    Job Runtime Parameters
    DATA: gd_eventid LIKE tbtcm-eventid,
          gd_eventparm LIKE tbtcm-eventparm,
          gd_external_program_active LIKE tbtcm-xpgactive,
          gd_jobcount LIKE tbtcm-jobcount,
          gd_jobname LIKE tbtcm-jobname,
          gd_stepcount LIKE tbtcm-stepcount,
          gd_error    TYPE sy-subrc,
          gd_reciever TYPE sy-subrc.
    DATA:  w_recsize TYPE i.
    DATA: gd_subject   LIKE sodocchgi1-obj_descr,
          it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          gd_sender_type     LIKE soextreci1-adr_typ,
          gd_attachment_desc TYPE so_obj_nam,
          gd_attachment_name TYPE so_obj_des.
    Spool to PDF conversions
    DATA: gd_spool_nr LIKE tsp01-rqident,
          gd_destination LIKE rlgrap-filename,
          gd_bytecount LIKE tst01-dsize,
          gd_buffer TYPE string.
    Binary store for PDF
    DATA: BEGIN OF it_pdf_output OCCURS 0.
            INCLUDE STRUCTURE tline.
    DATA: END OF it_pdf_output.
    CONSTANTS: c_dev LIKE  sy-sysid VALUE 'DEV',
               c_no(1)     TYPE c   VALUE ' ',
               c_device(4) TYPE c   VALUE 'LOCL'.
    *START-OF-SELECTION.
    START-OF-SELECTION.
    Write statement to represent report output. Spool request is created
    if write statement is executed in background. This could also be an
    ALV grid which would be converted to PDF without any extra effort
      WRITE 'Hello World'.
      new-page.
      commit work.
      new-page print off.
      IF sy-batch EQ 'X'.
        PERFORM get_job_details.
        PERFORM obtain_spool_id.
    Alternative way could be to submit another program and store spool
    id into memory, will be stored in sy-spono.
    *submit ZSPOOLTOPDF2
           to sap-spool
           spool parameters   %_print
           archive parameters %_print
           without spool dynpro
           and return.
    Get spool id from program called above
    IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
        PERFORM convert_spool_to_pdf.
        PERFORM process_email.
        if p_delspl EQ 'X'.
          PERFORM delete_spool.
        endif.
        IF sy-sysid = c_dev.
          wait up to 5 seconds.
          SUBMIT rsconn01 WITH mode   = 'INT'
                          WITH output = 'X'
                          AND RETURN.
        ENDIF.
      ELSE.
        SKIP.
        WRITE:/ 'Program must be executed in background in-order for spool',
                'request to be created.'.
      ENDIF.
          FORM obtain_spool_id                                          *
    FORM obtain_spool_id.
      CHECK NOT ( gd_jobname IS INITIAL ).
      CHECK NOT ( gd_jobcount IS INITIAL ).
      SELECT * FROM  tbtcp
                     INTO TABLE it_tbtcp
                     WHERE      jobname     = gd_jobname
                     AND        jobcount    = gd_jobcount
                     AND        stepcount   = gd_stepcount
                     AND        listident   <> '0000000000'
                     ORDER BY   jobname
                                jobcount
                                stepcount.
      READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
      IF sy-subrc = 0.
        message s004(zdd) with gd_spool_nr.
        gd_spool_nr = wa_tbtcp-listident.
        MESSAGE s004(zdd) WITH gd_spool_nr.
      ELSE.
        MESSAGE s005(zdd).
      ENDIF.
    ENDFORM.
          FORM get_job_details                                          *
    FORM get_job_details.
    Get current job details
      CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
           IMPORTING
                eventid                 = gd_eventid
                eventparm               = gd_eventparm
                external_program_active = gd_external_program_active
                jobcount                = gd_jobcount
                jobname                 = gd_jobname
                stepcount               = gd_stepcount
           EXCEPTIONS
                no_runtime_info         = 1
                OTHERS                  = 2.
    ENDFORM.
          FORM convert_spool_to_pdf                                     *
    FORM convert_spool_to_pdf.
      CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
           EXPORTING
                src_spoolid              = gd_spool_nr
                no_dialog                = c_no
                dst_device               = c_device
           IMPORTING
                pdf_bytecount            = gd_bytecount
           TABLES
                pdf                      = it_pdf_output
           EXCEPTIONS
                err_no_abap_spooljob     = 1
                err_no_spooljob          = 2
                err_no_permission        = 3
                err_conv_not_possible    = 4
                err_bad_destdevice       = 5
                user_cancelled           = 6
                err_spoolerror           = 7
                err_temseerror           = 8
                err_btcjob_open_failed   = 9
                err_btcjob_submit_failed = 10
                err_btcjob_close_failed  = 11
                OTHERS                   = 12.
      CHECK sy-subrc = 0.
    Transfer the 132-long strings to 255-long strings
      LOOP AT it_pdf_output.
        TRANSLATE it_pdf_output USING ' ~'.
        CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
      ENDLOOP.
      TRANSLATE gd_buffer USING '~ '.
      DO.
        it_mess_att = gd_buffer.
        APPEND it_mess_att.
        SHIFT gd_buffer LEFT BY 255 PLACES.
        IF gd_buffer IS INITIAL.
          EXIT.
        ENDIF.
      ENDDO.
    ENDFORM.
          FORM process_email                                            *
    FORM process_email.
      DESCRIBE TABLE it_mess_att LINES gd_recsize.
      CHECK gd_recsize > 0.
      PERFORM send_email USING p_email1.
    perform send_email using p_email2.
    ENDFORM.
          FORM send_email                                               *
    -->  p_email                                                       *
    FORM send_email USING p_email.
      CHECK NOT ( p_email IS INITIAL ).
      REFRESH it_mess_bod.
    Default subject matter
      gd_subject         = 'Subject'.
      gd_attachment_desc = 'Attachname'.
    CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
      it_mess_bod        = 'Message Body text, line 1'.
      APPEND it_mess_bod.
      it_mess_bod        = 'Message Body text, line 2...'.
      APPEND it_mess_bod.
    If no sender specified - default blank
      IF p_sender EQ space.
        gd_sender_type  = space.
      ELSE.
        gd_sender_type  = 'INT'.
      ENDIF.
    Send file by email as .xls speadsheet
      PERFORM send_file_as_email_attachment
                                   tables it_mess_bod
                                          it_mess_att
                                    using p_email
                                          'Example .xls documnet attachment'
                                          'PDF'
                                          gd_attachment_name
                                          gd_attachment_desc
                                          p_sender
                                          gd_sender_type
                                 changing gd_error
                                          gd_reciever.
    ENDFORM.
          FORM delete_spool                                             *
    FORM delete_spool.
      DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
      ld_spool_nr = gd_spool_nr.
      CHECK p_delspl <> c_no.
      CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
           EXPORTING
                spoolid = ld_spool_nr.
    ENDFORM.
    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
          Send email
    FORM send_file_as_email_attachment tables it_message
                                              it_attach
                                        using p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription
                                              p_sender_address
                                              p_sender_addres_type
                                     changing p_error
                                              p_reciever.
      DATA: ld_error    TYPE sy-subrc,
            ld_reciever TYPE sy-subrc,
            ld_mtitle LIKE sodocchgi1-obj_descr,
            ld_email LIKE  somlreci1-receiver,
            ld_format TYPE  so_obj_tp ,
            ld_attdescription TYPE  so_obj_nam ,
            ld_attfilename TYPE  so_obj_des ,
            ld_sender_address LIKE  soextreci1-receiver,
            ld_sender_address_type LIKE  soextreci1-adr_typ,
            ld_receiver LIKE  sy-subrc.
    data:   t_packing_list like sopcklsti1 occurs 0 with header line,
            t_contents like solisti1 occurs 0 with header line,
            t_receivers like somlreci1 occurs 0 with header line,
            t_attachment like solisti1 occurs 0 with header line,
            t_object_header like solisti1 occurs 0 with header line,
            w_cnt type i,
            w_sent_all(1) type c,
            w_doc_data like sodocchgi1.
      ld_email   = p_email.
      ld_mtitle = p_mtitle.
      ld_format              = p_format.
      ld_attdescription      = p_attdescription.
      ld_attfilename         = p_filename.
      ld_sender_address      = p_sender_address.
      ld_sender_address_type = p_sender_addres_type.
    Fill the document data.
      w_doc_data-doc_size = 1.
    Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = it_attach[].
    Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND t_receivers.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = w_doc_data
                put_in_outbox              = 'X'
                sender_address             = ld_sender_address
                sender_address_type        = ld_sender_address_type
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = w_sent_all
           TABLES
                packing_list               = t_packing_list
                contents_bin               = t_attachment
                contents_txt               = it_message
                receivers                  = t_receivers
           EXCEPTIONS
                too_many_receivers         = 1
                document_not_sent          = 2
                document_type_not_exist    = 3
                operation_no_authorization = 4
                parameter_error            = 5
                x_error                    = 6
                enqueue_error              = 7
                OTHERS                     = 8.
    Populate zerror return code
      ld_error = sy-subrc.
    Populate zreceiver return code
      LOOP AT t_receivers.
        ld_receiver = t_receivers-retrn_code.
      ENDLOOP.
    ENDFORM.
    regards,
    venkat.

  • Convert smartform spool to 2 pdf and send it by mail

    Hi! Can someone show me some code how to call the smartform and use the spool to convert to pdf and then send it by mail?
    Thanks in advance,
    Regards

    hai
    its very useful for u
    Object ID          :  PTP_TS_FRM_202                                 *
    Description        :  Print Program For PO Goods Receipt Document    *
    Developer          :  Ganesh Shanker Vidyarthi                       *
    Date               :  11/06/2006                                     *
    Genentech Contact  :                                                 *
    Functional Contact :                                                 *
    Purpose            :  This program is driver program of Goods Receipt*
                          Printing.                                      *
    Program Logic      : The Goods Receipt form (Raw material worksheet) *
                         would be created once we entered the values of
                         MBLNR MJAHR ZEILE fields on the selection screen.
                       Modification Log                                  *
    Changed On    Developer         Transport No.    Description         *
    11/06/2006    G.S.Vidyarthi                      Creation            *
    REPORT  zptpfrm202p_pogr_pr_instr MESSAGE-ID zmm.
              TABLES                                                     *
    Database table made for getting information about PRINTPREVIEW and
    PRINT command more than one times
    TABLES:    zgr_table.
    TYPE-POOLS:syscr.
              GLOBAL TYPE DECLARATION                                    *
    DATA:  zdoc_output_info     TYPE     ssfcrespd,  "SF:Return Document Inf.
         zjob_output_info     TYPE     ssfcrescl,  "SF:Return value at end of
                                                    form printing
           i_control TYPE ssfctrlop ,
           i_output_options TYPE ssfcompop,
           zjob_output_opts     TYPE     ssfcresop.  "SF:Return value at start
                                                    of form printing
    *This internal table is used for storing Document Segment: Material
    DATA: BEGIN OF i_mseg.
            INCLUDE STRUCTURE mseg.
    DATA: END OF i_mseg.
    This internal table is used for storing  Header: Material Document
    DATA: BEGIN OF i_mkpf.
            INCLUDE STRUCTURE mkpf.
    DATA: END OF i_mkpf.
    *Variables
    DATA flag(1) TYPE c.
    DATA: vfile TYPE string.
                    SELECTION-SCREEN                                     *
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-000.
    PARAMETERS:p_mblnr TYPE mkpf-mblnr OBLIGATORY MATCHCODE OBJECT zganesh,
               p_mjahr TYPE mkpf-mjahr OBLIGATORY MATCHCODE OBJECT zganesh1,
               p_zeile TYPE mseg-zeile OBLIGATORY MATCHCODE OBJECT zganesh2.
    SELECTION-SCREEN END OF BLOCK b1.
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-001.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN POSITION 10.
    PARAMETER:r_disp RADIOBUTTON GROUP g1 USER-COMMAND u1 DEFAULT 'X'.
    SELECTION-SCREEN:COMMENT 15(10) text-002 .
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN POSITION 10.
    PARAMETERS: r_down RADIOBUTTON GROUP g1.
    SELECTION-SCREEN:COMMENT 15(10) text-003.
    *PARAMETERS: v_file LIKE rlgrap-filename .
    *SELECTION-SCREEN:COMMENT 70(50) text-005.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN POSITION 10.
    PARAMETERS: r_print RADIOBUTTON GROUP g1 .
    SELECTION-SCREEN:COMMENT 15(10) text-004.
    SELECTION-SCREEN END OF LINE.
    PARAMETERS: v_file LIKE rlgrap-filename MODIF ID g12.
    SELECTION-SCREEN END OF BLOCK b2.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR v_file.
      DATA : wlv_field_name LIKE dynpread-fieldname,
              wlv_file_name  LIKE ibipparms-path.
      wlv_field_name = v_file.
      CALL FUNCTION 'F4_FILENAME'
        EXPORTING
          field_name = wlv_field_name
        IMPORTING
          file_name  = wlv_file_name.
      IF sy-subrc EQ 0.
        vfile = wlv_file_name.
        v_file = wlv_file_name.
      ENDIF.
    AT SELECTION-SCREEN OUTPUT.
      LOOP AT SCREEN.
        IF screen-name = 'V_FILE'.
          IF r_disp EQ 'X' OR r_print EQ 'X'.
            screen-input = 0.
          ELSE.
            screen-input = '1'.
          ENDIF.
          MODIFY SCREEN.
        ENDIF.
      ENDLOOP.
                        START-OF-SELECTION EVENT                         *
    START-OF-SELECTION.
      CALLING CONVERSION FUNCTION MODULE 'CONVERSION_EXIT_ALPHA_INPUT'   *
    *Conversion function module for appending 00 befor MBLNR FIELD
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = p_mblnr
        IMPORTING
          output = p_mblnr.
    Call subroutine for fetching data from database
      PERFORM get_data.
                        END-OF-SELECTION  EVENT                          *
    END-OF-SELECTION.
    Call subroutine for calling  and processing smartform
      PERFORM call_smartform.
    *&      Form  get_data
          Subroutine for fetching data from database
    FORM get_data .
    Fetching data from MKPF table with using parameters MBLNR and MJAHR
      SELECT SINGLE * FROM mkpf
                      INTO i_mkpf
                      WHERE mblnr = p_mblnr
                        AND mjahr = p_mjahr.
      IF sy-subrc EQ 0.
    Fetching data from MSEG with using parameters MBLNR,ZEILE and MJAHR
        SELECT SINGLE * FROM mseg
                        INTO i_mseg
                        WHERE mblnr = i_mkpf-mblnr
                          AND mjahr = i_mkpf-mjahr
                          AND zeile = p_zeile.
        IF sy-subrc NE 0.
          CLEAR i_mseg.
        ENDIF.
      ELSE.
        MESSAGE i000.
        EXIT.
      ENDIF.
    ENDFORM.                    " get_data
    *&      Form  call_smartform
         Subroutine for calling smartform
    FORM call_smartform .
    Local template used in the processing output of smartform
      TYPES: BEGIN OF lt_ztable,
              mandt TYPE sy-mandt,
              mblnr TYPE mseg-mblnr,
              flag(1) TYPE c,
              END OF lt_ztable.
      CONSTANTS: c_x(1) TYPE c VALUE 'X'.
    Workarea
      DATA: lw_ztable TYPE lt_ztable.
    *Variable used in the smartform
      DATA: lv_form(30)    TYPE c,
            lv_fm_name(30) TYPE c.
      lv_form = 'ZPTPFRM202L_POGR'.
    *Calling function module SSF_FUNCTION_MODULE_NAME which gives  new name
    *to the function module that will generated by smartform.
      CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
        EXPORTING
          formname           = lv_form
        IMPORTING
          fm_name            = lv_fm_name
        EXCEPTIONS
          no_form            = 1
          no_function_module = 2
          OTHERS             = 3.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    *Calling function module that will be generated by smartform
      IF r_disp = c_x.
        i_output_options-tdimmed       = space.
        i_output_options-tdnewid       = c_x.
        i_output_options-tddest        = 'LOCL'.
        i_control-no_dialog = 'X'.
        i_control-preview = 'X'.
      ELSEIF r_print = c_x.
        i_output_options-tdimmed       = c_x.
        i_output_options-tddest        = 'LOCL'.
        i_control-no_dialog = c_x.
      ELSE.
        i_output_options-tdimmed       = space.
        i_output_options-tdnewid       = c_x.
        i_output_options-tddest        = 'LOCL'.
        i_control-getotf    = 'X'.
        i_control-preview   = space.
        i_control-no_dialog = c_x.
        flag = c_x.
      ENDIF.
      CALL FUNCTION lv_fm_name
        EXPORTING
          control_parameters   = i_control
          output_options       = i_output_options
          user_settings        = space
          zmkpf                = i_mkpf
          zmseg                = i_mseg
        IMPORTING
          document_output_info = zdoc_output_info
          job_output_info      = zjob_output_info
          job_output_options   = zjob_output_opts
        EXCEPTIONS
          formatting_error     = 1
          internal_error       = 2
          send_error           = 3
          user_canceled        = 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.
    Modify the database table if it found the print command
      IF  zjob_output_opts-tdpreview NE c_x.
        lw_ztable-mandt = sy-mandt.
        lw_ztable-mblnr = p_mblnr.
        lw_ztable-flag = c_x.
        MODIFY zgr_table FROM lw_ztable.
        CLEAR lw_ztable.
      ENDIF.
      IF flag EQ c_x.
        DATA:   li_lines LIKE tline OCCURS 100 WITH HEADER LINE.
        DATA:   lv_file   TYPE string,
                lbin_fsiz TYPE i.
        lv_file = v_file.
        CALL FUNCTION 'CONVERT_OTF'
          EXPORTING
            format                = 'PDF'
          IMPORTING
            bin_filesize          = lbin_fsiz
          TABLES
            otf                   = zjob_output_info-otfdata
            lines                 = li_lines
          EXCEPTIONS
            err_max_linewidth     = 1
            err_format            = 2
            err_conv_not_possible = 3
            err_bad_otf           = 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 'GUI_DOWNLOAD'
          EXPORTING
            bin_filesize            = lbin_fsiz
            filename                = lv_file
            filetype                = 'BIN'
          TABLES
            data_tab                = li_lines
          EXCEPTIONS
            file_write_error        = 1
            no_batch                = 2
            gui_refuse_filetransfer = 3
            invalid_type            = 4
            no_authority            = 5
            unknown_error           = 6
            header_not_allowed      = 7
            separator_not_allowed   = 8
            filesize_not_allowed    = 9
            header_too_long         = 10
            dp_error_create         = 11
            dp_error_send           = 12
            dp_error_write          = 13
            unknown_dp_error        = 14
            access_denied           = 15
            dp_out_of_memory        = 16
            disk_full               = 17
            dp_timeout              = 18
            file_not_found          = 19
            dataprovider_exception  = 20
            control_flush_error     = 21
            OTHERS                  = 22.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
      ENDIF.
    ENDFORM.                    " call_smartform
    **Please reward suitable points***
    With Regards
    Navin Khedikar

  • Smartforms to pdf and send mail

    PROGRAM :
    *& Report  ZDB_PDFMAIL
    REPORT  zdb_pdfmail.
    Internal Table declarations
    DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
    i_tline TYPE TABLE OF tline WITH HEADER LINE,
    i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
    i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    Objects to send mail.
    i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
    i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    *i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
    *i_record LIKE SOLIX OCCURS 0 WITH HEADER LINE,
    i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    Work Area declarations
    w_objhead TYPE soli_tab,
    w_ctrlop TYPE ssfctrlop,
    w_compop TYPE ssfcompop,
    w_return TYPE ssfcrescl,
    w_doc_chng TYPE sodocchgi1,
    w_data TYPE sodocchgi1,
    w_buffer TYPE string,"To convert from 132 to 255
    Variables declarations
    v_form_name TYPE rs38l_fnam,
    v_len_in LIKE sood-objlen,
    v_len_out LIKE sood-objlen,
    v_len_outn TYPE i,
    v_lines_txt TYPE i,
    v_lines_bin TYPE i.
    DATA  doc LIKE docs OCCURS 0 WITH HEADER LINE.
    DATA bin_fsize TYPE i.
    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
      EXPORTING
        formname           = 'ZZZ_TEST2'
      IMPORTING
        fm_name            = v_form_name
      EXCEPTIONS
        no_form            = 1
        no_function_module = 2
        OTHERS             = 3.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    w_ctrlop-getotf = 'X'.
    w_ctrlop-no_dialog = 'X'.
    w_compop-tdnoprev = 'X'.
    CALL FUNCTION v_form_name
      EXPORTING
        control_parameters = w_ctrlop
        output_options     = w_compop
        user_settings      = 'X'
      IMPORTING
        job_output_info    = w_return
      EXCEPTIONS
        formatting_error   = 1
        internal_error     = 2
        send_error         = 3
        user_canceled      = 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.
    i_otf[] = w_return-otfdata[].
    *CALL FUNCTION 'CONVERT_OTF_2_PDF'
    EXPORTING
      USE_OTF_MC_CMD               = 'X'
      ARCHIVE_INDEX                =
    IMPORTING
      BIN_FILESIZE                 =
    TABLES
       otf                          =
       doctab_archive               =
       lines                        =
    EXCEPTIONS
      ERR_CONV_NOT_POSSIBLE        = 1
      ERR_OTF_MC_NOENDMARKER       = 2
      OTHERS                       = 3
    *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 'CONVERT_OTF'
      EXPORTING
        format                = 'PDF'
        max_linewidth         = 132
      IMPORTING
        bin_filesize          = v_len_in
      TABLES
        otf                   = i_otf
        lines                 = i_tline
      EXCEPTIONS
        err_max_linewidth     = 1
        err_format            = 2
        err_conv_not_possible = 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.
    Convert PDF from 132 to 255.
    LOOP AT i_tline.
    Replacing space by ~
      TRANSLATE i_tline USING ' ~'.
      CONCATENATE w_buffer i_tline INTO w_buffer.
    ENDLOOP.
    Replacing ~ by space
    TRANSLATE w_buffer USING '~ '.
    DO.
      i_record = w_buffer.
    Appending 255 characters as a record
      APPEND i_record.
      SHIFT w_buffer LEFT BY 255 PLACES.
      IF w_buffer IS INITIAL.
        EXIT.
      ENDIF.
    ENDDO.
    *CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
       format                = 'PDF'
       max_linewidth         = 132
    IMPORTING
       bin_filesize          = v_len_in
    TABLES
       otf                   = i_otf
       lines                 = i_tline
    EXCEPTIONS
       err_max_linewidth     = 1
       err_format            = 2
       err_conv_not_possible = 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.
    Convert PDF from 132 to 255.
    *LOOP AT i_tline.
    Replacing space by ~
    TRANSLATE i_tline USING ' ~'.
    CONCATENATE w_buffer i_tline INTO w_buffer.
    *ENDLOOP.
    Replacing ~ by space
    *TRANSLATE w_buffer USING '~ '.
    *DO.
    i_record = w_buffer.
    Appending 255 characters as a record
    APPEND i_record.
    SHIFT w_buffer LEFT BY 255 PLACES.
    IF w_buffer IS INITIAL.
       EXIT.
    ENDIF.
    *ENDDO.
    REFRESH: i_reclist,
    i_objtxt,
    i_objbin,
    i_objpack.
    CLEAR w_objhead.
    Object with PDF.
    i_objbin[] = i_record[].
    DESCRIBE TABLE i_objbin LINES v_lines_bin.
    Object with main text of the mail.
    i_objtxt = 'Find attached the output of the smart form.'.
    APPEND i_objtxt.
    i_objtxt = 'Regards,'.
    APPEND i_objtxt.
    i_objtxt = 'J.Jayanthi'.
    APPEND i_objtxt.
    DESCRIBE TABLE i_objtxt LINES v_lines_txt.
    Document information.
    w_doc_chng-obj_name = 'Smartform'.
    w_doc_chng-expiry_dat = sy-datum + 10.
    w_doc_chng-obj_descr = 'Smart form output'.
    w_doc_chng-sensitivty = 'F'. "Functional object
    w_doc_chng-doc_size = v_lines_txt * 255.
    Pack to main body as RAW.
    Obj. to be transported not in binary form
    CLEAR i_objpack-transf_bin.
    Start line of object header in transport packet
    i_objpack-head_start = 1.
    Number of lines of an object header in object packet
    i_objpack-head_num = 0.
    Start line of object contents in an object packet
    i_objpack-body_start = 1.
    Number of lines of the object contents in an object packet
    i_objpack-body_num = v_lines_txt.
    Code for document class
    i_objpack-doc_type = 'RAW'.
    APPEND i_objpack.
    Packing as PDF.
    i_objpack-transf_bin = 'X'.
    i_objpack-head_start = 1.
    i_objpack-head_num = 1.
    i_objpack-body_start = 1.
    i_objpack-body_num = v_lines_bin.
    i_objpack-doc_type = 'PDF'.
    i_objpack-obj_name = 'Smartform'.
    CONCATENATE 'Smartform_output' '.pdf'
    INTO i_objpack-obj_descr.
    i_objpack-doc_size = v_lines_bin * 255.
    APPEND i_objpack.
    Document information.
    CLEAR i_reclist.
    e-mail receivers.
    i_reclist-receiver = '[email protected]'.
    i_reclist-express = 'X'.
    i_reclist-rec_type = 'U'. "Internet address
    APPEND i_reclist.
    Sending mail.
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
      EXPORTING
        document_data              = w_doc_chng
        put_in_outbox              = 'X'
      TABLES
        packing_list               = i_objpack
        object_header              = w_objhead
        contents_hex               = i_objbin
        contents_txt               = i_objtxt
        receivers                  = i_reclist
      EXCEPTIONS
        too_many_receivers         = 1
        document_not_sent          = 2
        document_type_not_exist    = 3
        operation_no_authorization = 4
        parameter_error            = 5
        x_error                    = 6
        enqueue_error              = 7
        OTHERS                     = 8.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    ERROR:
    An exception occurred that is explained in detail below.
    The exception, which is assigned to class 'CX_SY_DYN_CALL_ILLEGAL_TYPE', was
      not caught and
    therefore caused a runtime error.
    The reason for the exception is:
    In the function "SO_NEW_DOCUMENT_ATT_SEND_API1", the STRUCTURE parameter
      "CONTENTS_HEX" is typed in such a way
    that only actual parameters are allowed, which are compatible in Unicode
      with respect to the fragment view. However, the specified actual
    parameter "I_OBJBIN" has an incompatible fragment view.
    PLS. TELL ME HOW TO UPDATE . 3KS
    WAITING FOR YOUR HELP

    I HAVE CHECK WHAT YOU SAID.
    CONCATENATE f_repid0(9) f_uname0(3) INTO lc_rq2name.
    SELECT * FROM tsp01 WHERE rq2name = lc_rq2name
      ORDER BY rqcretime DESCENDING.
    IN THE TABLE OF TSP01,HAVE NO MY RECORD.
    MAYBE MY PRINT REQUEST DOES NOT PUT INTO THE TABLE .
    WHY ? HOW TO SETTING ?
    OTHER ABAPER USER THE SAME PROGRAM ,HE CAN RUN SUCCESS.
    BUT SOMEONE NOT .
    Regards

  • How to convert an excel sheet as pdf  and sent mail?

    Hi,
    I have to open an excel file from report and display a value in a cell, based on that value in excel, macros will automatically trigger and the remaining data will fill in excel sheet.
    This sheet i need to convert as pdf and sent as attachment to mail.
    Regards,
    Shree

    Hi,
    I know how to do with word documents using OLE.  But i dont know how to work with Excel sheets.
    I have worked on word documents like displaying data in word document from SAP and saving it into local system.
    But here my requirement is i need to pass pernr to a cell in an Excel sheet, based on pernr in excel some macros will trigger and fill the details. After that, the filled sheet i need to convert as pdf and sent as mail.
    Regards,
    Shree.

  • Convert spool in the text format and send mail

    Hi All
    Can anyone tell me
    how to convert the spool into the text format and send that in email as an attachment..
    Points will be rewarded
    URGENT

    Hi,
    Read spool using FM  RSPO_RETURN_ABAP_SPOOLJOB
    CALL FUNCTION 'RSPO_RETURN_ABAP_SPOOLJOB'
        EXPORTING
          rqident                  = v_rqident   "Spool Number
      FIRST_LINE                 = 1
      LAST_LINE                  =
        TABLES
          buffer                     = i_spool "Internal table output
    You will get spool in internal table and then its your game, play the way you want.
    Regards,
    Mandeep

  • Convert ALV list to PDF and send mails to respective persons

    Hi All,
    I have a requirement ..we have written a program which will give o/p in alv list.Now I got a requirement to download that program to ALV format.Kindly help me how to approch for that we have some standard FM's for that like CONVERT_ABAPSPOOLJOB_2_PDF..what are the necessary inputs I have to give for that FM,
    Second requirement is I have to send an E mail of that list to respective persons.help me on this also
    Regards
      KK

    Hi,
    Try with this program which will send the spool to email.
    PARAMETER: p_email1 LIKE somlreci1-receiver
                        DEFAULT '[email protected]',
               p_sender LIKE somlreci1-receiver
                        DEFAULT '[email protected]',
               p_delspl AS CHECKBOX.
    *DATA DECLARATION
    DATA: gd_recsize TYPE i.
    * Spool IDs
    TYPES: BEGIN OF t_tbtcp.
            INCLUDE STRUCTURE tbtcp.
    TYPES: END OF t_tbtcp.
    DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
          wa_tbtcp TYPE t_tbtcp.
    * Job Runtime Parameters
    DATA: gd_eventid LIKE tbtcm-eventid,
          gd_eventparm LIKE tbtcm-eventparm,
          gd_external_program_active LIKE tbtcm-xpgactive,
          gd_jobcount LIKE tbtcm-jobcount,
          gd_jobname LIKE tbtcm-jobname,
          gd_stepcount LIKE tbtcm-stepcount,
          gd_error    TYPE sy-subrc,
          gd_reciever TYPE sy-subrc.
    DATA:  w_recsize TYPE i.
    DATA: gd_subject   LIKE sodocchgi1-obj_descr,
          it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          gd_sender_type     LIKE soextreci1-adr_typ,
          gd_attachment_desc TYPE so_obj_nam,
          gd_attachment_name TYPE so_obj_des.
    * Spool to PDF conversions
    DATA: gd_spool_nr LIKE tsp01-rqident,
          gd_destination LIKE rlgrap-filename,
          gd_bytecount LIKE tst01-dsize,
          gd_buffer TYPE string.
    * Binary store for PDF
    DATA: BEGIN OF it_pdf_output OCCURS 0.
            INCLUDE STRUCTURE tline.
    DATA: END OF it_pdf_output.
    CONSTANTS: c_dev LIKE  sy-sysid VALUE 'DEV',
               c_no(1)     TYPE c   VALUE ' ',
               c_device(4) TYPE c   VALUE 'LOCL'.
    *START-OF-SELECTION.
    START-OF-SELECTION.
    * Write statement to represent report output. Spool request is created
    * if write statement is executed in background. This could also be an
    * ALV grid which would be converted to PDF without any extra effort
      WRITE 'Hello World'.
      new-page.
      commit work.
      new-page print off.
      IF sy-batch EQ 'X'.
        PERFORM get_job_details.
        PERFORM obtain_spool_id.
    *** Alternative way could be to submit another program and store spool
    *** id into memory.
    *submit ZSPOOLTOPDF2
    *        to sap-spool
    *        spool parameters   %_print
    *        archive parameters %_print
    *        without spool dynpro
    *        and return.
    * Get spool id from program called above
    *  IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
        PERFORM convert_spool_to_pdf.
        PERFORM process_email.
        if p_delspl EQ 'X'.
          PERFORM delete_spool.
        endif.
        IF sy-sysid = c_dev.
          wait up to 5 seconds.
          SUBMIT rsconn01 WITH mode   = 'INT'
                          WITH output = 'X'
                          AND RETURN.
        ENDIF.
      ELSE.
        SKIP.
        WRITE:/ 'Program must be executed in background in-order for spool',
                'request to be created.'.
      ENDIF.
    *       FORM obtain_spool_id                                          *
    FORM obtain_spool_id.
      CHECK NOT ( gd_jobname IS INITIAL ).
      CHECK NOT ( gd_jobcount IS INITIAL ).
      SELECT * FROM  tbtcp
                     INTO TABLE it_tbtcp
                     WHERE      jobname     = gd_jobname
                     AND        jobcount    = gd_jobcount
                     AND        stepcount   = gd_stepcount
                     AND        listident   <> '0000000000'
                     ORDER BY   jobname
                                jobcount
                                stepcount.
      READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
      IF sy-subrc = 0.
        message s004(zdd) with gd_spool_nr.
        gd_spool_nr = wa_tbtcp-listident.
        MESSAGE s004(zdd) WITH gd_spool_nr.
      ELSE.
        MESSAGE s005(zdd).
      ENDIF.
    ENDFORM.
    *       FORM get_job_details                                          *
    FORM get_job_details.
    * Get current job details
      CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
           IMPORTING
                eventid                 = gd_eventid
                eventparm               = gd_eventparm
                external_program_active = gd_external_program_active
                jobcount                = gd_jobcount
                jobname                 = gd_jobname
                stepcount               = gd_stepcount
           EXCEPTIONS
                no_runtime_info         = 1
                OTHERS                  = 2.
    ENDFORM.
    *       FORM convert_spool_to_pdf                                     *
    FORM convert_spool_to_pdf.
      CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
           EXPORTING
                src_spoolid              = gd_spool_nr
                no_dialog                = c_no
                dst_device               = c_device
           IMPORTING
                pdf_bytecount            = gd_bytecount
           TABLES
                pdf                      = it_pdf_output
           EXCEPTIONS
                err_no_abap_spooljob     = 1
                err_no_spooljob          = 2
                err_no_permission        = 3
                err_conv_not_possible    = 4
                err_bad_destdevice       = 5
                user_cancelled           = 6
                err_spoolerror           = 7
                err_temseerror           = 8
                err_btcjob_open_failed   = 9
                err_btcjob_submit_failed = 10
                err_btcjob_close_failed  = 11
                OTHERS                   = 12.
      CHECK sy-subrc = 0.
    * Transfer the 132-long strings to 255-long strings
      LOOP AT it_pdf_output.
        TRANSLATE it_pdf_output USING ' ~'.
        CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
      ENDLOOP.
      TRANSLATE gd_buffer USING '~ '.
      DO.
        it_mess_att = gd_buffer.
        APPEND it_mess_att.
        SHIFT gd_buffer LEFT BY 255 PLACES.
        IF gd_buffer IS INITIAL.
          EXIT.
        ENDIF.
      ENDDO.
    ENDFORM.
    *       FORM process_email                                            *
    FORM process_email.
      DESCRIBE TABLE it_mess_att LINES gd_recsize.
      CHECK gd_recsize > 0.
      PERFORM send_email USING p_email1.
    *  perform send_email using p_email2.
    ENDFORM.
    *       FORM send_email                                               *
    *  -->  p_email                                                       *
    FORM send_email USING p_email.
      CHECK NOT ( p_email IS INITIAL ).
      REFRESH it_mess_bod.
    * Default subject matter
      gd_subject         = 'Subject'.
      gd_attachment_desc = 'Attachname'.
    *  CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
      it_mess_bod        = 'Message Body text, line 1'.
      APPEND it_mess_bod.
      it_mess_bod        = 'Message Body text, line 2...'.
      APPEND it_mess_bod.
    * If no sender specified - default blank
      IF p_sender EQ space.
        gd_sender_type  = space.
      ELSE.
        gd_sender_type  = 'INT'.
      ENDIF.
    * Send file by email as .xls speadsheet
      PERFORM send_file_as_email_attachment
                                   tables it_mess_bod
                                          it_mess_att
                                    using p_email
                                          'Example .xls documnet attachment'
                                          'PDF'
                                          gd_attachment_name
                                          gd_attachment_desc
                                          p_sender
                                          gd_sender_type
                                 changing gd_error
                                          gd_reciever.
    ENDFORM.
    *       FORM delete_spool                                             *
    FORM delete_spool.
      DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
      ld_spool_nr = gd_spool_nr.
      CHECK p_delspl <> c_no.
      CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
           EXPORTING
                spoolid = ld_spool_nr.
    ENDFORM.
    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
    *       Send email
    FORM send_file_as_email_attachment tables it_message
                                              it_attach
                                        using p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription
                                              p_sender_address
                                              p_sender_addres_type
                                     changing p_error
                                              p_reciever.
      DATA: ld_error    TYPE sy-subrc,
            ld_reciever TYPE sy-subrc,
            ld_mtitle LIKE sodocchgi1-obj_descr,
            ld_email LIKE  somlreci1-receiver,
            ld_format TYPE  so_obj_tp ,
            ld_attdescription TYPE  so_obj_nam ,
            ld_attfilename TYPE  so_obj_des ,
            ld_sender_address LIKE  soextreci1-receiver,
            ld_sender_address_type LIKE  soextreci1-adr_typ,
            ld_receiver LIKE  sy-subrc.
    data:   t_packing_list like sopcklsti1 occurs 0 with header line,
            t_contents like solisti1 occurs 0 with header line,
            t_receivers like somlreci1 occurs 0 with header line,
            t_attachment like solisti1 occurs 0 with header line,
            t_object_header like solisti1 occurs 0 with header line,
            w_cnt type i,
            w_sent_all(1) type c,
            w_doc_data like sodocchgi1.
      ld_email   = p_email.
      ld_mtitle = p_mtitle.
      ld_format              = p_format.
      ld_attdescription      = p_attdescription.
      ld_attfilename         = p_filename.
      ld_sender_address      = p_sender_address.
      ld_sender_address_type = p_sender_addres_type.
    * Fill the document data.
      w_doc_data-doc_size = 1.
    * Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    * Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = it_attach[].
    * Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    * Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    * Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND t_receivers.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = w_doc_data
                put_in_outbox              = 'X'
                sender_address             = ld_sender_address
                sender_address_type        = ld_sender_address_type
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = w_sent_all
           TABLES
                packing_list               = t_packing_list
                contents_bin               = t_attachment
                contents_txt               = it_message
                receivers                  = t_receivers
           EXCEPTIONS
                too_many_receivers         = 1
                document_not_sent          = 2
                document_type_not_exist    = 3
                operation_no_authorization = 4
                parameter_error            = 5
                x_error                    = 6
                enqueue_error              = 7
                OTHERS                     = 8.
    * Populate zerror return code
      ld_error = sy-subrc.
    * Populate zreceiver return code
      LOOP AT t_receivers.
        ld_receiver = t_receivers-retrn_code.
      ENDLOOP.
    ENDFORM.
    Regards,
    Raghav

  • Smart Form convert to Pdf and send to email

    hi,
    ive dev the smart for me21n. its  working fine. Standard programme is SAPLMEGUI.
    now new requirement is , convert the smart form to pdf and then sending the pdf through email to customer.
    Can any plz tell me is there any stadard programme or else need to custmise the print programme?
    Regards

    Kirans belong to convert the smart form to pdf.
    there is standard programme RSTXPDFT4
    but after convert the form to pdf. i need to send it thorough mail.
    iam checking other link one which is send by mr.naresh..
    thank you
    Regards

  • Convert smartforms to pdf and sending it as email

    hi,
    i am converting smart form into PDF and sending it as an attachment with the e-mail. the e-mail is getting delivered but i am unable to open the PDF. it shows error saying "unable to open as it is not a supported file type or  it has been damaged".
    can any one please help me.

    Hi Gouthaman,
    Check this code.
    *& Report  ZSPOOLTOPDF                                                 *
    *& Converts spool request into PDF document and emails it to           *
    *& recipicant.                                                         *
    *& Execution                                                           *
    *& This program must be run as a background job in-order for the write *
    *& commands to create a Spool request rather than be displayed on      *
    *& screen                                                              *
    REPORT  zspooltopdf.
    PARAMETER: p_email1 LIKE somlreci1-receiver
                                        DEFAULT '[email protected]',
               p_sender LIKE somlreci1-receiver
                                        DEFAULT '[email protected]',
               p_delspl  AS CHECKBOX.
    *DATA DECLARATION
    DATA: gd_recsize TYPE i.
    Spool IDs
    TYPES: BEGIN OF t_tbtcp.
            INCLUDE STRUCTURE tbtcp.
    TYPES: END OF t_tbtcp.
    DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
          wa_tbtcp TYPE t_tbtcp.
    Job Runtime Parameters
    DATA: gd_eventid LIKE tbtcm-eventid,
          gd_eventparm LIKE tbtcm-eventparm,
          gd_external_program_active LIKE tbtcm-xpgactive,
          gd_jobcount LIKE tbtcm-jobcount,
          gd_jobname LIKE tbtcm-jobname,
          gd_stepcount LIKE tbtcm-stepcount,
          gd_error    TYPE sy-subrc,
          gd_reciever TYPE sy-subrc.
    DATA:  w_recsize TYPE i.
    DATA: gd_subject   LIKE sodocchgi1-obj_descr,
          it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          gd_sender_type     LIKE soextreci1-adr_typ,
          gd_attachment_desc TYPE so_obj_nam,
          gd_attachment_name TYPE so_obj_des.
    Spool to PDF conversions
    DATA: gd_spool_nr LIKE tsp01-rqident,
          gd_destination LIKE rlgrap-filename,
          gd_bytecount LIKE tst01-dsize,
          gd_buffer TYPE string.
    Binary store for PDF
    DATA: BEGIN OF it_pdf_output OCCURS 0.
            INCLUDE STRUCTURE tline.
    DATA: END OF it_pdf_output.
    CONSTANTS: c_dev LIKE  sy-sysid VALUE 'DEV',
               c_no(1)     TYPE c   VALUE ' ',
               c_device(4) TYPE c   VALUE 'LOCL'.
    *START-OF-SELECTION.
    START-OF-SELECTION.
    Write statement to represent report output. Spool request is created
    if write statement is executed in background. This could also be an
    ALV grid which would be converted to PDF without any extra effort
      WRITE 'Hello World'.
      new-page.
      commit work.
      new-page print off.
      IF sy-batch EQ 'X'.
        PERFORM get_job_details.
        PERFORM obtain_spool_id.
    Alternative way could be to submit another program and store spool
    id into memory, will be stored in sy-spono.
    *submit ZSPOOLTOPDF2
           to sap-spool
           spool parameters   %_print
           archive parameters %_print
           without spool dynpro
           and return.
    Get spool id from program called above
    IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
        PERFORM convert_spool_to_pdf.
        PERFORM process_email.
        if p_delspl EQ 'X'.
          PERFORM delete_spool.
        endif.
        IF sy-sysid = c_dev.
          wait up to 5 seconds.
          SUBMIT rsconn01 WITH mode   = 'INT'
                          WITH output = 'X'
                          AND RETURN.
        ENDIF.
      ELSE.
        SKIP.
        WRITE:/ 'Program must be executed in background in-order for spool',
                'request to be created.'.
      ENDIF.
          FORM obtain_spool_id                                          *
    FORM obtain_spool_id.
      CHECK NOT ( gd_jobname IS INITIAL ).
      CHECK NOT ( gd_jobcount IS INITIAL ).
      SELECT * FROM  tbtcp
                     INTO TABLE it_tbtcp
                     WHERE      jobname     = gd_jobname
                     AND        jobcount    = gd_jobcount
                     AND        stepcount   = gd_stepcount
                     AND        listident   <> '0000000000'
                     ORDER BY   jobname
                                jobcount
                                stepcount.
      READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
      IF sy-subrc = 0.
        message s004(zdd) with gd_spool_nr.
        gd_spool_nr = wa_tbtcp-listident.
        MESSAGE s004(zdd) WITH gd_spool_nr.
      ELSE.
        MESSAGE s005(zdd).
      ENDIF.
    ENDFORM.
          FORM get_job_details                                          *
    FORM get_job_details.
    Get current job details
      CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
           IMPORTING
                eventid                 = gd_eventid
                eventparm               = gd_eventparm
                external_program_active = gd_external_program_active
                jobcount                = gd_jobcount
                jobname                 = gd_jobname
                stepcount               = gd_stepcount
           EXCEPTIONS
                no_runtime_info         = 1
                OTHERS                  = 2.
    ENDFORM.
          FORM convert_spool_to_pdf                                     *
    FORM convert_spool_to_pdf.
      CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
           EXPORTING
                src_spoolid              = gd_spool_nr
                no_dialog                = c_no
                dst_device               = c_device
           IMPORTING
                pdf_bytecount            = gd_bytecount
           TABLES
                pdf                      = it_pdf_output
           EXCEPTIONS
                err_no_abap_spooljob     = 1
                err_no_spooljob          = 2
                err_no_permission        = 3
                err_conv_not_possible    = 4
                err_bad_destdevice       = 5
                user_cancelled           = 6
                err_spoolerror           = 7
                err_temseerror           = 8
                err_btcjob_open_failed   = 9
                err_btcjob_submit_failed = 10
                err_btcjob_close_failed  = 11
                OTHERS                   = 12.
      CHECK sy-subrc = 0.
    Transfer the 132-long strings to 255-long strings
      LOOP AT it_pdf_output.
        TRANSLATE it_pdf_output USING ' ~'.
        CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
      ENDLOOP.
      TRANSLATE gd_buffer USING '~ '.
      DO.
        it_mess_att = gd_buffer.
        APPEND it_mess_att.
        SHIFT gd_buffer LEFT BY 255 PLACES.
        IF gd_buffer IS INITIAL.
          EXIT.
        ENDIF.
      ENDDO.
    ENDFORM.
          FORM process_email                                            *
    FORM process_email.
      DESCRIBE TABLE it_mess_att LINES gd_recsize.
      CHECK gd_recsize > 0.
      PERFORM send_email USING p_email1.
    perform send_email using p_email2.
    ENDFORM.
          FORM send_email                                               *
    -->  p_email                                                       *
    FORM send_email USING p_email.
      CHECK NOT ( p_email IS INITIAL ).
      REFRESH it_mess_bod.
    Default subject matter
      gd_subject         = 'Subject'.
      gd_attachment_desc = 'Attachname'.
    CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
      it_mess_bod        = 'Message Body text, line 1'.
      APPEND it_mess_bod.
      it_mess_bod        = 'Message Body text, line 2...'.
      APPEND it_mess_bod.
    If no sender specified - default blank
      IF p_sender EQ space.
        gd_sender_type  = space.
      ELSE.
        gd_sender_type  = 'INT'.
      ENDIF.
    Send file by email as .xls speadsheet
      PERFORM send_file_as_email_attachment
                                   tables it_mess_bod
                                          it_mess_att
                                    using p_email
                                          'Example .xls documnet attachment'
                                          'PDF'
                                          gd_attachment_name
                                          gd_attachment_desc
                                          p_sender
                                          gd_sender_type
                                 changing gd_error
                                          gd_reciever.
    ENDFORM.
          FORM delete_spool                                             *
    FORM delete_spool.
      DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
      ld_spool_nr = gd_spool_nr.
      CHECK p_delspl <> c_no.
      CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
           EXPORTING
                spoolid = ld_spool_nr.
    ENDFORM.
    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
          Send email
    FORM send_file_as_email_attachment tables it_message
                                              it_attach
                                        using p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription
                                              p_sender_address
                                              p_sender_addres_type
                                     changing p_error
                                              p_reciever.
      DATA: ld_error    TYPE sy-subrc,
            ld_reciever TYPE sy-subrc,
            ld_mtitle LIKE sodocchgi1-obj_descr,
            ld_email LIKE  somlreci1-receiver,
            ld_format TYPE  so_obj_tp ,
            ld_attdescription TYPE  so_obj_nam ,
            ld_attfilename TYPE  so_obj_des ,
            ld_sender_address LIKE  soextreci1-receiver,
            ld_sender_address_type LIKE  soextreci1-adr_typ,
            ld_receiver LIKE  sy-subrc.
    data:   t_packing_list like sopcklsti1 occurs 0 with header line,
            t_contents like solisti1 occurs 0 with header line,
            t_receivers like somlreci1 occurs 0 with header line,
            t_attachment like solisti1 occurs 0 with header line,
            t_object_header like solisti1 occurs 0 with header line,
            w_cnt type i,
            w_sent_all(1) type c,
            w_doc_data like sodocchgi1.
      ld_email   = p_email.
      ld_mtitle = p_mtitle.
      ld_format              = p_format.
      ld_attdescription      = p_attdescription.
      ld_attfilename         = p_filename.
      ld_sender_address      = p_sender_address.
      ld_sender_address_type = p_sender_addres_type.
    Fill the document data.
      w_doc_data-doc_size = 1.
    Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = it_attach[].
    Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND t_receivers.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = w_doc_data
                put_in_outbox              = 'X'
                sender_address             = ld_sender_address
                sender_address_type        = ld_sender_address_type
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = w_sent_all
           TABLES
                packing_list               = t_packing_list
                contents_bin               = t_attachment
                contents_txt               = it_message
                receivers                  = t_receivers
           EXCEPTIONS
                too_many_receivers         = 1
                document_not_sent          = 2
                document_type_not_exist    = 3
                operation_no_authorization = 4
                parameter_error            = 5
                x_error                    = 6
                enqueue_error              = 7
                OTHERS                     = 8.
    Populate zerror return code
      ld_error = sy-subrc.
    Populate zreceiver return code
      LOOP AT t_receivers.
        ld_receiver = t_receivers-retrn_code.
      ENDLOOP.
    ENDFORM.
    Hope this resolves your query.
    Reward all the helpful answers.
    Regards

  • How to convert Smart Form into PDF format and return the result in BAPI?

    I want to convert a Smart Form into PDF format and return the result in BAPI.
    can anyone tell me how it can be done with related example
    regards
    pranay

    hi,
    smart form to pdf--
    All you have to do is call your SF to get OTF and then concert it to PDF. Works like charm:
    DATA: p_output_options TYPE ssfcompop,
    p_control_parameters TYPE ssfctrlop.
    p_control_parameters-no_dialog = 'X'.
    p_control_parameters-getotf = 'X'.
    CALL FUNCTION v_func_name "call your smartform
    EXPORTING
    output_options = p_output_options
    control_parameters = p_control_parameters
    IMPORTING
    job_output_info = s_job_output_info.
    call function 'CONVERT_OTF_2_PDF'
    tables
    otf = s_job_output_info-otfdata
    lines = t_pdf
    and if u need more u can check below links also
    Check the below links..
    Re: Smartforms to PDF
    Re: smartform (otf) as pdf and sending as email-attachment
    VISIT THIS LINK
    Re: Smartforms to PDF
    PLZ REWARD POINTS IF IT HELPS YOU
    rgds
    anver

Maybe you are looking for

  • Update MRP Exception Messages...in Oracle Database

    Hi All, I am working on MRP Exception Messages. I am using the BAPI_MATERIAL_MRP_LIST for my MRP Messages. For the above BAPI The Inputs are 1.Material Number 2. Plant. I have the Plant and Material numbers (57,000 i inserted using BAPI_MATERIAL_GETL

  • Uploading data in CRMD_ORDER tcode

    Dear Friends, we are uploading data in CRM 2007. While uploading data for opportunity we want to upload the URL in attachment tab. But we tried for recording in BDC , but it doesn't work. Also in there is no provision for same in CRM_ORDER_MAINTAIN .

  • Doubt on Consuming webservices

    Hi all, I have a requirement to create a webservice from rfc and third party wantsto consume webservice from external system. I have created rfc and webservice from the same and got wsdl link. Can anyone tell how the external system can access wsdl l

  • Open Adobe Reader 9.1.1 in Microsoft Outlook 2003, SP 3

    When I try to open some of my PDF files, I get a notice that I need Outlook 2007, to be able to open the files. Is there a way to set up my computer, so the latest Adobe Reader will open in Microsoft Office Outlook 2003, SP3?

  • How do I modify the logon screen  & orcle dashboard  with custom images

    I want customize the logon page dashboard and also replace ORACLE Dashboard with custom icon. Also I want to remove powered by ORACLE con that appears on presentation/dashboard web pages. Please provide relevant information to achieve this. Thanks an