This is a test message to test the length of the message box.
ABAP Quick Backup for Reports
Created by Software-Heroes

ABAP Quick - Backup for reports

Save your own reports locally with one click? In this article, we'll show you how to do that without much effort.


You need a backup of your previous programs/reports you wrote? With today's tip, it's no longer a problem to extract everything with one click and archive it if necessary. We'll show you an efficient report that does it all for you.


Data definition

In the first step we define the data structure for the preparation of the data to be read. For this we need a table that contains the source code after reading. Since this is a simple report, the variables are directly declared globally.

" Types
  BEGIN OF ts_data,
    objnr  TYPE versobjnam,
    name   TYPE string,
    path   TYPE string,
  END OF ts_data,
  tt_data TYPE STANDARD TABLE OF ts_data.

" Data
  gt_text TYPE STANDARD TABLE OF abaptxt255,
  gw_text TYPE abaptxt255,
  gt_data TYPE tt_data,
  gw_data TYPE ts_data.


Selection screen

As second step we define the selection screen with the storage parameters. For which user should the data be extracted (in this case the own user) and in which local folder the finished files should be backed up.

" Define Parameters
  p_user  TYPE syuname DEFAULT sy-uname,
  p_path  TYPE string LOWER CASE DEFAULT 'C:	empcode',
  p_test AS CHECKBOX DEFAULT abap_true.


Read and prepare

You use the table TRDIR to read in all includes and reports and prepare them in the data structure. As a result, you get all the ingredients in an internal table. Of course, you can also save this step and start directly with the preparation and output of the source code to the files.

" Get data
 FROM trdir
 WHERE cnam = @p_user
   AND ( name LIKE 'LZ%' OR name LIKE 'SAPLZ%' OR name LIKE 'Z%' ).
 INTO TABLE @DATA(gt_dir).
" Fill structure
LOOP AT gt_dir INTO DATA(gs_dir).
  CLEAR gw_data.
  gw_data-objnr = gs_dir-name.
  gw_data-name = gs_dir-name.
  gw_data-path = p_path && gw_data-name && '.txt'.
  APPEND gw_data TO gt_data.


Download and print

Now you process the data from the global table and read in the content of the resource via the READ REPORT command. The test flag determines whether the content should only be output or the files should be stored on the file system.

LOOP AT gt_data INTO gw_data.
  " Clear data
  CLEAR: gt_text.

  " Get the code
  READ REPORT gw_data-objnr INTO gt_text.
  IF sy-subrc <> 0.
    WRITE: / 'Error: ', gw_data-name.

  " Test mode -> only some info
  IF p_test = abap_true.
    WRITE: / 'File found: ', gw_data-path.

  " Download as text
      filename = gw_data-path
      write_lf = 'X'
      data_tab = gt_text
      OTHERS   = 1
  IF sy-subrc = 0.
    WRITE: / 'File written: ', gw_data-path.



The reading of the source code is implemented with nearly no effort, as well as the download to the local computer. Thus, the report is a simple tool to help you manage your own source code and bring it in file form. Likewise, old reports can be archived and stored.

Included topics:
Comments (0)

ABAP Quick - Creation of test data

Category - ABAP

What challenges do you have when setting up test tables and test data and how can machine processing help you?


ABAP Unit Quick Guide

Category - ABAP

Our current e-book is now available on Amazon, we would like to briefly show you what you can expect in the book and what it will bring you in the end.


ABAP Quick - RFC Buffer

Category - ABAP

Here is a little tip from us about what can go wrong with the buffer when reading via RFC and what you should definitely pay attention to.


ABAP Quick - Wait for task

Category - ABAP

Today a tip for asynchronous processing or if you want to put processing in a separate task in special situations. What happens afterwards?


ABAP Quick - Performance INSERT vs VALUE

Category - ABAP

In this article we take a look at the performance of the insert operations APPEND, INSERT and VALUE with regard to tables and evaluate the performance and stability during development.