備份ABAP程式碼 (分模組儲存)

TolyHuang發表於2007-11-01

 

[@more@]

REPORT zrp_backup_abapcode.
TABLES tadir.
TYPES: BEGIN OF t_type,
line(9999),
END OF t_type.
DATA rep_table TYPE STANDARD TABLE OF t_type WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 500.
DATA: file TYPE string,"RLGRAP-FILENAME.
path TYPE string.
PARAMETER: obj_name LIKE tadir-obj_name DEFAULT 'Z%'.
SELECT-OPTIONS: object FOR tadir-object DEFAULT 'PROG',
author FOR tadir-author, "AUTHOR FOR TADIR-AUTHOR DEFAULT SY-UNAME,
devclass FOR tadir-devclass.
DATA: BEGIN OF it_table OCCURS 0,
obj_name LIKE tadir-obj_name,
END OF it_table.
DATA: BEGIN OF wa_table,
obj_name LIKE tadir-obj_name,
END OF wa_table.
DATA: message_text TYPE string.
DATA: zmd TYPE char6.
***********************************************************************

START-OF-SELECTION.

SELECT obj_name INTO TABLE it_table FROM tadir
WHERE obj_name LIKE obj_name AND
object IN object AND
author IN author AND
devclass IN devclass.
SORT it_table BY obj_name.
LOOP AT it_table INTO wa_table.

IF wa_table-obj_name+4(2) = 'MM'
OR wa_table-obj_name+5(2) = 'MM' .
zmd = 'MM'.
ELSEIF wa_table-obj_name+4(2) = 'PP'
OR wa_table-obj_name+5(2) = 'PP'.
zmd = 'PP'.
ELSEIF wa_table-obj_name+4(2) = 'SD'
OR wa_table-obj_name+5(2) = 'SD'.
zmd = 'SD'.
ELSEIF wa_table-obj_name+4(2) = 'FI'
OR wa_table-obj_name+5(2) = 'FI'
OR wa_table-obj_name+4(2) = 'CO'
OR wa_table-obj_name+5(2) = 'CO'.
zmd = 'FICO'.
ELSEIF wa_table-obj_name+4(2) = 'HR'
OR wa_table-obj_name+5(2) = 'HR'.
zmd = 'HR'.
ELSE.
zmd = 'OTHERS'.
ENDIF.

IF devclass-high <> ''.
CONCATENATE 'C:BACKUP-' zmd '-' sy-datum+6(2) '.' sy-datum+4(2) '.'
sy-datum+0(4) '-' sy-sysid '-' devclass-low
'-' devclass-high ''
INTO path.
ELSE.
CONCATENATE 'C:BACKUP-' zmd '-' sy-datum+6(2) '.' sy-datum+4(2) '.'
sy-datum+0(4) '-' sy-sysid '-' devclass-low
''
INTO path.
ENDIF.
CONDENSE path NO-GAPS.

READ REPORT wa_table-obj_name INTO rep_table.
IF wa_table-obj_name CS ''.

ELSE.
CLEAR file.
CONCATENATE path wa_table-obj_name '.TXT' INTO file.
IF sy-subrc = 0.
* CALL FUNCTION 'DOWNLOAD'
* EXPORTING
* FILENAME = FILE
* FILETYPE = 'ASC' "ASC, WK1, DBF, DAT, bin
* MODE = ' ' "Mode ' ' = Rewrite Mode 'A' = Appending
* TABLES
* DATA_TAB = REP_TABLE.
* WRITE: / 'File Saved Successfully'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = file
filetype = 'ASC'
* APPEND = 'X'
* WRITE_FIELD_SEPARATOR = 'X'
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* IMPORTING
* FILELENGTH =
TABLES
data_tab = rep_table
* FIELDNAMES =
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.
WRITE :/ 'File download error,Message code:',sy-subrc,
' creating file ',file.
ENDIF.
ELSE.
WRITE: / 'Error Occured'.
ENDIF.
ENDIF.
ENDLOOP.
message_text = 'FILE(S) CREATED IN FOLDER'.
CONCATENATE message_text path INTO message_text SEPARATED BY space.
MESSAGE message_text TYPE 'I'.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9437124/viewspace-980341/,如需轉載,請註明出處,否則將追究法律責任。

相關文章