Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

Source code for Dynamic Report from flat file

$
0
0

Below set of code was used to execute the report prom from flat file.

*&---------------------------------------------------------------------*
*& Report  Z_DYNAMIC_REPORT
*&---------------------------------------------------------------------*
*  Execute ABAP report from a PC file(.txt)Therefor allowing any       *
*  abap code to be executed on any clientwhich contains this program   *
*&---------------------------------------------------------------------*

REPORT  z_dynamic_report.

TABLES rlgrap.

*selection screen creation
PARAMETER: p_file(200)
TYPE c,
           p_temp(30) 
TYPE c DEFAULT 'Z_REPORT_FOR_CODE'.

*data declaration
DATA: it_tab
TYPE filetable,
      gd_subrc
TYPE i,
      answer
TYPE c.

TYPES:
BEGIN OF t_abapcode,
          row(72)
TYPE c,
      
END OF t_abapcode.

DATA: it_abapcode
TYPE STANDARD TABLE OF t_abapcode INITIAL SIZE 0,
      it_store   
TYPE STANDARD TABLE OF t_abapcode INITIAL SIZE 0.

DATA: filename
TYPE  string.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*Selecting a File, plus inserting default file extension
  REFRESH: it_tab.
 
CALL METHOD cl_gui_frontend_services=>file_open_dialog
   
EXPORTING
      window_title     =
'Select File'
      default_filename =
'*.txt'
      multiselection   =
' '
   
CHANGING
      file_table       = it_tab
      rc               = gd_subrc.

START-OF-SELECTION.
  filename = p_file.

*upload file from PC
 
CALL FUNCTION 'GUI_UPLOAD'
   
EXPORTING
      filename                = filename
   
TABLES
      data_tab                = it_abapcode
   
EXCEPTIONS
      file_open_error         =
1
      file_read_error         =
2
      no_batch                =
3
      gui_refuse_filetransfer =
4
      invalid_type            =
5
      no_authority            =
6
      unknown_error           =
7
      bad_data_format         =
8
      header_not_allowed      =
9
      separator_not_allowed   =
10
      header_too_long         =
11
      unknown_dp_error        =
12
      access_denied           =
13
      dp_out_of_memory        =
14
      disk_full               =
15
      dp_timeout              =
16
     
OTHERS                  = 17.
 
IF sy-subrc EQ 0.
*   Check if report name being used fro temorary code already exists as
*   any code will be over written and lost
   
READ REPORT p_temp INTO it_store.
   
IF sy-subrc NE 0.
*     Please note any existing code in the program will be lost!!!!
     
INSERT REPORT p_temp FROM it_abapcode.
     
SUBMIT (p_temp) AND RETURN.
     
DELETE REPORT p_temp.
    ELSE.
     
CALL FUNCTION 'POPUP_TO_CONFIRM'
       
EXPORTING
          text_question =
'Report used to store temporary code already exists!!! Do you want to overwrite it?'
       
IMPORTING
          answer        = answer.
     
IF sy-subrc EQ 0.
       
IF answer EQ '1'. "yes
*         Please note any existing code in the program will be lost!!!!
         
INSERT REPORT p_temp FROM it_abapcode.
         
SUBMIT (p_temp) AND RETURN.
         
DELETE REPORT p_temp.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.

 

kindly provide your valuable comments,


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>