Abapta Smartforms Çıktısını Mail Olarak Gönderme

Hazırlanan bir smartformu yazılan bir program ile direkt belirlediğimiz bir e-posta adresine mail göndermek için aşağıdaki programdaki kodlardan faydalanabiliriz. Kodarda ufak açıklamalar mevcuttur. Anlaşılmayan bir nokta olması durumunda yorum olarak belirtebilirsiniz.


**&---------------------------------------------------------------------*
**& Report ZMK_CIKTI_MAIL
**&---------------------------------------------------------------------*
**&
**&---------------------------------------------------------------------*
REPORT zmk_cikti_mail.

*/.. Internal Tablo Tanımı

DATA: li_otf TYPE TABLE OF itcoo,

      li_pdf_tab          TYPE TABLE OF tline,

      li_content_txt    TYPE soli_tab,

      li_content_hex  TYPE solix_tab,

      li_objhead         TYPE soli_tab,

      gi_main_text     TYPE bcsy_text.

*/.. Work Area Tanımı

DATA: lw_control_parameters TYPE ssfctrlop,
lw_output_options TYPE ssfcompop,

       lw_ssfcrescl                TYPE ssfcrescl,

       lw_content                  TYPE soli,

       lw_otf                         TYPE itcoo.

*/..Değişken Tanımlamaları

DATA: gv_fname TYPE rs38l_fnam, "Fucntion Module

      gv_subject         TYPE so_obj_des,
      gv_title              TYPE so_obj_des,

      lv_bin_filesize    TYPE i,

      lv_transfer_bin   TYPE sx_boolean,
      lv_len                TYPE so_obj_len,

      lv_email            TYPE ad_smtpadr,

      lv_sent_to_all    TYPE os_boolean.

*/.. Class Tanımı

DATA: go_send_request TYPE REF TO cl_bcs,
go_document TYPE REF TO cl_document_bcs,

      lo_recipient            TYPE REF TO  if_recipient_bcs,
      lo_bcs_exception   TYPE REF TO  cx_bcs.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZMK_SF_MAIL'
IMPORTING
fm_name = gv_fname
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.

*/.. Get OTF data
lw_control_parameters-getotf = 'X'.

*/.. To supress preview
lw_control_parameters-no_dialog = 'X'.

lw_control_parameters-langu = sy-langu.

lw_output_options-tdnoprev = 'X'.

*/.. To add multiple attachments write below code till Add attachment method in LOOP and ENDLOOP.

*Birden fazla dosya eklemek için LOOP ve ENDLOOP’da Ekleme yöntemi ekleninceye kadar aşağıdaki kodu yazın.

*/.. Call Smart Form FM
CALL FUNCTION gv_fname
EXPORTING
control_parameters = lw_control_parameters
output_options = lw_output_options
user_settings = 'X'
IMPORTING
job_output_info = lw_ssfcrescl
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.

*/.. Get OTF data to convert to PDF
REFRESH li_otf[].
li_otf[] = lw_ssfcrescl-otfdata[].

CLEAR : lv_bin_filesize.

*/.. Convert OTF data to binary
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = lv_bin_filesize
TABLES
otf = li_otf
lines = li_pdf_tab
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.



REFRESH li_content_txt.


LOOP AT li_otf  INTO  lw_otf.

  CLEAR lw_content.

  CONCATENATE lw_otf-tdprintcom lw_otf-tdprintpar

         INTO lw_content.

  APPEND lw_content TO li_content_txt.

ENDLOOP.


REFRESH : li_content_hex,
             li_objhead.

CLEAR : lv_transfer_bin,
          lv_len.

DATA: lo_sender TYPE REF TO cl_cam_address_bcs. "sender

*/.. FM to convert OTF to PDF
CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
EXPORTING
format_src = 'otf'
format_dst = 'pdf'
CHANGING
transfer_bin = lv_transfer_bin
content_txt = li_content_txt
content_bin = li_content_hex
objhead = li_objhead
len = lv_len
EXCEPTIONS
err_conv_failed = 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.





TRY.

*/.. Create persistent send request
go_send_request = cl_bcs=>create_persistent( ).

  go_document = cl_document_bcs=>create_document(

        i_type     = 'raw'

        i_text      = gi_main_text

        i_subject = gv_subject ).

   IF NOT li_content_hex IS INITIAL.
      go_document->add_attachment(
        i_attachment_type      =  'pdf'

        i_attachment_subject  =  gv_title




        i_attachment_size      =   lv_len
        i_att_content_hex       =   li_content_hex ).
    ENDIF.

*/.. Add document object to send request
go_send_request->set_document( go_document ).

  TRY.

* lo_sender = cl_sapuser_bcs=>create( sy-uname ). "sender is the logged in user
* Set sender to send request
CALL METHOD cl_cam_address_bcs=>create_internet_address
EXPORTING
i_address_string = 'iletisim@website.info.tr' " Gönderen Adres
RECEIVING
result = lo_sender.
go_send_request->set_sender(
EXPORTING
i_sender = lo_sender ).
* CATCH CX_ADDRESS_BCS.
****Catch exception here
ENDTRY.

  lv_email = 'mehdikapsal@website.info.tr'. "Alıcı Adres

*/.. Add recipient (e-mail address)
*/.. create recipient object
lo_recipient = cl_cam_address_bcs=>create_internet_address(
lv_email ).

*/.. Add recipient object to send request
go_send_request->add_recipient( lo_recipient ).

*/.. Send document
lv_sent_to_all = go_send_request->send( i_with_error_screen =
abap_true ).

COMMIT WORK.

  IF lv_sent_to_all IS INITIAL.
      "Hata Mesajı

  MESSAGE 'Mail Gönderilemedi.' TYPE 'S' DISPLAY LIKE'E'.

  else.
      "Başarı Message
  endif.

*/.. Exception handling
CATCH cx_bcs INTO lo_bcs_exception.
"Exception Handling

 endtry.

Mehdi Kapsal

Bilgisayar Mühendisi

Abapta Smartforms Çıktısını Mail Olarak Gönderme” için bir yorum

  • 23 Ekim 2019 tarihinde, saat 15:44
    Permalink

    Çıktı popupı gelmeden mail gönderilmesini istiyorsanız aşağıdaki kodlar eklenebilir. Aşağıdaki kodlarla birlikte ‘X’ olan user_settings i boş bırakmak gerekli.

    lw_control_parameters-getotf = ‘X’.
    lw_control_parameters-NO_DIALOG = ‘X’.
    lw_control_parameters-GETOTF = ‘X’.
    lw_control_parameters-LANGU = ‘T’.
    lw_control_parameters-PREVIEW = ‘X’.
    lw_control_parameters-NO_DIALOG = ‘X’.
    lw_control_parameters-DEVICE = ‘PRINTER’.
    lw_output_options-TDNOPRINT = ‘X’. “No printing from print preview
    lw_output_options-TDDEST = ‘LP01’.

    Yanıtla

Abapçı için bir cevap yazın Cevabı iptal et

%d blogcu bunu beğendi: