07-27-2010 7:50 AM
Hi All,
I have developed an ALV report using SALV (cl_salv_table=>factory) . The requirement is to download the ALV output to PDF.
Inorder to achieve this I will have to write the output to the spool and then convert the spool to PDF.
Please do let me know how the ALV output can be written to spool.
Thanks,
Maansi
07-28-2010 8:16 AM
Hi Maansi,
We had a discussion on extracting spool no here
Regards
Marcin
07-27-2010 8:58 AM
This works excatly the same as with OO ALV in background. To export its content to spool in ABAP List format you need to pass empty docking container as parent
DATA: r_dock TYPE REF TO cl_gui_docking_container,
r_salv TYPE REF TO cl_salv_table.
DATA: it_sflight TYPE TABLE OF sflight.
INITIALIZATION.
SELECT * FROM sflight INTO TABLE it_sflight UP TO 10 ROWS.
START-OF-SELECTION.
CALL SCREEN 100.
MODULE pbo OUTPUT.
IF sy-batch = 'X'.
"initial docking container as parent
CALL METHOD cl_salv_table=>factory
EXPORTING
r_container = r_dock
IMPORTING
r_salv_table = r_salv
CHANGING
t_table = it_sflight.
ENDIF.
r_salv->display( ).
ENDMODULE.
Now pick your spool no and pass it to program RSTXPDFT4 . It will do necessary conversion for you.
Regards
Marcin
07-28-2010 7:29 AM
Hi Marcin,
I did it as mentioned by you, but the spool number is not getting populated. here is my code:
DATA: gr_dock TYPE REF TO cl_gui_docking_container.
TRY.
CALL METHOD cl_salv_table=>factory
EXPORTING
r_container = gr_dock
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = xt_output.
CATCH cx_salv_msg. "#EC NO_HANDLER
ENDTRY.
..........
gr_table->display( ).
g_spool = sy-spono. " Here the spool number is '0'.
Please let me knw how can I get the spool number.
Thanks,
Maansi.
07-27-2010 9:04 AM
Hi Maansi,
Get the Spool request id from tsp01 using the user id and client
Pass the Spool id to the FM: CONVERT_ABAPSPOOLJOB_2_PDF
Then, Use the function "GUI_DOWNLOAD" to download the generated PDF.
Check the below Link
[http://www.sapdev.co.uk/reporting/rep_spooltopdf.htm]
Edited by: Raj on Jul 27, 2010 1:37 PM
07-28-2010 7:44 AM
07-28-2010 8:16 AM
Hi Maansi,
We had a discussion on extracting spool no here
Regards
Marcin
07-28-2010 8:42 AM
Hi Marcin,
Thansk for your reply. I still am not able to retrieve the spool number. I used COMMIT WORk and even tried with FM GET_PRINT_PARAMETERS it doesnt seem to help. I chekced in table TSP01 but it doesnt seem to have generated any spool,.
Kindly help me in this regard.
Thanks,
Maansi
07-28-2010 9:06 AM
It's working fine for me. After running the program go to SM37 and click on SPOOL output -> get that spool no -> go to SE16N and type table TSP01 -> pass it on input and make sure there is corresponding entry in the table (must be there).
So in your program you get the lastest entry after SALV->display with
SELECT MAX( rqident ) INTO g_spool FROM tsp01
WHERE rqclient = sy-mandt
AND rqowner = sy-uname.
Now as you have the latest spool no in g_spool you can pass it to the aforemenitoned program. This however will not work in the background as you have GUI interaction in that program. So you need your own coding for dowloading this spool result to pdf -> then to external file.
Raj has already gave you the necessary FMs to use, you can also refer this downloading program as it uses the same technique.
Regards
Marcin
07-29-2010 8:22 AM
Hi Marcin,
My requirement is that I need to display a report in ALV grid format and on click of a button in application tool bar, the PDF download should happen. When I try to directly download the PDF without displaying the ALV it works, but on click of the button, the spool number is '0'. Below is my code.I have split my code in two different posts as I cannot paste teh entire code here.
TYPES:
t_pripar TYPE pri_params,
t_arcpar TYPE arc_params.
DATA: ispfli TYPE TABLE OF spfli.
DATA: xspfli TYPE spfli.
DATA: gr_table TYPE REF TO cl_salv_table.
DATA: gr_events TYPE REF TO cl_salv_events_table.
DATA: gr_selections TYPE REF TO cl_salv_selections,
r_dock TYPE REF TO cl_gui_docking_container.
DATA : iv_file TYPE string VALUE 'C:\test.pdf'.
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.
DATA:
gw_valid TYPE c,
lw_print_ctrl TYPE alv_s_pctl ,
lo_print TYPE REF TO cl_salv_print,
gw_pparams TYPE t_pripar.
*---------------------------------------------------------
* CLASS lcl_handle_events DEFINITION
*---------------------------------------------------------
CLASS lcl_handle_events DEFINITION.
PUBLIC SECTION.
METHODS:
on_user_command FOR EVENT added_function OF cl_salv_events IMPORTING e_salv_function.
ENDCLASS. "lcl_handle_events DEFINITION
DATA: event_handler TYPE REF TO lcl_handle_events.
*start-of-selection.
SELECT * INTO CORRESPONDING FIELDS OF TABLE ispfli FROM spfli UP TO 100 ROWS.
CALL METHOD cl_salv_table=>factory
* EXPORTING
* r_container = r_dock
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = ispfli.
gr_table->set_screen_status( pfstatus = 'SALV_TABLE_STANDARD'
report = sy-repid set_functions = gr_table->c_functions_all ).
gr_events = gr_table->get_event( ).
CREATE OBJECT event_handler.
SET HANDLER event_handler->on_user_command FOR gr_events.
* Set up selections.
gr_selections = gr_table->get_selections( ).
gr_selections->set_selection_mode( 1 ). "Single
* Display
gr_table->display( ).
07-29-2010 8:22 AM
* CLASS lcl_handle_events IMPLEMENTATION
CLASS lcl_handle_events IMPLEMENTATION.
METHOD on_user_command.
DATA: lr_selections TYPE REF TO cl_salv_selections.
DATA: lt_rows TYPE salv_t_row.
DATA: ls_rows TYPE i.
DATA: message TYPE string.
TYPES:
t_pripar TYPE pri_params,
t_arcpar TYPE arc_params.
DATA:
gw_valid TYPE c,
lw_print_ctrl TYPE alv_s_pctl ,
lo_print TYPE REF TO cl_salv_print,
gw_pparams TYPE t_pripar,
g_spool TYPE tsp01-rqident.
lo_print = gr_table->get_print( ).
* Get the selection rows
lr_selections = gr_table->get_selections( ).
lt_rows = lr_selections->get_selected_rows( ).
CASE e_salv_function.
WHEN 'PDF'.
MESSAGE 'test' TYPE 'I'.
/ get print parameters
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
no_dialog = 'X'
IMPORTING
valid = gw_valid
out_parameters = gw_pparams
EXCEPTIONS
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
OTHERS = 4.
CONCATENATE 'test' sy-datum sy-uzeit INTO gw_pparams-prtxt SEPARATED BY space.
lw_print_ctrl = lo_print->get_print_control( ).
lw_print_ctrl-pri_params = gw_pparams.
lo_print->set_print_control( lw_print_ctrl ).
lo_print->set_print_only( if_salv_c_bool_sap=>true ).
gr_table->display( ).
g_spool = sy-spono.
MESSAGE sy-spono TYPE 'I'.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = g_spool
TABLES
pdf = 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.
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 = iv_file
filetype = 'BIN'
TABLES
data_tab = pdf
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
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.
ENDCASE.
ENDMETHOD. "on_user_command
ENDCLASS. "lcl_handle_events IMPLEMENTATION
07-30-2010 8:23 AM
Hi Maansi,
I was thinking a while about your issue. It seems that when you call method set_print_only outside method handler your ALV is send to spool, otherwise (when called within that method) it doesn't even seem to execute "print" command, so the spool is never generated. The problem in first solution is that just right after calling set_print_only you are not able to do any further processing (the program simply doesn't reach next statement), so you are not able to download your spool to PDF afterwards.
Anyhow I found different solution. See below
"let's say your program calls Z_ALV_PRINT.
...
METHOD on_user_command.
...
CASE e_salv_function.
WHEN 'PDF'.
"when PDF button pressed, set flag in ABAP memory requesting print command
EXPORT flag = 'X' TO MEMORY ID 'DO_PRINT'.
"and submit your report again to perfrom just PRINT
SUBMIT Z_ALV_PRINT AND RETURN.
"here the processing is back after the print has been send to spool,
"now you are able to select latest spool entry to get that number
SELECT MAX( rqident ) INTO g_spool FROM tsp01
WHERE rqclient = sy-mandt
AND rqowner = sy-uname.
"...here download to PDF
ENDCASE.
ENDMETHOD.
ENDCLASS.
"normaly report will display ALV on screen, but when submited with flag set
"it will do a print to spool instead
START-OF-SELECTION.
SELECT * INTO CORRESPONDING FIELDS OF TABLE ispfli FROM spfli UP TO 100 ROWS.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = ispfli.
gr_table->set_screen_status( pfstatus = 'SALV_TABLE_STANDARD'
...
"now import flag from ABAP memory and see if print requested,
"if so do a print, not a table display
DATA: g_flag TYPE c.
IMPORT flag = g_flag FROM MEMORY ID 'DO_PRINT'.
IF g_flag = 'X'.
lo_print = gr_table->get_print( ).
" get print parameters
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
no_dialog = 'X'
IMPORTING
valid = gw_valid
out_parameters = gw_pparams
EXCEPTIONS
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
OTHERS = 4.
CONCATENATE 'test' sy-datum sy-uzeit INTO gw_pparams-prtxt SEPARATED BY space.
lw_print_ctrl = lo_print->get_print_control( ).
lw_print_ctrl-pri_params = gw_pparams.
lo_print->set_print_control( lw_print_ctrl ).
lo_print->set_print_only( if_salv_c_bool_sap=>true ).
"free the flag in memory
FREE MEMORY ID 'DO_PRINT'.
ENDIF.
gr_table->display( ).
As descirbed in the comments: normally report will show ALV display, but when flag is set the print to spool will be done.
So in fact you are executing the print in "fly" and when you back from the print program you can get latest spool no and use that one to download the results to pdf.
Works fine, tested
Regards
Marcin