This sample program is used to download all programs and function modules from a particular package.
REPORT zdownload_pack.
*table decleration
TABLES : tadir.
*data decleration
TYPES: codeline(255).
DATA: sourcecode TYPE STANDARD TABLE OF codeline WITH HEADER LINE.
DATA: prog(60) ,
codefile LIKE rlgrap-filename,
filename TYPE string,
func_tab TYPE TABLE OF rs38l_incl WITH HEADER LINE,
pname TYPE pname,
poolname TYPE tlibg-area,
fmcount(3) TYPE n ,
prgcount(3) TYPE n,
msg1(45).
*Internal table for prgram info
DATA: BEGIN OF pgminfo OCCURS 0,
pgmid TYPE tadir-pgmid,
object TYPE tadir-object,
obj_name TYPE tadir-obj_name,
devclass TYPE tadir-devclass,
END OF pgminfo.
*____________________________________________________________________
*Get Development class from User
PARAMETERS: pckg TYPE tadir-devclass.
*____________________________________________________________________
*Initialize variables
fmcount = '000'.
prgcount = '000'.
*____________________________________________________________________
*Proceed one by one
PERFORM cleardata.
PERFORM write_prgrms.
PERFORM cleardata.
PERFORM write_fms.
CONCATENATE prgcount ' Prgs Files & '
fmcount ' FM Files Written' INTO msg1.
MESSAGE s001(00) WITH msg1.
*____________________________________________________________________
*&------------------------------------------------------------------*
*& Form cleardata
*&------------------------------------------------------------------*
* text
*-------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*-------------------------------------------------------------------*
FORM cleardata.
CLEAR: sourcecode,
pgminfo[],
prog,
codefile,
filename,
func_tab[],
pname,
poolname.
ENDFORM. " cleardata
*&------------------------------------------------------------------*
*& Form write_prgrms
*&------------------------------------------------------------------*
* text
*-------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*-------------------------------------------------------------------*
FORM write_prgrms.
DATA: prgmsg(45).
*select statement.
SELECT pgmid object obj_name devclass FROM tadir INTO TABLE pgminfo
WHERE pgmid = 'R3TR' AND
object = 'PROG' AND
devclass = pckg.
LOOP AT pgminfo.
prog = pgminfo-obj_name.
READ REPORT prog INTO sourcecode.
CONCATENATE 'D:\ABAP\'
pckg
'Reports\'
prog
'.txt'
INTO codefile.
filename = codefile.
*function module for download files into local system
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.
prgcount = prgcount + 1.
ENDIF.
CLEAR prog.
CLEAR: sourcecode[] , sourcecode , func_tab.
ENDLOOP.
CONCATENATE prgcount ' Prgs Files Written' INTO prgmsg..
MESSAGE s001(00) WITH prgmsg.
ENDFORM. " write_prgrms
*____________________________________________________________________
*&------------------------------------------------------------------*
*& Form write_fms
*&------------------------------------------------------------------*
* text
*-------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*-------------------------------------------------------------------*
FORM write_fms.
DATA: fmmsg(45).
*select statement to get all function groups.
SELECT pgmid object obj_name devclass FROM tadir INTO TABLE pgminfo
WHERE pgmid = 'R3TR' AND
object = 'FUGR' AND
devclass = pckg.
LOOP AT pgminfo.
poolname = pgminfo-obj_name.
CALL FUNCTION 'RS_FUNCTION_POOL_CONTENTS'
EXPORTING
function_pool = poolname
TABLES
functab = func_tab
* EXCEPTIONS
* FUNCTION_POOL_NOT_FOUND = 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.
LOOP AT func_tab .
prog = func_tab-include.
READ REPORT prog INTO sourcecode.
CONCATENATE 'D:\ABAP\'
pckg
'FM\'
func_tab-funcname
'.txt'
INTO codefile.
filename = codefile.
*function module for download files into local system
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.
fmcount = fmcount + 1.
ENDIF.
CLEAR prog.
CLEAR: sourcecode[] , sourcecode , func_tab.
ENDLOOP.
ENDLOOP.
CONCATENATE fmcount ' FM Files Written' INTO fmmsg..
MESSAGE s001(00) WITH fmmsg.
ENDFORM. " write_fms
No comments:
Post a Comment