*&---------------------------------------------------------------------*
*& Report YTST_CX_DOWN
*&
*&---------------------------------------------------------------------*
*@---------------------------------------------------------------------*
*@ Created by Xavery Hsueh on 2011-03-01
*@ Lasted Edited date:
*@---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
report ytst_use_down no standard page heading.
***********************************************************************@
** 声明数据库表
***********************************************************************@
tables:rs38m,
trdir, "程序库
trdyse01cm.
***********************************************************************@
** 内表结构类型的定义
***********************************************************************@
data begin of dynpfields occurs 1.
include structure dynpread.
data end of dynpfields.
types:begin of typ_result,
box type c,
tabix type sytabix, "顺序号
name type char40, "程序名称
cnam type cnam, "创建人员
unam type unam, "最后修改人
code(72) type c, "程序描述
end of typ_result.
***********************************************************************@
** 变量与内表的定义
***********************************************************************@
data:gt_report type table of string with header line."TDLINE
data:gt_report1 type table of tdline with header line."TDLINE
*DATA:GT_REPORT2 TYPE TABLE OF CHAR1000 WITH HEADER LINE."TDLINE
data:gt_result type table of typ_result with header line.
data:gt_trdir type table of trdir with header line.
data:gt_btab type table of textpool with header line.
data:g_filenm type rlgrap-filename. "文件名称
ranges r_prog for rs38m-programm. "程序名称
*@------------------ ALV 相关的变量 -----------------------------------*
type-pools:slis.
data: g_repid like sy-repid,
wa_print type slis_print_alv,
gt_list_top_of_page type slis_t_listheader,
gt_events type slis_t_event with header line,
gt_sort type slis_t_sortinfo_alv,
wa_layout type slis_layout_alv,
gt_fieldcat type slis_t_fieldcat_alv with header line,
wa_fieldcat like line of gt_fieldcat,
g_save type c,
g_pos type i.
data:g_len type string.
data:g1(10000) type c.
***********************************************************************@
** 宏定义
***********************************************************************@
define mcr_field.
clear wa_fieldcat.
g_pos = g_pos + 1 .
wa_fieldcat-col_pos = g_pos.
wa_fieldcat-fieldname = &1.
wa_fieldcat-tabname = 'I_RESULT'.
* wa_fieldcat-no_out = 'X'. "field no display, choose from layout
wa_fieldcat-key = ' '. "SUBTOTAL KEY
wa_fieldcat-seltext_l = &2.
wa_fieldcat-outputlen = &3.
append wa_fieldcat to gt_fieldcat.
end-of-definition.
*@---------------------------------------------------------------------*
*@ MACRO MCR_RANGE 初始化选择条件
*@---------------------------------------------------------------------*
* &1 RANGE 变量
* &2 操作符
* &3 LOW
* &4 HIGH
*----------------------------------------------------------------------*
define mcr_range.
clear &1.
&1-sign = 'I'.
&1-option = &2.
&1-low = &3.
&1-high = &4.
append &1.
end-of-definition.
***********************************************************************@
** 屏幕定义
***********************************************************************@
selection-screen begin of block xavery with frame title text_001.
selection-screen begin of line.
*&p_prog.
selection-screen comment 1(15) text_002 for field s_prog.
select-options:s_prog for rs38m-programm memory id rid.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 1(15) text_003 for field s_cnam.
*PARAMETERS:P_CNAM TYPE CNAM DEFAULT SY-UNAME.
select-options:s_cnam for trdyse01cm-username. "MEMORY ID RID.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 1(15) text_004 for field p_filenm.
parameters:p_filenm type rlgrap-filename.
selection-screen end of line.
selection-screen end of block xavery.
***********************************************************************@
** 执行程序事件
***********************************************************************@
initialization.
perform f_init_condition.
at selection-screen on value-request for s_prog-low.
perform sub_get_program.
start-of-selection.
perform sub_query_report.
perform sub_process_report.
end-of-selection.
perform sub_init_layout.
perform sub_create_fieldcat.
perform sub_display_as_alv. "以ALV的方式输出结果表
*@---------------------------------------------------------------------*
*@ Form F_INIT_CONDITION
*@---------------------------------------------------------------------*
* 初始化选择条件
*----------------------------------------------------------------------*
form f_init_condition .
text_001 = '查询条件'.
text_002 = '程序名称'.
text_003 = '程序创建人'.
text_004 = '下载文件名称'.
* 选择屏幕初始值
s_prog-low = 'Z*'.
p_filenm = 'C:\ABAP\'.
endform. " F_INIT_CONDITION
*&---------------------------------------------------------------------*
*& Form SUB_GET_PROGRAM
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form sub_get_program .
data: repid like sy-repid.
dynpfields-fieldname = 'P_PROG'.
append dynpfields.
repid = sy-repid.
call function 'DYNP_VALUES_READ'
exporting
dyname = repid
dynumb = sy-dynnr
tables
dynpfields = dynpfields
exceptions
others.
read table dynpfields index 1.
s_prog = dynpfields-fieldvalue.
perform program_directory using s_prog-low 'X'.
endform. " SUB_GET_PROGRAM
*---------------------------------------------------------------------*
* FORM PROGRAM_DIRECTORY *
*---------------------------------------------------------------------*
form program_directory using programm like rs38m-programm
f4_call.
data: info_object like euobj-id,
l_programm like rs38m-programm.
if sy-tcode(4) = 'SE38'.
info_object = 'PROG'.
if f4_call = 'X'.
call function 'REPOSITORY_INFO_SYSTEM_F4'
exporting
object_type = info_object
object_name = programm
suppress_selection = 'X'
importing
object_name_selected = programm
exceptions
cancel = 01.
else.
call function 'REPOSITORY_INFO_SYSTEM'
exporting
object_type = info_object
action = 'S'
object_name = programm
importing
object_name_selected = programm
exceptions
cancel = 01
wrong_type = 02.
endif.
else.
l_programm = programm.
if l_programm = space.
submit rsabadab and return via selection-screen
with f4_call = f4_call.
else.
submit rsabadab and return via selection-screen
with repname cp l_programm
with f4_call = f4_call.
endif.
get parameter id 'RID' field s_prog-low.
endif.
endform. "program_directory
*&---------------------------------------------------------------------*
*& Form SUB_QUERY_REPORT
*&---------------------------------------------------------------------*
* 查询程序代码
*----------------------------------------------------------------------*
form sub_query_report .
mcr_range r_prog 'CP' s_prog-low ''.
*&程序库中找程序
select *
from trdir
into table gt_trdir
where name in r_prog
and cnam in s_cnam
and subc ne 'X'.
*&条目数
g_len = lines( gt_trdir[] ).
if g_len eq 0.
message i000(oo) with '没有找到符合条件的数据!'.
stop.
else.
message s000(oo) with '找到数据条目数:' g_len.
endif.
endform. " SUB_QUERY_REPORT
*&---------------------------------------------------------------------*
*& Form SUB_DOWNLOAD_REPORT
*&---------------------------------------------------------------------*
* 下载程序代码
*----------------------------------------------------------------------*
form sub_download_report using l_filenm type rlgrap-filename.
data: binfilesize type i.
data: l_file type string.
data: l_message type char100.
concatenate '文件已下载到:' p_filenm '文件夹中!'
into l_message.
l_file = l_filenm.
call function 'GUI_DOWNLOAD'
exporting
bin_filesize = binfilesize
filename = l_file
filetype = 'ASC'
tables
data_tab = gt_report[]
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 l_message type 'S'.
endif.
endform. " SUB_DOWNLOAD_REPORT
*&---------------------------------------------------------------------*
*& Form SUB_PROCESS_REPORT
*&---------------------------------------------------------------------*
* 处理文件名称,并放到内表中
*----------------------------------------------------------------------*
form sub_process_report .
sort gt_trdir by name.
loop at gt_trdir.
clear gt_result.
gt_result-name = gt_trdir-name.
gt_result-cnam = gt_trdir-cnam.
gt_result-unam = gt_trdir-unam.
gt_result-tabix = sy-tabix.
refresh gt_btab.
read textpool gt_trdir-name into gt_btab language sy-langu.
clear gt_btab.
read table gt_btab with key 'R'.
if sy-subrc = 0.
move gt_btab-entry to gt_result-code.
endif.
append gt_result.
endloop.
* 清空内表
free gt_trdir.
endform. " SUB_PROCESS_REPORT
*&---------------------------------------------------------------------*
*& Form SUB_CREATE_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form sub_create_fieldcat .
clear gt_fieldcat[].
mcr_field 'TABIX' '顺序号' '10'.
mcr_field 'NAME' '程序名称' '15'.
mcr_field 'CNAM' '程序创建人' '20'.
mcr_field 'UNAM' '最后修改人' '20'.
mcr_field 'CODE' '程序描述' '30'.
endform. " SUB_CREATE_FIELDCAT
*&---------------------------------------------------------------------*
*& Form SUB_INIT_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form sub_init_layout .
wa_layout-zebra = 'X'.
wa_layout-window_titlebar = '开发程序名称清单'.
wa_layout-colwidth_optimize = 'X'.
wa_layout-box_fieldname = 'BOX'.
*WA_LAYOUT-SEL_FIELDNAME = 'BOX'.
endform. " SUB_INIT_LAYOUT
*&---------------------------------------------------------------------*
*& Form SUB_DISPLAY_AS_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form sub_display_as_alv .
g_repid = sy-repid.
*ABAP List Viewer
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = g_repid
i_structure_name = 'TYP_RESULT'
i_callback_user_command = 'SUB_USER_COMMAND'
i_callback_pf_status_set = 'SUB_SET_PF_STATUS'
i_save = g_save
is_layout = wa_layout
it_fieldcat = gt_fieldcat[]
tables
t_outtab = gt_result
exceptions
program_error = 1
others = 2.
endform. " SUB_DISPLAY_AS_ALV
*@--------------------------------------------------------------------*
*@ Form sub_user_command
*@--------------------------------------------------------------------*
* -->R_UCOMM 事务功能码
* -->RS_SELFIELD ALV相关的数据
*---------------------------------------------------------------------*
form sub_user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
case r_ucomm.
when '&IC1'. "双击事件的功能码
read table gt_result index rs_selfield-tabindex.
set parameter id 'RID' field gt_result-name.
call transaction 'SE38' and skip first screen.
when '&DATA_SAVE'. "下载代码
perform sub_ucomm_down.
endcase.
* 刷新ALV屏幕报表
rs_selfield-refresh = 'X'.
endform. "sub_user_command
*@---------------------------------------------------------------------*
*@ FORM SUB_SET_PF_STATUS *
*@---------------------------------------------------------------------*
* 设置ALV菜单
* 通过SE41,拷贝程序SAPLSLVC_FULLSCREEN的状态STANDARD_FULLSCREEN过来
*@---------------------------------------------------------------------*
form sub_set_pf_status using rt_extab type slis_t_extab.
set pf-status 'STANDARD_FULLSCREEN'.
endform. "sub_set_pf_status
*&---------------------------------------------------------------------*
*& Form SUB_UCOMM_DOWN
*&---------------------------------------------------------------------*
* 下载选中的行的程序代码
*----------------------------------------------------------------------*
form sub_ucomm_down .
loop at gt_result where box = 'X'.
* 得到文件名称
clear g_filenm.
concatenate p_filenm gt_result-name '-'
gt_result-code '.txt'
into g_filenm.
* 得到程序代码
clear gt_report[].
if gt_result-name is not initial.
read report gt_result-name into gt_report.
* LOOP AT GT_REPORT.
* CONCATENATE GT_REPORT G1 INTO G1.
* ENDLOOP.
endif.
* 下载程序
perform sub_download_report using g_filenm.
endloop.
endform. " SUB_UCOMM_DOWN