Skip to Content
0
Former Member
Aug 02, 2016 at 06:15 AM

Download ALV out to pdf file I place a pdf icon in the ouput section once user click the icon output is to be download in pdf in landscape format.

836 Views

Hi all,


I try to download the ALV out to pdf file I place a pdf icon in the ouput section once user click that icon it has to download the pdf in landscape format. Once user click on pdf button I am calling the below code. My problem is I am able to download the PDF but if try to open the pdf it is giving error as no pages (Once the program got executed it is showing 1340 bytes got transfered).


* Tables

DATA:

lt_pdf TYPE tlinetab,

lt_slopt TYPE STANDARD TABLE OF rsparams.

* Strectures

DATA:

ls_params TYPE pri_params.

* Variables

DATA:

lv_filename TYPE string,

lv_path TYPE string,

lv_fullpath TYPE string,

lv_user_action TYPE i,

lv_spool TYPE tsp01-rqident,

lv_pdf_bytecount TYPE i,

lv_device TYPE tsp03-padest VALUE 'LP01' .

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

DATA: lv_file TYPE string,

ev_xstring TYPE xstring,

lt_binary TYPE solix_tab.

IF lv_ucomm EQ '%PDF'.

* for change the file name and extension file to PDF

CALL METHOD cl_gui_frontend_services=>file_save_dialog

EXPORTING

default_file_name = '*.pdf'

file_filter = '*.pdf'

CHANGING

filename = lv_filename

path = lv_path

fullpath = lv_fullpath

user_action = lv_user_action

EXCEPTIONS

cntl_error = 1

error_no_gui = 2

not_supported_by_gui = 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 button cancel not clicked then download pdf.

IF lv_user_action <> '9'.

* Get parameters from select option

CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'

EXPORTING

curr_report = sy-repid

TABLES

selection_table = lt_slopt.

* Get print parameters

CALL FUNCTION 'GET_PRINT_PARAMETERS'

EXPORTING

destination = 'LP01'

immediately = ' '

line_count = '65'

line_size = '255'

no_dialog = abap_true

cover_page = ''

IMPORTING

out_parameters = ls_params.

* Submit the transcation to spool

SUBMIT zrhr_sa_wage_type_reporter WITH SELECTION-TABLE lt_slopt

TO SAP-SPOOL

SPOOL PARAMETERS ls_params

WITHOUT SPOOL DYNPRO

AND RETURN.

* Get created spool number from tsp01

SELECT MAX( rqident )

INTO lv_spool

FROM tsp01

WHERE rqclient = sy-mandt

AND rqowner = sy-uname.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = lv_spool

no_dialog = space

IMPORTING

pdf_bytecount = lv_pdf_bytecount

TABLES

pdf = lt_pdf

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.

IF sy-subrc <> 0.

* Implement suitable error handling here

ENDIF.

* Download to local

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

bin_filesize = lv_pdf_bytecount

filename = lv_fullpath

filetype = 'BIN'

TABLES

data_tab = lt_pdf. "lt_binary.

ENDIF.

ENDIF.