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

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

Advertising

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)
Advertising

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?

03/05/2021

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.

02/26/2021

ABAP - BOPF Quick Guide (Update)

Category - ABAP

A little update to our book that we published. For all people who find the paperless office boring.

10/23/2020

ABAP - BOPF Quick Guide

Category - ABAP

You need a quick introduction to the SAP Business Object Processing Framework (BOPF), we have the right guide for you here.

09/11/2020

ABAP Quick - Search in source code

Category - ABAP

Sometimes it is necessary to search through different source codes in one system. We show you how it works in the SAP GUI and in Eclipse.

04/24/2020

We use cookies for our services and functions. More informations