Sunday, December 26, 2010
The below sample program is used to convert classical report output to PDF and zips the PDF and downloads Zip file using GUI_DOWNLOAD function module.
Similar
REPORT ztest_notepad. *&-------------------------------------------------------------------------* *& Declarations *&-------------------------------------------------------------------------* DATA:g_val TYPE c. DATA:w_pripar TYPE pri_params. DATA:w_arcpar TYPE arc_params. DATA:input_length TYPE i. DATA:content_x TYPE xstring. DATA:content_s TYPE string. DATA:spool_no LIKE tsp01-rqident. DATA:it_pdf TYPE TABLE OF tline WITH HEADER LINE. DATA:wa_pdf LIKE LINE OF it_pdf. DATA:file_tab TYPE STANDARD TABLE OF solisti1. DATA:bin_file TYPE xstring. DATA:bytecount TYPE i. DATA:zip TYPE xstring. DATA:path_table TYPE TABLE OF char1024. *&-------------------------------------------------------------------------* *& Start of selection *&-------------------------------------------------------------------------* START-OF-SELECTION. CALL FUNCTION 'GET_PRINT_PARAMETERS' EXPORTING in_archive_parameters = w_arcpar in_parameters = w_pripar layout = 'X_65_132' line_count = 65 line_size = 132 no_dialog = 'X' IMPORTING out_archive_parameters = w_arcpar out_parameters = w_pripar valid = g_val. IF g_val NE space AND sy-subrc = 0. w_pripar-prrel = space. w_pripar-primm = space. NEW-PAGE PRINT ON NEW-SECTION PARAMETERS w_pripar ARCHIVE PARAMETERS w_arcpar NO DIALOG. "Output which is gone to spool WRITE:/ 'Output in spool to create zip file 1'. WRITE:/ 'Output in spool to create zip file 2'. WRITE:/ 'Output in spool to create zip file 3'. WRITE:/ 'Output in spool to create zip file 4'. NEW-PAGE PRINT OFF. CALL FUNCTION 'ABAP4_COMMIT_WORK'. ENDIF. IF NOT sy-spono IS INITIAL. "Declarations spool_no = sy-spono. CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF' EXPORTING src_spoolid = spool_no no_dialog = space IMPORTING pdf_bytecount = bytecount TABLES pdf = it_pdf. CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE' EXPORTING line_width_src = 134 line_width_dst = 255 TABLES content_in = it_pdf content_out = file_tab. "create xstring from table CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' EXPORTING input_length = bytecount IMPORTING buffer = content_x TABLES binary_tab = file_tab. "create our zipper object DATA:g_zipper TYPE REF TO cl_abap_zip. DATA:file_name TYPE string VALUE 'Report_output.pdf'. CREATE OBJECT g_zipper. "add file to zip CALL METHOD g_zipper->add EXPORTING name = file_name content = content_x. "save zip CALL METHOD g_zipper->save RECEIVING zip = zip. "convert to table CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' EXPORTING buffer = zip IMPORTING output_length = bytecount TABLES binary_tab = file_tab. "Save the file CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING bin_filesize = bytecount filename = 'C:\data1.zip' filetype = 'BIN' TABLES data_tab = file_tab. ENDIF.
Similar
REPORT ztest_notepad. DATA: g_val TYPE c, w_pripar TYPE pri_params, w_arcpar TYPE arc_params, input_length TYPE i, content_x TYPE xstring, content_s TYPE string, spool_no LIKE tsp01-rqident, it_pdf TYPE TABLE OF tline WITH HEADER LINE, wa_pdf LIKE LINE OF it_pdf, file_tab TYPE STANDARD TABLE OF solisti1, bin_file TYPE xstring, bytecount TYPE i, zip TYPE xstring, path_table TYPE TABLE OF char1024. DATA: BEGIN OF it_t001 OCCURS 0, bukrs TYPE t001-bukrs, butxt TYPE t001-butxt, END OF it_t001. DATA:g_zipper TYPE REF TO cl_abap_zip. DATA:file_name TYPE string VALUE 'Report_output.pdf'. DATA:file_path TYPE string VALUE 'C:\temp\pdf_report.ZIP'. START-OF-SELECTION. PERFORM get_data. PERFORM print_data CHANGING spool_no. PERFORM convert_spool_2_pdf. PERFORM convert_binary_2_xstring. PERFORM zipping_pdf_file. PERFORM download_zip_file. *&---------------------------------------------------------------------* *& Form get_data *&---------------------------------------------------------------------* FORM get_data . SELECT * FROM t001 INTO CORRESPONDING FIELDS OF TABLE it_t001 UP TO 10 ROWS. ENDFORM. " get_data *&---------------------------------------------------------------------* *& Form print_data *&---------------------------------------------------------------------* FORM print_data CHANGING spool_no. CALL FUNCTION 'GET_PRINT_PARAMETERS' EXPORTING in_archive_parameters = w_arcpar in_parameters = w_pripar layout = 'X_65_132' line_count = 65 line_size = 132 no_dialog = 'X' IMPORTING out_archive_parameters = w_arcpar out_parameters = w_pripar valid = g_val. IF g_val NE space AND sy-subrc = 0. w_pripar-prrel = space. w_pripar-primm = space. NEW-PAGE PRINT ON NEW-SECTION PARAMETERS w_pripar ARCHIVE PARAMETERS w_arcpar NO DIALOG. "Output which is gone to spool LOOP AT it_t001. WRITE:/ it_t001. ENDLOOP. NEW-PAGE PRINT OFF. CALL FUNCTION 'ABAP4_COMMIT_WORK'. ENDIF. IF NOT sy-spono IS INITIAL. spool_no = sy-spono. ENDIF. ENDFORM. " print_data *&---------------------------------------------------------------------* *& Form convert_spool_2_pdf *&---------------------------------------------------------------------* FORM convert_spool_2_pdf . CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF' EXPORTING src_spoolid = spool_no no_dialog = space IMPORTING pdf_bytecount = bytecount TABLES pdf = it_pdf. CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE' EXPORTING line_width_src = 134 line_width_dst = 255 TABLES content_in = it_pdf content_out = file_tab. ENDFORM. " convert_spool_2_pdf *&---------------------------------------------------------------------* *& Form convert_binary_2_xstring *&---------------------------------------------------------------------* FORM convert_binary_2_xstring . "create xstring from table CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' EXPORTING input_length = bytecount IMPORTING buffer = content_x TABLES binary_tab = file_tab. ENDFORM. " convert_binary_2_xstring *&---------------------------------------------------------------------* *& Form zipping_pdf_file *&---------------------------------------------------------------------* FORM zipping_pdf_file . "create our zipper object CREATE OBJECT g_zipper. "add file to zip CALL METHOD g_zipper->add EXPORTING name = file_name content = content_x. "save zip CALL METHOD g_zipper->save RECEIVING zip = zip. ENDFORM. " zipping_pdf_file *&---------------------------------------------------------------------* *& Form download_zip_file *&---------------------------------------------------------------------* FORM download_zip_file . "convert to table CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' EXPORTING buffer = zip IMPORTING output_length = bytecount TABLES binary_tab = file_tab. "Save the file CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING bin_filesize = bytecount filename = file_path filetype = 'BIN' TABLES data_tab = file_tab. ENDFORM. " download_zip_file
Followers
Popular Posts
- ABAP - ALV Report example with steps
- ABAP - Step by step tutorial on Smart Forms - Template Node
- ABAP - Sending email with pdf attachment
- SAP Adobe Form - Steps to create simple ADOBE Form and calling it from ABAP Program
- SAP ABAP - CL_ABAP_CHAR_UTILITIES class usage
- ABAP - Multiple value selection from F4 help for SELECT-OPTIONS
- Execute ABAP Report using SUBMIT statement
- ABAP - Select all or Deselect all in ALV or Check box handling in ALV
- Web Dynpro ABAP ALV - ON_CLICK event
- ABAP - Dynamic WHERE clause
0 comments:
Post a Comment
Your useful comments, suggestions are appreciated.Your comments are moderated.