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

ABAP Quick - Backup for reports

581

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
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
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
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
SELECT * 
 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.
ENDLOOP.

 

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.
    CONTINUE.
  ENDIF.

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

  " Download as text
  cl_gui_frontend_services=>gui_download(
    EXPORTING
      filename = gw_data-path
      write_lf = 'X'
    CHANGING
      data_tab = gt_text
    EXCEPTIONS
      OTHERS   = 1
  ).
  IF sy-subrc = 0.
    WRITE: / 'File written: ', gw_data-path.
  ENDIF.
ENDLOOP.

 

Conclusion

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:
QuickBackupReport
Comments (0)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Tuesday and Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


ABAP in Practice - Fiori Data incorrect

Category - ABAP

In this short practical example, we'll look at a Fiori error. Here, the data is displayed incorrectly in the UI, even though everything else appears to be correct. The trail leads us in a different direction through the RAP stack.

10/10/2025

ABAP Quick - Handling of Function modules

Category - ABAP

How do you actually handle function modules and error handling within ABAP? In this short tip, we'll also look at handling them within the context of RFC.

08/26/2025

ABAP Quick - Generic Data Types

Category - ABAP

What exactly distinguishes CLIKE from CSEQUENCE? Generic types can sometimes be a bit opaque, and as ABAP developers, we might choose a type that's too generic.

08/12/2025

BTP - Quick Deployment

Category - ABAP

Want to make Fiori Elements apps available even faster after RAP modeling? Quick Deployment is now possible.

07/18/2025

Recycling Heroes (Explained)

Category - ABAP

What do the Recycling Heroes have to do with modern ABAP development and ABAP Cloud? In this article, we provide insights into the idea.

07/15/2025