Program for Auto Backup which will be useful for developers who can take backup before and after Modifications.
Hi guys,
This is my first document. I have a habit to always take a backup before and After Critical Modifications incase any error occurs and revert back is required. I would like to share this with you and i would be glad if any feedback is provided regarding code or suggestions for development for a new program which will be useful.
Search for Change in your program to get path change line
REPORT ZDEV_BACKUP.
TYPES: codeline(255).
DATA: sourcecode TYPE STANDARD TABLE OF codeline WITH HEADER LINE.
DATA: prog(60) ,
filename TYPE string,
dirname(255) TYPE c,
gv_datum(10).data: gt_DIRTABLE LIKE SDOKPATH OCCURS 0 WITH HEADER LINE,
gt_fileTABLE LIKE SDOKPATH OCCURS 0 WITH HEADER LINE,
gv_filecount TYPE i,
gv_dircount TYPE i,
gv_cnt TYPE string.SELECTION–SCREEN: BEGIN of BLOCK b1 WITH FRAME .
PARAMETERS: p_prog(40) TYPE c OBLIGATORY. “Program Name
PARAMETERS: p_rem(60) TYPE c.” Remarks for own use
SELECTION–SCREEN: end of BLOCK b1 .
BREAK–POINT.
PERFORM read_prog.
CHECK sourcecode[] is not INITIAL.
PERFORM write_prgrms.PERFORM cleardata.
*&——————————————————————*
*& Form cleardata
*&——————————————————————*
* text
*——————————————————————-*
* –> p1 text
* <– p2 text
*——————————————————————-*
FORM cleardata.CLEAR: sourcecode,
filename.ENDFORM. ” cleardata
FORM write_prgrms.
DATA: prgmsg(45).
write sy–datum to gv_datum.
CONCATENATE ‘…….\Auto Backup\’ Change ” Folder Path for all backups
p_prog ‘\’ gv_datum ‘\’ into dirname.* Get New Directory Name
CALL FUNCTION ‘TMP_GUI_DIRECTORY_LIST_FILES’
EXPORTING
DIRECTORY = dirname
FILTER = ‘*.*’
IMPORTING
file_COUNT = gv_filecount
DIR_COUNT = gv_dircount
TABLES
FILE_TABLE = gt_fileTABLE
DIR_TABLE = gt_DIRTABLE
EXCEPTIONS
CNTL_ERROR = 1
OTHERS = 2
.
IF SY–SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
gv_cnt = gv_dircount + 1.
CONCATENATE dirname gv_cnt p_rem INTO dirname.* /Get New Directory Name
* Format : Prog Name / Date / Remark / Filename.txt
CONCATENATE dirname ‘\’ p_prog ‘.txt’ into filename.
*download files into local system
CONCATENATE ‘* Path : ‘ filename into sourcecode SEPARATED BY space.
INSERT sourcecode INTO sourcecode INDEX 1.CALL FUNCTION ‘GUI_DOWNLOAD’
EXPORTING
filename = filename
TABLES
data_tab = sourcecode
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.IF sy–subrc <> 0.
MESSAGE ID SY–MSGID TYPE SY–MSGTY NUMBER SY–MSGNO
WITH SY–MSGV1 SY–MSGV2 SY–MSGV3 SY–MSGV4.
ELSE.
ENDIF.
* / download files into local system
CLEAR: sourcecode[] , sourcecode .ENDFORM. ” write_prgrms
*&———————————————————————*
*& Form READ_PROG
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM READ_PROG .
* *& Format : (Prog Name / Date / Remark) / Filename.txt
READ REPORT p_prog INTO sourcecode.
* Add First Line HeaderENDFORM. ” READ_PROG
The Program will be stored in the following Format. for eg : if your program is ZDEV_BACKUP in your auto backup folder it will be stored like
Todays Date / 1 Before Modifications / ZDEV_BACKUP.txt
1 Before Modifications -> 1 is autogenerated while Before Modifications is the Remarks you Enter
Second Time you execute
Todays Date / 2 After Modifications / ZDEV_BACKUP.txt
Even within the txt file the remarks will be added as a comment for identifying