Monday, December 20, 2010
REPORT zhrpy_r_download_cluster_rt MESSAGE-ID zhr. *&---------------------------------------------------------------------* *&Declarations *&---------------------------------------------------------------------* *Types TYPES: BEGIN OF t_header, col_01 TYPE string, col_02 TYPE string, col_03 TYPE string, col_04 TYPE string, col_05 TYPE string, col_06 TYPE string, col_07 TYPE string, END OF t_header, BEGIN OF t_data, col_01 TYPE string, col_02 TYPE string, col_03 TYPE string, col_04 TYPE string, col_05 TYPE string, col_06 TYPE string, col_07 TYPE string, END OF t_data, BEGIN OF t_footer, lines TYPE string, END OF t_footer. *Work areas DATA: w_header TYPE t_header, w_data TYPE t_data, w_footer TYPE t_footer. *Internal tables DATA: i_header TYPE STANDARD TABLE OF t_header, i_data TYPE STANDARD TABLE OF t_data, i_footer TYPE STANDARD TABLE OF t_footer. *&---------------------------------------------------------------------* *&Selection-Screen *&---------------------------------------------------------------------* SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-002. PARAMETERS: p_file1 LIKE ibipparms-path. SELECTION-SCREEN END OF BLOCK b1. *&---------------------------------------------------------------------* *&Inintialization *&---------------------------------------------------------------------* INITIALIZATION. PERFORM default_file_path. *&---------------------------------------------------------------------* *&At Selection-screen *&---------------------------------------------------------------------* AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1. PERFORM f4_help_for_file CHANGING p_file1. *&---------------------------------------------------------------------* *&Start of selection *&---------------------------------------------------------------------* START-OF-SELECTION. *Prepare File Header data PERFORM prepare_file_header. *Prepare data to download PERFORM prepare_cd_data. *Prepare footer data PERFORM prepare_file_footer. *&---------------------------------------------------------------------* *&End of selection *&---------------------------------------------------------------------* END-OF-SELECTION. *Down load data into files. PERFORM download_data_into_file. *---------------------------------------------------------------------* * FORM default_file_path * *---------------------------------------------------------------------* FORM default_file_path. CONCATENATE 'C:\TEMP\' 'Excel_with_Header&Footer' sy-datum sy-uzeit+0(2) '.txt' INTO p_file1. ENDFORM. "default_file_path *---------------------------------------------------------------------* * FORM f4_help_for_file * *---------------------------------------------------------------------* FORM f4_help_for_file CHANGING filename. CALL FUNCTION 'F4_FILENAME' EXPORTING program_name = syst-cprog dynpro_number = syst-dynnr field_name = 'P_FILE' IMPORTING file_name = filename. . ENDFORM. "f4_help_for_file *&---------------------------------------------------------------------* *& Form prepare_file_header *&---------------------------------------------------------------------* FORM prepare_file_header. w_header-col_01 = 'Column1'. w_header-col_02 = 'Column2'. w_header-col_03 = 'Column3'. w_header-col_04 = 'Column4'. w_header-col_05 = 'Column5'. w_header-col_06 = 'Column6'. w_header-col_07 = 'Column7'. APPEND w_header TO i_header. CLEAR w_header. ENDFORM. " prepare_file_header *&---------------------------------------------------------------------* *& Form prepare_file_footer *&---------------------------------------------------------------------* FORM prepare_file_footer. *Local variables DATA: l_no_of_records TYPE string, l_lines TYPE sy-tabix. *Footer for CU DESCRIBE TABLE i_data LINES l_lines. l_no_of_records = l_lines. CONCATENATE 'TRAILER:' l_no_of_records INTO w_footer-lines. APPEND w_footer TO i_footer. CLEAR w_footer. ENDFORM. " prepare_file_footer *&---------------------------------------------------------------------* *& Form download_data_into_file *&---------------------------------------------------------------------* FORM download_data_into_file. DATA: l_filename TYPE string, l_append TYPE char01. *Download Data and Create one file with header,data and footer. l_filename = p_file1. *Download header l_append = space. PERFORM download TABLES i_header USING l_filename l_append. *Download data l_append = 'X'. PERFORM download TABLES i_data USING l_filename l_append. *Download footer l_append = 'X'. PERFORM download TABLES i_footer USING l_filename l_append. ENDFORM. " download_data_into_file *&---------------------------------------------------------------------* *& Form prepare_cd_data *&---------------------------------------------------------------------* FORM prepare_cd_data. DO 10 TIMES. w_data-col_01 = w_data-col_01 + sy-index. w_data-col_02 = w_data-col_02 + sy-index. w_data-col_03 = w_data-col_03 + sy-index. w_data-col_04 = w_data-col_04 + sy-index. w_data-col_05 = w_data-col_05 + sy-index. w_data-col_06 = w_data-col_06 + sy-index. w_data-col_07 = w_data-col_07 + sy-index. APPEND w_data TO i_data. CLEAR w_data. ENDDO. ENDFORM. " prepare_cd_data *&---------------------------------------------------------------------* *& Form download *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_I_HEADER_CU text * -->P_L_FILENAME text * -->P_L_APPEND text *----------------------------------------------------------------------* FORM download TABLES p_i_datatab USING p_l_filename p_l_append. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = p_l_filename filetype = 'ASC' append = p_l_append write_field_separator = 'X' TABLES data_tab = p_i_datatab 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 NE 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ENDFORM. " download
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.