Saturday, December 18, 2010
Set 'X' to IS_PRINT-PRINT to print ALV output to spool and read spool using function module CONVERT_ABAPSPOOLJOB_2_PDF. 

REPORT  zdownload_alvoutput.
*&-----------------------------------------------------------------------*
* Declarations
*&-----------------------------------------------------------------------*
DATA:
      i_t001       TYPE t001 OCCURS 0,
      pdf          LIKE tline OCCURS 0.
DATA:
      g_spool      TYPE tsp01-rqident,
      g_program    TYPE sy-repid VALUE sy-repid.
TYPE-POOLS:slis.
DATA: 
      w_print      TYPE slis_print_alv,
      w_print_ctrl TYPE alv_s_pctl.
*&-----------------------------------------------------------------------*
* Selection-Screen
*&-----------------------------------------------------------------------*
PARAMETERS: p_file TYPE string.

*&-----------------------------------------------------------------------*
* Initialization
*&-----------------------------------------------------------------------*
INITIALIZATION.
  p_file = 'C:\venkat.pdf'.


*&-----------------------------------------------------------------------*
* Start-of-selection
*&-----------------------------------------------------------------------*
START-OF-SELECTION.
  SELECT * FROM t001 INTO TABLE i_t001 UP TO 100 ROWS.
  w_print-print = 'X'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = g_program
      i_structure_name   = 'T001'
      is_print           = w_print
    TABLES
      t_outtab           = i_t001.
  IF sy-subrc EQ 0.
    g_spool = sy-spono.
    CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
      EXPORTING
        src_spoolid = g_spool
      TABLES
        pdf         = pdf.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ELSE.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename = p_file
          filetype = 'BIN'
        TABLES
          data_tab = pdf.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ELSE.
        CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
          EXPORTING
            i_callback_program = g_program
            i_structure_name   = 'T001'
          TABLES
            t_outtab           = i_t001.    "is_print = w_print
      ENDIF.
    ENDIF.

  ENDIF.

2 comments:

  1. this is good , but i want send mail with pdf attachment

    ReplyDelete
  2. Hi,
    When i try to create PDF file with this logic, When i Execute, A pop up window is coming asking for Output Device, Number of Copes etc.. . How can i bypass this pop up screen. Directly output should be saved in PDF without asking any input for Output Device, Number of Copes etc.

    ReplyDelete

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.