Sending the Multiple ALVs as PDF Attachment through Email

By Bhawna Khosla, IBM India

Brief Requirement Overview:  

In this document, an email, with the PDF attachment of 3 ALV outputs, will be send to the Email addresses of multiple persons or single person as required. The principle is to print ALVs to spool directly, convert spool to PDF, and send the PDF to email. It can be used in background as well as in foreground. The program must be executed in background to generate the spool request.

Scenario:

The program will display 3 ALV grids using Custom containers in foreground and will use FM REUSE_ALV_BLOCK_LIST_APPEND to generate spool. When the program is executed in foreground, the three ALV grids will be displayed and an email with PDF attachment of the ALV outputs will be send .When the program is executed in background, spool request will be generated containing the 3 ALV outputs and an email with PDF attachment of the ALV outputs will be send.

Challenge:

The challenge in this scenario is, the 3 ALV grids built using OOPS concept cannot be sent to Spool directly in foreground. For sending the 3 ALV grids to spool, FM REUSE_ALV_BLOCK_LIST_APPEND has been used. The foreground mode uses both the normal ALV grid display methods of OOPS to display the three ALVs in foreground and then uses REUSE_ALV_BLOCK_LIST_APPEND FM to send the report to spool as list. The background mode uses only REUSE_ALV_BLOCK_LIST_APPEND to send the report to spool.

Step1:    Creating screen for foreground display

Go to Screen painter Transaction Code SE51.

Create a screen with no 100.

Provide description for the screen and click on the Layout Button.

Place 3 Custom container UI elements and give names as ‘G_CONTAINER1’ , ‘G_CONTAINER2’ and ‘G_CONTAINER3’ .The screen 100 will have 3 custom containers as shown below. Activate the Object.  

Step 2: Flow Logic

Go to the Flow Logic Tab to write coding for PBO & PAI.

Step3:  ABAP Editor

Create a Z program with the code as below:

The three internal tables for 3 ALVs are: I_ORDERS1, I_ORDERS2 and I_INVSTATUS.

The three field catalogs are built and the field catalog names are: I_FIELDCATALOG1, I_FIELDCATALOG2 and I_FIELDCATALOG3.

*&---------------------------------------------------------------------*
*&      Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.

* PF status of the screen
  PERFORM sub_pf_status.
*  Set the title of report
  SET TITLEBAR 'TTL'.

* Display ALV Data
  PERFORM sub_display_firstalv  USING  i_fieldcatalog1
                                       i_orders1.

  PERFORM sub_display_secondalv USING  i_fieldcatalog2
                                       i_orders2.

  PERFORM sub_display_thirdalv  USING  i_fieldcatalog3
                                       i_invstatus.
* Send email to customers
  PERFORM sub_send_mail.

*    Refresh the first display table
  CALL METHOD g_grid1->refresh_table_display
    EXCEPTIONS
      finished = 1
      OTHERS   = 2.

*    Refresh the second display table
  CALL METHOD g_grid2->refresh_table_display
    EXCEPTIONS
      finished = 1
      OTHERS   = 2.

*    Refresh the third display table
  CALL METHOD g_grid3->refresh_table_display
    EXCEPTIONS
      finished = 1
      OTHERS   = 2.

ENDMODULE.                 " STATUS_0100  OUTPUT

Subroutine to set the PF Status of the report

*&---------------------------------------------------------------------*
*&      Form sub_pf_status
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM sub_pf_status.

* Local data declaration
  DATA: lt_excl TYPE ty_t_excl.

*Set PF status
  SET PF-STATUS 'ZSTATUS_0100' EXCLUDING lt_excl.
ENDFORM.                    “SUB_PF_STATUS

Subroutine to Display First ALV

*&---------------------------------------------------------------------*
*&      Form  SUB_DISPLAY_FIRSTALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_FIELDCATALOG1  text
*      -->P_I_ORDERS1  text
*----------------------------------------------------------------------*
FORM sub_display_firstalv  USING    fp_i_fieldcatalog1 TYPE lvc_t_fcat
                                    fp_i_orders1     TYPE ty_t_orders1.

  DATA:      lx_print TYPE lvc_s_prnt.

* Local data declaration
  DATA: li_layout TYPE lvc_s_layo.

* Layout for ALV
  PERFORM sub_prepare_layout USING c_x
                                   text-011
                                   c_x
                                   c_cellstyle
                          CHANGING li_layout.
* Use Flush
  CALL METHOD cl_gui_cfw=>flush.

  IF g_custom_container1 IS INITIAL.       "To ensure that object is created only once

    CREATE OBJECT g_custom_container1
      EXPORTING
        container_name = 'G_CONTAINER1'.

* Splitting the container
    CREATE OBJECT g_split
      EXPORTING
        parent        = g_custom_container1
        sash_position = 50 "Position of Splitter Bar (in Percent)
        with_border   = 0.”With Border = 1 Without Border = 0

* Placing the containers in the splitter
    g_top_container = g_split->top_left_container.
    g_bottom_container = g_split->bottom_right_container.

*     Create an instance of ALV control
    CREATE OBJECT g_grid1
      EXPORTING
        i_parent = g_bottom_container.


*   Creating the document
    CREATE OBJECT g_document
      EXPORTING
        style = 'ALV_GRID'.

*Top of page
    PERFORM sub_top_of_page.

    CALL METHOD g_grid1->set_table_for_first_display
      EXPORTING
        it_toolbar_excluding          = i_exclude
        is_layout                     = li_layout
        is_print                      = lx_print
      CHANGING
        it_outtab                     = fp_i_orders1
        it_fieldcatalog               = fp_i_fieldcatalog1
      EXCEPTIONS
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 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.
  ENDIF.

ENDFORM.                    “SUB_DISPLAY_FIRSTALV

Click here to continue...

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image