SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Dynamic manipulation of report programs



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dynamic Programming | Динамическое программирование
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sun Oct 14, 2007 5:57 pm    Post subject: Dynamic manipulation of report programs Reply with quote

Using ABAP code you are able to manipulate programs dynamically during execution.

The code below demonstrates how to read, delete and insert new code into an ABAP report program. It
uploads a file containing ABAP code which is inserted into a temporary program. This is then executed
using the submit statement and deleted once execution is complete.

Basic ABAP syntax for manipulating reports dynamically:
INSERT REPORT <prog> FROM &ltitab>.
READ REPORT <prog> INTO &ltitab>.
DELETE REPORT <prog>.

Code:
*Dynamic manipulation of report programs
*......................................................................
*: Report  ZDYNAMICCODE                                               :
*:.....................................................................
*:   Execute ABAP from a PC file(.txt)                                :
*:   Therefor allowing any abap code to be executed on any client     :
*:   which contains this program                                      :
*:                                                                    :
*.....................................................................:
REPORT  zdynamiccode                                                .

TABLES rlgrap.

*selection screen creation
PARAMETER:       p_file(200) TYPE c,
                 p_temp(30)  TYPE c DEFAULT 'Z123TEMP_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.
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.

  LOOP AT it_tab INTO p_file.
  ENDLOOP.


************************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.

*move file name into a field with type compatable with FM
  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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dynamic Programming | Динамическое программирование All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.