"
Supported by

Sending a report or spool job by email

This post inaugurates a new category in Abapinho: Code. Posts in this category will present useful programs that are ready to execute.

This one is used for sending the result of any report or spool order by e-mail. This program makes use of the new BCS (Business Communication Services) through the CL_BCS class instead of the tired and old SO_DOCUMENT_SEND_API1, may its soul rest in peace.

The content can be sent in the body of the email, as a TXT attachment or as an HTML attachment, with the latter being sent nice and neat with all the colours. Enjoy it. Blindly copy it and use it or dissect it and learn how to use CL_BCS. On the way, you can still learn, if you feel like it, how to use local classes and exception classes.

A local class is simpler to show here in Abapinho but if you want you can transform it into a global class through SE24 as Abapinho already explained some time ago so that you can use it anywhere.


*&---------------------------------------------------------------------*
*& Report ZZZ_NFG_SEND_REPORT_BY_EMAIL
*&
*&---------------------------------------------------------------------*
*& Author: Nuno Godinho
*& Date:   03 January 2012
*& Description: Sends an abap list (generated by a submitted program or
*&              read from an existing spool) by email. The list can be
*&              sent either in the email body, as a text attachment or
*&              as an HTML attachment.
*&---------------------------------------------------------------------*
REPORT zzz_nfg_send_list_by_mail MESSAGE-ID so.

***************************************************************************

* Exception classes
CLASS zcx_zs_no_receivers       
  DEFINITION FINAL INHERITING FROM cx_static_check. 
ENDCLASS.
CLASS zcx_zs_spool_error        
  DEFINITION FINAL INHERITING FROM cx_static_check. 
ENDCLASS.
CLASS zcx_zs_invalid_parameters 
  DEFINITION FINAL INHERITING FROM cx_static_check. 
ENDCLASS.
CLASS zcx_zs_objectlist_error   
  DEFINITION FINAL INHERITING FROM cx_static_check. 
ENDCLASS.

*----------------------------------------------------------------------*
*       CLASS cl_send_list_by_mail DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_send_list_by_mail DEFINITION.
  PUBLIC SECTION.
    TYPES: ty_send_mode TYPE char4,
           ty_source    TYPE char6.

    CONSTANTS:
      k_send_mode_text        TYPE ty_send_mode VALUE 'TEXT',
      k_send_mode_text_attach TYPE ty_send_mode VALUE 'TXTA',
      k_send_mode_html_attach TYPE ty_send_mode VALUE 'HTMA',
      k_send_mode_attachment  TYPE ty_send_mode VALUE space,

      k_source_submit         TYPE ty_source    VALUE 'SUBMIT',
      k_source_spool          TYPE ty_source    VALUE 'SPOOL'.

    METHODS:
      constructor
        RAISING
          cx_send_req_bcs,

      add_recipient
        IMPORTING
          i_smtp_address TYPE ad_smtpadr
        RAISING
          cx_send_req_bcs
          cx_address_bcs,

      submit_and_send_mail
        IMPORTING
          i_report       TYPE program
          i_variant      TYPE raldb_vari
          i_send_mode    TYPE ty_send_mode
          i_subject      TYPE so_obj_des
          i_smtp_address TYPE ad_smtpadr OPTIONAL
        RAISING
          zcx_zs_no_receivers
          cx_bcs
          zcx_zs_invalid_parameters
          zcx_zs_objectlist_error
          zcx_zs_spool_error,

      read_spool_and_send_mail
        IMPORTING
          i_spool_number TYPE rspoid
          i_send_mode    TYPE ty_send_mode
          i_subject      TYPE so_obj_des
          i_smtp_address TYPE ad_smtpadr OPTIONAL
        RAISING
          zcx_zs_no_receivers
          zcx_zs_invalid_parameters
          zcx_zs_objectlist_error
          cx_send_req_bcs
          cx_bcs
          zcx_zs_spool_error.

  PRIVATE SECTION.
    DATA: go_send_request       TYPE REF TO cl_bcs.

    METHODS:
      get_objectlist_and_send_mail
        IMPORTING
          i_source       TYPE ty_source
          i_report       TYPE program OPTIONAL
          i_variant      TYPE raldb_vari OPTIONAL
          i_spool_number TYPE rspoid OPTIONAL
          i_send_mode    TYPE ty_send_mode
          i_subject      TYPE so_obj_des
          i_smtp_address TYPE ad_smtpadr OPTIONAL
        RAISING
          zcx_zs_no_receivers
          zcx_zs_invalid_parameters
          zcx_zs_objectlist_error
          cx_bcs
          zcx_zs_spool_error,

      submit_report_to_memory
        IMPORTING
          value(i_report)     TYPE program
          value(i_variant)    TYPE raldb_vari
        RETURNING
          value(ot_listobject) TYPE table_abaplist
        RAISING
          zcx_zs_objectlist_error,

      read_spool_to_memory
        IMPORTING
          i_spool_number     TYPE rspoid
        RETURNING
          value(ot_listobject) TYPE table_abaplist
        RAISING
          zcx_zs_spool_error,

       get_objectlist
        IMPORTING
          i_source       TYPE ty_source
          value(i_report)     TYPE program
          value(i_variant)    TYPE raldb_vari
          i_spool_number     TYPE rspoid
        RETURNING
          value(ot_listobject) TYPE table_abaplist
        RAISING
          zcx_zs_spool_error
          zcx_zs_objectlist_error,

       create_text_document
         IMPORTING
           i_report       TYPE program
           i_variant      TYPE raldb_vari
           i_spool_number TYPE rspoid
           i_subject      TYPE so_obj_des
           it_listobject  TYPE table_abaplist OPTIONAL
         RETURNING
           value(o_document)    TYPE REF TO cl_document_bcs
         RAISING
           zcx_zs_objectlist_error
           cx_document_bcs,

       add_header_to_body
         IMPORTING
           i_report       TYPE program
           i_variant      TYPE raldb_vari
           i_spool_number TYPE rspoid
         CHANGING
           xt_soli TYPE soli_tab,

      add_abaplist_text_attach
        IMPORTING
          it_listobject   TYPE table_abaplist
          i_name          TYPE so_obj_des
        CHANGING
          x_document      TYPE REF TO cl_document_bcs
        RAISING
          zcx_zs_objectlist_error
          cx_document_bcs,

      add_abaplist_html_attach
        IMPORTING
          it_listobject   TYPE table_abaplist
          i_name          TYPE so_obj_des
        CHANGING
          x_document      TYPE REF TO cl_document_bcs
        RAISING
          cx_document_bcs,

      send_mail
        IMPORTING
          value(it_listobject) TYPE table_abaplist
          i_report      TYPE program OPTIONAL
          i_variant     TYPE raldb_vari OPTIONAL
          i_spool_number TYPE rspoid OPTIONAL
          i_send_mode   TYPE ty_send_mode
          i_subject     TYPE so_obj_des
        RAISING
          zcx_zs_objectlist_error
          zcx_zs_invalid_parameters
          cx_bcs,

      build_attach_name
        IMPORTING
          i_report    TYPE program
          i_variant   TYPE raldb_vari
          i_spool_number TYPE rspoid
          i_extension TYPE so_obj_des OPTIONAL
        RETURNING value(o_name) TYPE so_obj_des.

ENDCLASS.                    "cl_send_list_by_mail DEFINITION

*----------------------------------------------------------------------*
*       CLASS cl_send_list_by_mail IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_send_list_by_mail IMPLEMENTATION.

  METHOD constructor.
*   Create the send request
    go_send_request = cl_bcs=>create_persistent( ).
    go_send_request->set_send_immediately( 'X' ).
  ENDMETHOD.                    "constructor

  METHOD add_recipient.
    DATA: recipient TYPE REF TO if_recipient_bcs.
    recipient = cl_cam_address_bcs=>create_internet_address( i_smtp_address ).
    go_send_request->add_recipient( recipient ).
  ENDMETHOD.                    "add_receiver

  METHOD submit_and_send_mail.
    get_objectlist_and_send_mail(
              i_source       = k_source_submit
              i_send_mode    = i_send_mode
              i_report       = i_report
              i_variant      = i_variant
              i_subject      = i_subject ).
  ENDMETHOD.                    "submit_report_and_sendmail

  METHOD read_spool_and_send_mail.
    get_objectlist_and_send_mail(
              i_source       = k_source_spool
              i_send_mode    = i_send_mode
              i_spool_number = i_spool_number
              i_subject      = i_subject ).
  ENDMETHOD.                    "read_spool_and_send_mail

  METHOD get_objectlist_and_send_mail.
    DATA: t_recipients TYPE bcsy_re,
          t_listobject TYPE table_abaplist.

*   Check parameters
    IF ( i_source = k_source_spool AND i_spool_number IS INITIAL ) OR
       ( i_source = k_source_submit AND i_report IS INITIAL ).
      RAISE EXCEPTION TYPE zcx_zs_invalid_parameters.
    ENDIF.

*   Add recipient if supplied
    IF i_smtp_address IS SUPPLIED.
      add_recipient( i_smtp_address ).
    ENDIF.

*   It should only run if there is at least one recipient
    t_recipients = go_send_request->recipients( ).
    IF t_recipients[] IS INITIAL.
      RAISE EXCEPTION TYPE zcx_zs_no_receivers.
    ENDIF.

*   Get objectlist either from submit or from spool
    t_listobject = get_objectlist(
      i_source       = i_source
      i_report       = i_report
      i_variant      = i_variant
      i_spool_number = i_spool_number ).

*   Send email
    CALL METHOD send_mail
      EXPORTING
        it_listobject  = t_listobject
        i_report       = i_report
        i_variant      = i_variant
        i_spool_number = i_spool_number
        i_send_mode    = i_send_mode
        i_subject      = i_subject.
  ENDMETHOD.                    "get_objectlist_and_send_mail

  METHOD get_objectlist.
*   Get abap list into memory (either from spool or submit)
    IF i_source = k_source_submit.
      submit_report_to_memory( i_report  = i_report i_variant = i_variant ).
    ELSE.
      read_spool_to_memory( i_spool_number = i_spool_number ).
    ENDIF.

*   Import the list from memory and store it in table listobject
    REFRESH : ot_listobject.
    CALL FUNCTION 'LIST_FROM_MEMORY'
      TABLES
        listobject = ot_listobject
      EXCEPTIONS
        not_found  = 1
        OTHERS     = 2.
    IF sy-subrc <> 0.
      RAISE EXCEPTION TYPE zcx_zs_objectlist_error.
    ENDIF.

*   Free memory
    CALL FUNCTION 'LIST_FREE_MEMORY'
      TABLES
        listobject = ot_listobject
      EXCEPTIONS
        OTHERS     = 1.
    IF sy-subrc <> 0.
      RAISE EXCEPTION TYPE zcx_zs_objectlist_error.
    ENDIF.

  ENDMETHOD.                    "get_objectlist

  METHOD submit_report_to_memory.
    TRANSLATE: i_report  TO UPPER CASE,
               i_variant TO UPPER CASE.
*   Submit report
    SUBMIT (i_report) USING SELECTION-SET i_variant EXPORTING LIST TO MEMORY AND RETURN.
  ENDMETHOD.                    "submit_report

  METHOD read_spool_to_memory.
*   Adapted from FM RSPO_RETURN_ABAP_SPOOLJOB. This FM converts the list to ASCII
*   and I needed it as an ABAPLIST so I just copied the code and adapted it
    DATA: data_is_otf TYPE c.

    CALL FUNCTION 'RSPO_CHECK_JOB_ID_PERMISSION'
      EXPORTING
        rqident       = i_spool_number
        access        = 'DISP'
      EXCEPTIONS
        no_such_job   = 1
        no_permission = 2.
    IF sy-subrc <> 0.
      RAISE EXCEPTION TYPE zcx_zs_spool_error.
    ENDIF.

    CALL FUNCTION 'RSPO_GET_TYPE_SPOOLJOB'
      EXPORTING
        rqident        = i_spool_number
      IMPORTING
        is_otf         = data_is_otf
      EXCEPTIONS
        can_not_access = 1.
    IF sy-subrc <> 0.
      RAISE EXCEPTION TYPE zcx_zs_spool_error.
    ENDIF.

    IF data_is_otf = 'X'.
      RAISE EXCEPTION TYPE zcx_zs_spool_error.
    ELSE.
      SUBMIT rspolist EXPORTING LIST TO MEMORY AND RETURN
                      WITH rqident = i_spool_number
                      WITH first = 1
                      WITH last = 0
                      WITH pages = space.
    ENDIF.
  ENDMETHOD.                    "read_spool

  METHOD send_mail.

    DATA: document       TYPE REF TO cl_document_bcs,
          sent_to_all    TYPE os_boolean,
          bcs_exception  TYPE REF TO cx_bcs,
          name           TYPE so_obj_des.

    IF i_send_mode = k_send_mode_text.
      document = create_text_document(
        i_report       = i_report
        i_variant      = i_variant
        i_spool_number = i_spool_number
        it_listobject  = it_listobject
        i_subject      = i_subject ).
    ELSE.
*     Create text document without adding listobject to the body (it will be attached)
      document = create_text_document(
        i_report       = i_report
        i_variant      = i_variant
        i_spool_number = i_spool_number
        i_subject      = i_subject ).
*     Add attachment to document
      IF i_send_mode = k_send_mode_text_attach.
        name = build_attach_name(
          i_report       = i_report
          i_variant      = i_variant
          i_spool_number = i_spool_number
          i_extension    = 'TXT' ).
        add_abaplist_text_attach(
           EXPORTING
             it_listobject = it_listobject
             i_name        = name
          CHANGING
            x_document = document ).
      ELSEIF i_send_mode = k_send_mode_html_attach.
        name = build_attach_name(
          i_report       = i_report
          i_variant      = i_variant
          i_spool_number = i_spool_number ).
        add_abaplist_html_attach(
           EXPORTING
             it_listobject = it_listobject
             i_name        = name
          CHANGING
            x_document = document ).
      ENDIF.
    ENDIF.

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

*   Send
    sent_to_all = go_send_request->send( i_with_error_screen = 'X' ).
*    IF sent_to_all NE 'X'.
*      RAISE EXCEPTION TYPE zcx_zs_mail_not_sent.
*    ENDIF.

  ENDMETHOD.                    "send_mail

  METHOD create_text_document.
    DATA: t_listasci   TYPE STANDARD TABLE OF solisti1,
          t_listobject LIKE it_listobject,
          t_soli       TYPE soli_tab,
          w_soli       LIKE LINE OF t_soli.

*   Add header
    add_header_to_body(
      EXPORTING
        i_report       = i_report
        i_variant      = i_variant
        i_spool_number = i_spool_number
      CHANGING
        xt_soli = t_soli ).

*   Add abap list
    IF it_listobject IS SUPPLIED.

      CLEAR w_soli.
      APPEND w_soli TO t_soli.
      w_soli = '------------------------------------------------------'.
      APPEND w_soli TO t_soli.
      CLEAR w_soli.
      APPEND w_soli TO t_soli.

      t_listobject[] = it_listobject[].
      CALL FUNCTION 'LIST_TO_ASCI'
        TABLES
          listasci           = t_listasci
          listobject         = t_listobject
        EXCEPTIONS
          empty_list         = 1
          list_index_invalid = 2
          OTHERS             = 3.
      IF sy-subrc <> 0.
        RAISE EXCEPTION TYPE zcx_zs_objectlist_error.
      ENDIF.
      APPEND LINES OF t_listasci TO t_soli.
    ENDIF.

*   Create text document
    o_document = cl_document_bcs=>create_document(
                            i_type    = 'RAW'
                            i_text    = t_soli
                            i_subject = i_subject ).
  ENDMETHOD.                    "create_text_document

  METHOD add_header_to_body.
    DATA: w_soli LIKE LINE OF xt_soli.

    IF i_report IS NOT INITIAL.
      CONCATENATE 'Report:' i_report INTO w_soli SEPARATED BY space.
      APPEND w_soli TO xt_soli.
    ENDIF.

    IF i_variant IS NOT INITIAL.
      CONCATENATE 'Variant:' i_variant INTO w_soli SEPARATED BY space.
      APPEND w_soli TO xt_soli.
    ENDIF.

    IF i_spool_number IS NOT INITIAL.
      MOVE i_spool_number TO w_soli.
      CONCATENATE 'Spool number:' w_soli INTO w_soli SEPARATED BY space.
      APPEND w_soli TO xt_soli.
    ENDIF.

    CONCATENATE 'Date:' sy-datum sy-uzeit INTO w_soli SEPARATED BY space.
    APPEND w_soli TO xt_soli.

    CONCATENATE 'User:' sy-uname INTO w_soli SEPARATED BY space.
    APPEND w_soli TO xt_soli.

  ENDMETHOD.                    "build_header

  METHOD add_abaplist_text_attach.
    DATA: t_solix TYPE solix_tab.

*   It's always necessary to compress the table. SAPconnect will decompress it
    CALL FUNCTION 'TABLE_COMPRESS'                          "#EC *
      TABLES
        in             = it_listobject
        out            = t_solix
      EXCEPTIONS
        compress_error = 1
        OTHERS         = 2.
    IF sy-subrc <> 0.
      RAISE EXCEPTION TYPE zcx_zs_objectlist_error.
    ENDIF.

    x_document->add_attachment(
      i_attachment_type    = 'ALI'
      i_attachment_subject = i_name
      i_att_content_hex    = t_solix ).

  ENDMETHOD.                    "add_abaplist_text_attach

  METHOD add_abaplist_html_attach.
    DATA: t_soli       TYPE soli_tab,
          t_listobject LIKE it_listobject.

    t_listobject[] = it_listobject[].

    CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'
      TABLES
        html       = t_soli
        listobject = t_listobject.

    x_document->add_attachment(
      i_attachment_type    = 'HTM'
      i_attachment_subject = i_name
      i_att_content_text   = t_soli ).

  ENDMETHOD.                    "add_abaplist_html_attach

  METHOD build_attach_name.
    IF i_report IS NOT INITIAL.
      o_name = i_report.
      IF i_variant IS NOT INITIAL.
        CONCATENATE o_name '-' i_variant INTO o_name.
      ENDIF.
    ELSE.
      MOVE i_spool_number TO o_name.
      SHIFT o_name LEFT DELETING LEADING space.
    ENDIF.
    CONCATENATE o_name '-' sy-datum '-' sy-uzeit INTO o_name.
    IF i_extension IS NOT INITIAL.
      CONCATENATE o_name '.' i_extension INTO o_name.
    ENDIF.
  ENDMETHOD.                    "build_attach_name

ENDCLASS.                    "cl_send_list_by_mail IMPLEMENTATION

***************************************************************************
TABLES: adr6.

*------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_subj TYPE so_obj_des OBLIGATORY.
SELECT-OPTIONS: s_rec  FOR adr6-smtp_addr NO INTERVALS LOWER CASE OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: p_submit RADIOBUTTON GROUP typ USER-COMMAND typ.
SELECTION-SCREEN BEGIN OF BLOCK b2a WITH FRAME.
PARAMETERS:     p_rep  TYPE program MODIF ID ty1,
              p_var  TYPE raldb_vari MODIF ID ty1.
SELECTION-SCREEN END OF BLOCK b2a.
PARAMETERS: p_spool RADIOBUTTON GROUP typ.
SELECTION-SCREEN BEGIN OF BLOCK b2b WITH FRAME.
PARAMETERS:   p_rspoid TYPE rspoid MODIF ID ty2.
SELECTION-SCREEN END OF BLOCK b2b.
SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
PARAMETERS: p_text  RADIOBUTTON GROUP opt,
            p_texta RADIOBUTTON GROUP opt,
            p_htmla RADIOBUTTON GROUP opt DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK b3.

AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    IF screen-group1 = 'TY1'.
      IF p_submit IS NOT INITIAL.
        screen-input = 1.
      ELSE.
        screen-input = 0.
      ENDIF.
      MODIFY SCREEN.
    ENDIF.
    IF screen-group1 = 'TY2'.
      IF p_spool IS NOT INITIAL.
        screen-input = 1.
      ELSE.
        screen-input = 0.
      ENDIF.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.

START-OF-SELECTION.

  DATA: go_sender TYPE REF TO cl_send_list_by_mail,
        send_mode TYPE cl_send_list_by_mail=>ty_send_mode,
        exc_ref   TYPE REF TO cx_root,
        text      TYPE string.

  IF ( p_submit IS NOT INITIAL AND p_rep IS INITIAL ) OR
     ( p_spool IS NOT INITIAL AND p_rspoid IS INITIAL ).
    MESSAGE s622 DISPLAY LIKE 'E'.
    EXIT.
  ENDIF.

  CREATE OBJECT go_sender.

* Determine send mode
  CASE 'X'.
    WHEN p_texta.
      send_mode = cl_send_list_by_mail=>k_send_mode_text_attach.
    WHEN p_htmla.
      send_mode = cl_send_list_by_mail=>k_send_mode_html_attach.
    WHEN OTHERS.
      send_mode = cl_send_list_by_mail=>k_send_mode_text.
  ENDCASE.

* Add recipients
  LOOP AT s_rec.
    CALL METHOD go_sender->add_recipient
      EXPORTING
        i_smtp_address = s_rec-low.
  ENDLOOP.

  TRY.
      CASE 'X'.
        WHEN p_submit.
          CALL METHOD go_sender->submit_and_send_mail
            EXPORTING
              i_send_mode = send_mode
              i_report    = p_rep
              i_variant   = p_var
              i_subject   = p_subj.
        WHEN p_spool.
          CALL METHOD go_sender->read_spool_and_send_mail
            EXPORTING
              i_send_mode    = send_mode
              i_spool_number = p_rspoid
              i_subject      = p_subj.
      ENDCASE.
      WRITE: / 'Mail message sent'.
    CATCH cx_root INTO exc_ref.
      text = exc_ref->get_text( ).
      WRITE: / text.
  ENDTRY.

* It will not work without this commit
  COMMIT WORK.

Texts for selection screen:

P_SUBJSubject
S_RECRecipients
P_SUBMITSend report
P_REPReport
P_VARVariant
P_SPOOLSend spool job
P_RSPOIDSpool job ID
P_TEXTEmail body
P_TEXTATXT attachment
P_HTMLAHTML attachment

Greetings from Abapinho.

10 comentários a “Sending a report or spool job by email”

  1. Murilo Diz:

    Eu tentei usar essa função, mas como vem de um spool OTF, e eu quero gerar um pdf, ele deu um erro pois ele é OTF.
    Você sabe alguma função que faça isso?
    IF data_is_otf = ‘X’.
    RAISE EXCEPTION TYPE zcx_zs_spool_error.

    você consegue me ajudar nesse caso?

    Obrigado.

  2. admin Diz:

    Olá Murilo, vê lá se isto te ajuda:

    http://forums.sdn.sap.com/thread.jspa?threadID=1406475

    http://www.howforge.com/abap-4-example-code-download-otf-spool-to-pdf

    http://wiki.sdn.sap.com/wiki/display/ABAP/PDF+files+in+SAP

  3. Fabio Diz:

    Eu não consegui mudar o nome do arquivo anexo. Ele atribui e eu não consegui passar…

  4. Lucas (Osvaldo) Diz:

    Bom, caso ainda precisam segue um report, gera um SMARTFORMS, Gera o PDF e envia por email, sem usar o spool.

    Código ta meio feio, mais era com apenas 3 meses de experiencia.

    Objetivo: Encaminhar email a todos os fornecedores que tiveram suas notas pagas através da rotina de pagamento automático.

    ************************************************************************
    * Autor : Lucas Augusto Gonçalves *
    * Data : 14.07.2011 *
    * Descrição : *
    * Transação : ZFIR056 *
    * Projeto : *
    * Request : *
    ************************************************************************
    * Histórico Das Modificações *
    ************************************************************************
    * Autor : *
    * Data : *
    * Comentário : *
    ************************************************************************

    *———————————————————————-*
    * Report
    *———————————————————————-*
    REPORT zfir016.

    *———————————————————————-*
    * Tabelas
    *———————————————————————-*
    TABLES : reguh,
    regup,
    lfa1,
    adr6.

    *———————————————————————-*
    * Tipos
    *———————————————————————-*
    TYPE-POOLS: icon,
    slis.

    TYPES: BEGIN OF ty_relatorio,
    status TYPE icon-name,
    lifnr TYPE regup-lifnr,
    name1 TYPE reguh-name1,
    msg TYPE string,
    END OF ty_relatorio.

    TYPES: BEGIN OF ty_reguh,
    laufd TYPE reguh-laufd,
    laufi TYPE reguh-laufi,
    xvorl TYPE reguh-xvorl,
    zbukr TYPE reguh-zbukr,
    lifnr TYPE reguh-lifnr,
    kunnr TYPE reguh-kunnr,
    empfg TYPE reguh-empfg,
    vblnr TYPE reguh-vblnr,
    name1 TYPE reguh-name1,
    zaldt TYPE reguh-zaldt,
    END OF ty_reguh.

    TYPES: BEGIN OF ty_regup,
    laufd TYPE regup-laufd,
    laufi TYPE regup-laufi,
    xvorl TYPE regup-xvorl,
    zbukr TYPE regup-zbukr,
    lifnr TYPE regup-lifnr,
    kunnr TYPE regup-kunnr,
    empfg TYPE regup-empfg,
    vblnr TYPE regup-vblnr,
    bukrs TYPE regup-bukrs,
    belnr TYPE regup-belnr,
    gjahr TYPE regup-gjahr,
    buzei TYPE regup-buzei,
    dmbtr TYPE regup-dmbtr,
    xblnr TYPE regup-xblnr,
    name1 TYPE reguh-name1,
    zaldt TYPE reguh-zaldt,
    END OF ty_regup.

    TYPES: BEGIN OF ty_lfa1,
    lifnr TYPE lfa1-lifnr,
    name1 TYPE lfa1-name1,
    adrnr TYPE lfa1-adrnr,
    END OF ty_lfa1.

    TYPES: BEGIN OF ty_adr6,
    addrnumber TYPE adr6-addrnumber,
    persnumber TYPE adr6-persnumber,
    date_from TYPE adr6-date_from ,
    consnumber TYPE adr6-consnumber,
    smtp_addr TYPE adr6-smtp_addr ,
    END OF ty_adr6.

    *———————————————————————-*
    * Tabelas Internas
    *———————————————————————-*
    DATA: tg_reguh TYPE TABLE OF ty_reguh,
    tg_regup TYPE TABLE OF ty_regup,
    tg_lfa1 TYPE TABLE OF ty_lfa1,
    tg_adr6 TYPE TABLE OF ty_adr6,
    tg_reclist TYPE TABLE OF somlreci1,
    tg_saida TYPE zfict013,
    tg_saida2 TYPE zfict013,
    tg_control TYPE TABLE OF ssfctrlop.

    DATA: tg_events TYPE TABLE OF slis_alv_event.
    DATA: tg_relatorio TYPE TABLE OF ty_relatorio.

    DATA: tg_objtxt TYPE TABLE OF solisti1,
    tg_objbin TYPE TABLE OF solisti1,
    tg_objhead TYPE TABLE OF solisti1,
    tg_tline TYPE TABLE OF tline,
    tg_objpack TYPE TABLE OF sopcklsti1.

    *———————————————————————-*
    * Estruturas/Work areas
    *———————————————————————-*
    DATA: wg_reguh TYPE ty_reguh,
    wg_regup TYPE ty_regup,
    wg_lfa1 TYPE ty_lfa1,
    wg_adr6 TYPE ty_adr6,
    wg_reclist TYPE somlreci1,
    wg_saida TYPE zfie013,
    wg_saida2 TYPE zfie013,
    wg_control TYPE ssfctrlop.

    DATA: wg_relatorio TYPE ty_relatorio.

    DATA: wg_objtxt TYPE solisti1,
    wg_objbin TYPE solisti1,
    wg_tline TYPE tline,
    wg_doc_chng TYPE sodocchgi1,
    wg_objpack TYPE sopcklsti1,
    wg_objhead TYPE soli_tab.

    DATA: wg_buffer TYPE string.

    DATA: i_record TYPE solisti1 OCCURS 0 WITH HEADER LINE.

    *———————————————————————-*
    * Variáveis
    *———————————————————————-*
    DATA: vl_smtp_to TYPE adr6-smtp_addr,
    vl_len_in TYPE sood-objlen.

    DATA : i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
    i_tline TYPE TABLE OF tline WITH HEADER LINE. ” make each line 132 character

    *** make each line 255 characters
    DATA : BEGIN OF i_tline2 OCCURS 0,
    tline TYPE char255,
    END OF i_tline2.

    * Variáveis ALV
    DATA: tg_fieldcat TYPE slis_t_fieldcat_alv.
    DATA: wg_fieldcat LIKE LINE OF tg_fieldcat.
    DATA: vg_colpos(05) TYPE n.

    DATA: vg_lines_bin TYPE i,
    vg_lines_txt TYPE i.

    *———————————————————————-*
    * Constantes
    *———————————————————————-*
    DATA: c_x(1) TYPE c VALUE ‘X’,
    c_u(1) TYPE c VALUE ‘U’,
    c_l(1) TYPE c VALUE ‘L’,
    c_10(2) TYPE c VALUE ’10’,
    c_30(2) TYPE c VALUE ’30’,
    c_35(2) TYPE c VALUE ’35’,
    c_status(6) TYPE c VALUE ‘STATUS’,
    c_lifnr(5) TYPE c VALUE ‘LIFNR’,
    c_regup(5) TYPE c VALUE ‘REGUP’,
    c_name1(5) TYPE c VALUE ‘NAME1’,
    c_reguh(5) TYPE c VALUE ‘REGUH’,
    c_msg(3) TYPE c VALUE ‘MSG’,
    c_string(6) TYPE c VALUE ‘STRING’,
    c_tabcolor(8) TYPE c VALUE ‘TABCOLOR’,
    c_st TYPE tdid VALUE ‘ST’,
    c_text(10) TYPE c VALUE ‘TEXT’,
    c_raw(03) TYPE c VALUE ‘RAW’.

    *———————————————————————-*
    * Definição dos Parâmetros de Seleção
    *———————————————————————-*
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

    PARAMETERS: p_laufd TYPE reguh-laufd OBLIGATORY, “Dia de Execução
    p_laufi TYPE reguh-laufi OBLIGATORY. “Identificação
    SELECT-OPTIONS: s_lifnr FOR regup-lifnr . “Código do Fornecedor

    SELECTION-SCREEN END OF BLOCK b1.

    *———————————————————————-*
    * Start-of-Selection
    *———————————————————————-*
    START-OF-SELECTION.

    * Valida dada
    PERFORM valida_data.

    * Seleção das tabelas utilizadas
    PERFORM selecao.

    * Monta Email
    PERFORM prepara_email.

    END-OF-SELECTION.

    *&———————————————————————*
    *& Form VALIDA_DADA
    *&———————————————————————
    FORM valida_data.

    IF p_laufd > sy-datum.
    MESSAGE i208(00) WITH text-e02. “Data não pode ser futura
    LEAVE LIST-PROCESSING.
    ENDIF.

    ENDFORM. ” VALIDA_DADA

    *&———————————————————————*
    *& Form SELECAO
    *&———————————————————————*
    FORM selecao .

    * Seleciona os dados para seleção
    SELECT laufd laufi xvorl zbukr lifnr
    kunnr empfg vblnr name1 zaldt
    FROM reguh
    INTO CORRESPONDING FIELDS OF TABLE tg_reguh
    WHERE laufd = p_laufd AND
    laufi = p_laufi AND
    lifnr IN s_lifnr.

    * Se existe, seleciona os dados do email
    IF sy-subrc = 0.
    SORT tg_reguh BY laufd laufi xvorl zbukr lifnr
    kunnr empfg vblnr.

    SELECT laufd laufi xvorl zbukr lifnr
    kunnr empfg vblnr bukrs belnr
    gjahr buzei dmbtr xblnr
    FROM regup
    INTO CORRESPONDING FIELDS OF TABLE tg_regup
    FOR ALL ENTRIES IN tg_reguh
    WHERE laufd = tg_reguh-laufd AND
    laufi = tg_reguh-laufi AND
    xvorl = space AND
    zbukr = tg_reguh-zbukr AND
    lifnr = tg_reguh-lifnr AND
    kunnr = tg_reguh-kunnr AND
    empfg = tg_reguh-empfg AND
    vblnr space.

    IF tg_regup IS NOT INITIAL.

    * Seleciona o cod do fornecedor
    SELECT lifnr name1 adrnr
    FROM lfa1
    INTO TABLE tg_lfa1
    FOR ALL ENTRIES IN tg_reguh
    WHERE lifnr = tg_reguh-lifnr.

    IF tg_lfa1 IS NOT INITIAL.

    * Seleciona o email (destinatário)
    SELECT addrnumber persnumber date_from
    consnumber smtp_addr
    FROM adr6
    INTO CORRESPONDING FIELDS OF TABLE tg_adr6
    FOR ALL ENTRIES IN tg_lfa1
    WHERE addrnumber = tg_lfa1-adrnr.

    ENDIF.

    ELSE.
    * Se seleção não encontrar, msg de erro
    MESSAGE i208(00) WITH text-e01.
    LEAVE LIST-PROCESSING.

    ENDIF.

    ELSE.
    * Se seleção não encontrar, msg de erro
    MESSAGE i208(00) WITH text-e01.
    LEAVE LIST-PROCESSING.

    ENDIF.

    ENDFORM. ” SELECAO

    *&———————————————————————*
    *& Form PREPARA_EMAIL
    *&———————————————————————*
    FORM prepara_email .

    * Preenche dados a ser exibidos
    PERFORM abastece_email.
    * Mostra na tela para usuario o LOG
    PERFORM relatorio.

    ENDFORM. ” PREPARA_EMAIL

    *&———————————————————————*
    *& Form ABASTECE_EMAIL
    *&———————————————————————*
    FORM abastece_email .

    DATA: vl_total TYPE string.

    SORT tg_reguh BY name1.

    REFRESH: tg_saida2[].
    CLEAR: wg_saida2.
    CLEAR: vl_total.

    LOOP AT tg_reguh INTO wg_reguh.

    CLEAR: wg_saida2.
    *Dados para preencher o cabelho do smartforms
    MOVE: wg_reguh-name1 TO wg_saida2-name1, ” Nome fornecedor
    wg_reguh-zaldt TO wg_saida2-zaldt. ” Dt. Pagamento

    APPEND wg_saida2 TO tg_saida2.

    REFRESH : tg_saida[].
    CLEAR: wg_saida.
    CLEAR: vl_total.

    LOOP AT tg_regup INTO wg_regup WHERE laufd = wg_reguh-laufd AND
    laufi = wg_reguh-laufi AND
    xvorl = wg_reguh-xvorl AND
    zbukr = wg_reguh-zbukr AND
    lifnr = wg_reguh-lifnr AND
    kunnr = wg_reguh-kunnr AND
    empfg = wg_reguh-empfg AND
    vblnr = wg_reguh-vblnr.

    * Dados para preencher a tabela do smartforms
    MOVE: wg_regup-lifnr TO wg_saida-lifnr, ” N° fornecedor
    wg_regup-xblnr TO wg_saida-xblnr, ” N° da NFe
    wg_regup-dmbtr TO wg_saida-dmbtr, ” Valor
    wg_reguh-zaldt TO wg_saida-zaldt. ” Dt. pagamento

    vl_total = wg_saida-dmbtr + vl_total.

    APPEND wg_saida TO tg_saida.

    ENDLOOP.

    SORT tg_saida BY xblnr zaldt.

    IF tg_saida IS NOT INITIAL.

    CLEAR wg_saida.
    wg_saida-lifnr = ‘TOTAL’.
    wg_saida-dmbtr = vl_total.
    APPEND wg_saida TO tg_saida.

    ENDIF.

    * Trata Destinatários
    PERFORM trata_destinatario.

    * Chama smartforms e dispara o email
    PERFORM smartforms.

    ENDLOOP.

    ENDFORM. ” ABASTECE_EMAIL

    *&———————————————————————*
    *& Form TRATA_DESTINATARIO
    *&———————————————————————*
    FORM trata_destinatario .

    SORT tg_lfa1 BY lifnr adrnr.
    SORT tg_adr6 BY addrnumber.

    REFRESH: tg_reclist.
    CLEAR: wg_reclist.

    CLEAR: wg_lfa1.
    READ TABLE tg_lfa1 INTO wg_lfa1 WITH KEY lifnr = wg_reguh-lifnr
    BINARY SEARCH.

    CLEAR: wg_adr6.
    READ TABLE tg_adr6 INTO wg_adr6 WITH KEY addrnumber = wg_lfa1-adrnr
    BINARY SEARCH.

    IF sy-subrc IS INITIAL.

    LOOP AT tg_adr6 INTO wg_adr6 FROM sy-tabix.

    IF wg_adr6-addrnumber wg_lfa1-adrnr.
    EXIT.
    ENDIF.
    wg_reclist-receiver = vl_smtp_to = wg_adr6-smtp_addr.
    wg_reclist-rec_type = c_u.
    * wg_reclist-express = c_x.
    APPEND wg_reclist TO tg_reclist.
    ENDLOOP.
    ENDIF.

    ENDFORM. ” TRATA_DESTINATARIO

    *&———————————————————————*
    *& Form SMARTFORMS
    *&———————————————————————*
    FORM smartforms .

    DATA: wl_fmname TYPE rs38l_fnam,
    wl_return TYPE ssfcrescl.

    DATA: vl_msg1 TYPE string,
    vl_msg2 TYPE string.

    * Pegar nome do programa de formulário
    CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME’
    EXPORTING
    formname = ‘ZFI001’
    IMPORTING
    fm_name = wl_fmname
    EXCEPTIONS
    no_form = 1
    no_function_module = 2
    OTHERS = 3.

    IF sy-subrc = 0.

    ENDIF.

    IF tg_saida IS NOT INITIAL.

    PERFORM preencher_control.

    *** Chama a função do Smartforms ***
    CALL FUNCTION wl_fmname
    EXPORTING
    user_settings = c_x
    t_dados = tg_saida
    name1 = wg_saida2-name1
    datapag = wg_saida2-zaldt
    control_parameters = wg_control
    IMPORTING
    job_output_info = wl_return
    EXCEPTIONS
    formatting_error = 1
    internal_error = 2
    send_error = 3
    user_canceled = 4
    OTHERS = 5.

    i_otf[] = wl_return-otfdata[].

    *** CONVERT PARA PDF ***
    CALL FUNCTION ‘CONVERT_OTF’
    EXPORTING
    format = ‘PDF’
    max_linewidth = 132
    IMPORTING
    bin_filesize = vl_len_in
    TABLES
    otf = i_otf
    lines = i_tline
    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.

    *SX_TABLE_LINE_WIDTH_CHANGE use :-faça de cada linha 255 caracteres
    CALL FUNCTION ‘SX_TABLE_LINE_WIDTH_CHANGE’
    TABLES
    content_in = i_tline
    content_out = i_tline2
    EXCEPTIONS
    err_line_width_src_too_long = 1
    err_line_width_dst_too_long = 2
    err_conv_failed = 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.

    IF tg_reclist IS NOT INITIAL.

    PERFORM corpo_email.

    CALL FUNCTION ‘SO_NEW_DOCUMENT_ATT_SEND_API1’
    EXPORTING
    document_data = wg_doc_chng
    put_in_outbox = c_x
    TABLES
    packing_list = tg_objpack
    object_header = wg_objhead
    contents_bin = tg_objbin
    contents_txt = tg_objtxt
    receivers = tg_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.

    vl_msg1 = text-010. “‘Email enviado com sucesso.’.

    ***Mensagem de sucesso
    CLEAR: wg_relatorio.
    MOVE: icon_system_okay TO wg_relatorio-status,
    vl_msg1 TO wg_relatorio-msg,
    wg_regup-lifnr TO wg_relatorio-lifnr,
    wg_reguh-name1 TO wg_relatorio-name1.

    APPEND wg_relatorio TO tg_relatorio.

    ENDIF.

    ELSE.

    vl_msg2 = text-011. “‘Campo email do Fornecedor não atualizado.’.

    **Mensagem de erro
    CLEAR: wg_relatorio.
    MOVE: icon_system_cancel TO wg_relatorio-status,
    vl_msg2 TO wg_relatorio-msg,
    wg_regup-lifnr TO wg_relatorio-lifnr,
    wg_reguh-name1 TO wg_relatorio-name1.

    APPEND wg_relatorio TO tg_relatorio.

    ENDIF.

    ENDIF.

    ENDFORM. ” SMARTFORMS

    *&———————————————————————*
    *& Form PREENCHER_OUTPUT
    *&———————————————————————*
    FORM preencher_control .

    * wg_control-device = ‘LOCL’.
    wg_control-no_dialog = c_x.
    * wg_control-preview = c_x.
    wg_control-getotf = c_x.
    wg_control-langu = sy-langu.

    ENDFORM. ” PREENCHER_OUTPUT

    *&———————————————————————*
    *& Form CORPO_EMAIL
    *&———————————————————————*

    DATA: vl_assunto TYPE string.
    DATA: vl_msg TYPE string.
    DATA: vl_data TYPE char10.

    WRITE sy-datum TO vl_data DD/MM/YYYY.
    REPLACE ‘.’ WITH ‘/’ INTO vl_data.
    REPLACE ‘.’ WITH ‘/’ INTO vl_data.

    vl_assunto = text-008.

    CONCATENATE: text-007 vl_data
    INTO vl_msg SEPARATED BY space.

    * Attachment
    REFRESH: tg_objtxt,
    tg_objbin,
    tg_objpack.
    CLEAR wg_objhead.

    tg_objbin[] = i_tline2[].

    * Mensagem no corpo do email
    wg_objtxt = vl_msg.
    APPEND wg_objtxt TO tg_objtxt.

    DESCRIBE TABLE tg_objtxt LINES vg_lines_txt.
    READ TABLE tg_objtxt INTO wg_objtxt INDEX vg_lines_txt.
    wg_doc_chng-obj_name = vl_assunto.
    wg_doc_chng-expiry_dat = sy-datum + 10.
    wg_doc_chng-obj_descr = vl_assunto.
    wg_doc_chng-doc_size = vg_lines_txt * 255.

    * Main Text
    CLEAR wg_objpack-transf_bin.
    wg_objpack-head_start = 1.
    wg_objpack-head_num = 0.
    wg_objpack-body_start = 1.
    wg_objpack-body_num = vg_lines_txt.
    wg_objpack-doc_type = ‘RAW’.
    APPEND wg_objpack TO tg_objpack.

    * Attachment (pdf-Attachment)
    wg_objpack-transf_bin = ‘X’.
    wg_objpack-head_start = 1.
    wg_objpack-head_num = 0.
    wg_objpack-body_start = 1.

    * Anexo do smart forms em pdf
    DESCRIBE TABLE tg_objbin LINES vg_lines_bin.
    READ TABLE tg_objbin INTO wg_objbin INDEX vg_lines_bin.
    wg_objpack-doc_size = vg_lines_bin * 255 .
    wg_objpack-body_num = vg_lines_bin.
    wg_objpack-doc_type = ‘PDF’.
    wg_objpack-obj_name = vl_assunto.
    wg_objpack-obj_descr = vl_assunto.
    APPEND wg_objpack TO tg_objpack.

    * wg_objpack-transf_bin = space.
    * wg_objpack-head_start = 000000000000001.
    * wg_objpack-head_num = 000000000000001.
    * wg_objpack-body_start = 000000000000002.
    * wg_objpack-body_num = 000000000000010.
    * wg_objpack-doc_type = ‘RAW’.
    * APPEND wg_objpack TO tg_objpack.

    ENDFORM. ” CORPO_EMAIL

    *&———————————————————————*
    *& Form RELATORIO
    *&———————————————————————*
    FORM relatorio .

    * Prepar o fieldcat
    PERFORM criar_fieldcat.

    * Imprimi Relatório
    PERFORM imprimir_relatorio.

    ENDFORM. ” RELATORIO

    *&———————————————————————*
    *& Form CRIAR_FIELDCAT
    *&———————————————————————*
    FORM criar_fieldcat .

    CLEAR: vg_colpos.

    * Status
    PERFORM preenche_fieldcat USING c_status
    c_status
    c_status
    text-005
    c_l
    space
    space
    space
    c_10
    space.

    * Cód do Fornecedor
    PERFORM preenche_fieldcat USING c_lifnr
    c_lifnr
    c_regup
    text-002
    c_l
    space
    space
    space
    c_10
    space.

    * Nome do Fornecedor
    PERFORM preenche_fieldcat USING c_name1
    c_name1
    c_reguh
    text-003
    c_l
    space
    space
    space
    c_35
    space.

    * Msg do Sistema
    PERFORM preenche_fieldcat USING c_msg
    c_msg
    c_string
    text-004
    c_l
    space
    space
    space
    c_30
    space.

    ENDFORM. ” CRIAR_FIELDCAT
    *&———————————————————————*
    *& Form PREENCHE_FIELDCAT
    *&———————————————————————*
    * text
    *———————————————————————-*
    * –>P_C_NAME1 text
    * –>P_C_NAME1 text
    * –>P_C_REGUH text
    * –>P_TEXT_003 text
    * –>P_C_L text
    * –>P_SPACE text
    * –>P_SPACE text
    * –>P_SPACE text
    * –>P_C_4 text
    * –>P_SPACE text
    *———————————————————————-*
    FORM preenche_fieldcat USING p_fieldname
    p_ref_fieldname
    p_ref_tabname
    seltext_l
    p_ddictxt
    p_key
    p_do_sum
    p_no_out
    p_outputlen
    p_inttype.

    ADD 1 TO vg_colpos.

    CLEAR: wg_fieldcat.

    wg_fieldcat-fieldname = p_fieldname.
    wg_fieldcat-ref_fieldname = p_ref_fieldname.
    wg_fieldcat-ref_tabname = p_ref_tabname.
    wg_fieldcat-seltext_l = seltext_l.
    wg_fieldcat-ddictxt = p_ddictxt.
    wg_fieldcat-key = p_key.
    wg_fieldcat-col_pos = vg_colpos.
    wg_fieldcat-do_sum = p_do_sum.
    wg_fieldcat-no_out = p_no_out.
    wg_fieldcat-outputlen = p_outputlen.
    wg_fieldcat-inttype = p_inttype.

    APPEND wg_fieldcat TO tg_fieldcat.

    ENDFORM. ” PREENCHE_FIELDCAT

    *&———————————————————————*
    *& Form IMPRIMIR_RELATORIO
    *&———————————————————————*

    FORM imprimir_relatorio .

    DATA: wl_slis TYPE slis_layout_alv,
    wl_variant TYPE disvariant.

    * Opções do ALV
    CLEAR: wl_slis,
    wl_variant.

    wl_slis-zebra = c_x.
    wl_slis-numc_sum = c_x.
    wl_slis-colwidth_optimize = c_x.
    wl_slis-totals_text = c_x.
    wl_slis-subtotals_text = c_x.
    wl_slis-coltab_fieldname = c_tabcolor.

    wl_variant-variant = ‘/STD’.

    CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
    EXPORTING
    i_callback_program = ‘ZFIR016’
    * i_callback_top_of_page = ‘GERA_CABECALHO’
    i_callback_user_command = ‘USER_COMMAND’
    it_fieldcat = tg_fieldcat[]
    * it_sort = tg_sort[]
    it_events = tg_events[]
    is_layout = wl_slis
    is_variant = wl_variant
    i_save = c_x
    TABLES
    t_outtab = tg_relatorio
    EXCEPTIONS
    program_error = 1
    OTHERS = 2.

    ENDFORM. ” IMPRIMIR_RELATORIO

    *Text elements
    *———————————————————-
    * 001 Parâmetros de Seleção
    * 002 Número do Fornecedor
    * 003 Nome do Fornecedor
    * 004 Mensagem do Sistema
    * 005 Status
    * 006 Informativo de Pagamento Dicico
    * 007 Segue em anexo faturas liquidadas pela empresa Dicico na data de
    * 008 Informativo de Pagamento Dicico
    * 010 Email enviado com sucesso.
    * 011 Campo email do Fornecedor não atualizado.
    * E01 Não existem dados para o Critério de Seleção
    * E02 Data não pode ser futura.
    * E03 Campo email do Fornecedor não atualizado.

    *Selection texts
    *———————————————————-
    * P_LAUFD Dia de Execução
    * P_LAUFI Identificação
    * S_LIFNR Código do Fornecedor

    *Messages
    *———————————————————-
    *
    * Message class: 00
    *208 &

    ———————————————————————————-
    Extracted by Direct Download Enterprise version 1.3.1 – E.G.Mellodew. 1998-2005 UK. Sap Release 700

  5. Bruno Esperança Diz:

    Acho difícil expressar por palavras a minha gratidão.

    Não obstante, tenho uma sugestão para esta nova modalidade da partilha de código. Que tal em vez de usar a velha modalidade da “partilha” de código, que implica a partilha do código “em esparguete”, como lhe chamava o meu caro colega Zé Nascimento, fazer apenas uma boa descrição do programa e partilhá-lo em nuggets?

    Abraço.

  6. admin Diz:

    Olá Bruno,
    Realmente quando meti aqui o código considerei nuggets e gist (http://gist.github.com) mas acabei por ainda não me decidir por nenhum. Mas acho que tens razão e vou começar a meter nuggets no Abapinho.

  7. Valdevy Pires Diz:

    Lucas, vc nos disponibilizou o código do programa que dispara e-mails para o fornecedor após a fatura ser paga. Achei muito legal, porém, faltou nos passar também a estrutura da tabela zfict013. Poderia encaminhar, por favor?

    Obrigado.

  8. amar Diz:

    How to email report : RSSHOWRABAX using this program?

  9. erica Diz:

    Ola, é possivel enviar spool em html por email com mais de 1 pagina?
    tenho relatorios que sao de mais de 100 paginas que precisamos enviar por email e nao estamos conseguindo – so conseguimos schedular com 1 pagina por email html

  10. Nuno Godinho Diz:

    Não sei, nunca experimentei, mas é estranho que não dê. Se descobrires diz.

Deixe um comentário


About Abapinho
Abapinho runs on WordPress
Articles (RSS) e Comments (RSS).