Skip to Content
0
May 22, 2014 at 08:25 PM

How to send an ALV to Spool

3480 Views

Dear all,

Could you please help, my requirement is to send an ALV report as a PDF attachement to a list of email address. My plan is to send the ALV to spool and read it from there and email it. However I have a problem in as much as the ALV is not being sent to spool, furthermore I also get print dialog popup when running the report. Can you please help, i am using CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY and CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF' I have browsed here and there are several questions on this topic but they do not address the issue of sending the file to the spool. The partial code is below

DATA:i_t001 TYPE t001 OCCURS 0,

pdf LIKE tline OCCURS 0,

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.

PARAMETERS: p_file TYPE string.

INITIALIZATION.

p_file = 'H:\TEST_gh.pdf'.

START-OF-SELECTION.

rp-def-time-period.

help1 = behrs DIV 24.

bdate = ldate - help1.

help1 = behrs MOD 24.

help2 = ltime(2) - help1.

IF help2 LT 0.

bdate = bdate - 1.

btime = ltime.

btime(2) = 24 + help2.

ELSE.

btime = ltime.

btime(2) = help2.

ENDIF.

pn-begps = ldate - 1.

pn-endps = ldate.

GET pernr.

loop at p0007 where begda le ldate and endda ge ldate. "

endloop.

* überprüft Arbeitszeitplanregel

* CHECK schkz.

CHECK p0007-schkz IN schkz.

CHECK p0007-zterf IN zterf.

CALL FUNCTION 'HR_SEL_STAT_CHECK'

EXPORTING

get_pernr = pernr-pernr

get_ldate = ldate

get_bdate = bdate

get_btime = btime

get_psp_flag = psp_flag

get_ltime = ltime

* IMPORTING

* NO_PERMIT =

TABLES

get_p0000 = p0000

get_p0001 = p0001

get_p0002 = p0002

get_p0050 = p0050

get_p0007 = p0007

data_tab = data_tab.

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

* End-of-Selection *

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

END-OF-SELECTION.

loop at data_tab into ls_data_tab.

ls_data_tab-total_records = '1'.

ls_data_tab-kostl = p0001-kostl.

Append ls_data_tab to lt_data_tab.

endloop.

DESCRIBE TABLE data_tab LINES lines.

CALL FUNCTION 'HR_GET_ERROR_LIST'

TABLES

error = errors

errortexts = errortexts

EXCEPTIONS

no_errors = 1

OTHERS = 2.

IF lines EQ 0 AND sy-subrc EQ 1.

MESSAGE i050.

STOP.

ENDIF.

LOOP AT errors.

READ TABLE data_tab WITH KEY errors-pernr.

IF sy-subrc EQ 0.

DELETE data_tab INDEX sy-tabix.

ENDIF.

ENDLOOP.

g_repid = sy-repid.

* fill field catalog for output

PERFORM fill_fcat USING fcat

g_repid.

* Listheader

PERFORM fill_header USING header_alv_wa

header_alv.

FIELD-SYMBOLS <lwa_fcat> like line of fcat.

LOOP AT fcat ASSIGNING <lwa_fcat>.

IF <lwa_fcat>-fieldname = 'TOTAL_RECORDS'.

<lwa_fcat>-do_sum = 'X'.

ENDIF.

ENDLOOP.

*Right, sort the table and produce sub totals

wa_sort-spos = 18.

wa_sort-fieldname = 'KOSTL'.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

append wa_sort to it_sort.

* Layout for REUSE_ALV_GRID_DISPLAY

s_layout-colwidth_optimize = 'X'.

s_layout-zebra = 'X'.

s_layout-no_author = 'X'.

w_print-print = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = g_repid

" i_callback_pf_status_set = 'SET_PF_STATUS'

i_callback_user_command = 'USER_COMMAND'

i_callback_top_of_page = 'TOP_OF_PAGE'

is_layout = s_layout

it_fieldcat = fcat

it_sort = it_sort

i_save = 'A'

i_structure_name = MY_STRUCTURE'

is_print = w_print

TABLES

t_outtab = lt_data_tab

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ELSE.

***=====================================================================*

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_repid

" i_callback_pf_status_set = 'SET_PF_STATUS'

i_callback_user_command = 'USER_COMMAND'

i_callback_top_of_page = 'TOP_OF_PAGE'

is_layout = s_layout

it_fieldcat = fcat

it_sort = it_sort

i_save = 'A'

i_structure_name = MY_STRUCTURE'

TABLES

t_outtab = lt_data_tab

EXCEPTIONS

program_error = 1.

ENDIF.

endif.

endif.