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

299

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 Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


ABAP Tools - Quick Actions und Highlighting (ABAP Unit)

Category - ABAP

With the last release of the ABAP Development Tools, Quick Actions were added for ABAP development in the ABAP Unit area. Here we take a closer look at them.

06/18/2024

ABAP Quick - RFC Error handling

Category - ABAP

How do you actually handle errors when communicating via a destination in the function module? More about this in our tip.

03/05/2024

ABAP Quick - CLEAR right

Category - ABAP

Delete correctly? In this article we want to take a look at when it makes sense to delete and how you can do it effectively.

05/12/2023

ABAP Quick - Performance chained statements

Category - ABAP

Let's take a look at the performance when creating chained statements with DATA and FIELD-SYMBOL. Which variant will be ahead in terms of performance?

04/28/2023

ABAP - ALV still relevant in 2022?

Category - ABAP

Today the joking question, do we still need reports that generate ALV outputs in 2022? In this article, we want to look into this question.

07/01/2022