*&---------------------------------------------------------------------*
*& Report Ytst_cx_down
*&
*&---------------------------------------------------------------------*
*@---------------------------------------------------------------------*
*@ Created by Xavery Hsueh on 2011-03-01
*@ lasted edited date:
*@---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
Report Ytst_use_down no standard page heading.
***********************************************************************@
* * Declaring database tables
***********************************************************************@
tables:rs38m,
Trdir, "Program Library
trdyse01cm.
***********************************************************************@
* * Definition of the Inner table structure type
***************** @
Data begin of Dynpfields occurs 1.
include structure Dynpread.
Data end of dynpfields.
Types:begin of Typ_result,
box type C,
Tabix type Sytabix, order number
Name Type CHAR40, program name
Cnam type Cnam, "Create person
UNAM type UNAM," Last modified by
Code (*) Type C, "program describes
end of Typ_result.
@
* * variable and definition of inner table
********************* @
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. The file name
Ranges R_prog for Rs38m-programm. The program name
*@------------------ALV Related variables-----------------------------------*
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.
***********************************************************************@
* * Macro Definition
***********************************************************************@
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 Initialization selection criteria
*@---------------------------------------------------------------------*
* &1 RANGE variable
* &2 operator
* &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.
***********************************************************************@
* * Screen definition
***********************************************************************@
Selection-screen begin of block xavery with frame title text_001.
Selection-screen begin of line.
*&p_prog.
Selection-screen Comment 1 (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 (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 (text_004) for field P_filenm.
Parameters:p_filenm type Rlgrap-filename.
Selection-screen end of line.
Selection-screen end of Block Xavery.
***********************************************************************@
* * Execute Program events
***********************************************************************@
Initialization.
Perform f_init_condition.
At Selection-screen in 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. "Output a table of results in a ALV way
*@---------------------------------------------------------------------*
*@ Form f_init_condition
*@---------------------------------------------------------------------*
* Initialize selection criteria
*----------------------------------------------------------------------*
Form F_init_condition.
text_001 = ' query condition '.
text_002 = ' program name '.
text_003 = ' program Creator '.
text_004 = ' Download file name '.
* Select Screen Initial value
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
*&---------------------------------------------------------------------*
* Query Program code
*----------------------------------------------------------------------*
Form Sub_query_report.
Mcr_range R_prog ' CP ' S_prog-low '.
Find programs in the *& program library
SELECT *
From Trdir
into table Gt_trdir
where name in R_prog
and Cnam in S_cnam
and subc ne ' X '.
Number of *& entries
G_len = lines (gt_trdir[]).
If G_len eq 0.
Message i000 (OO) with ' did not find qualifying data! '.
Stop.
Else.
Message s000 (OO) with ' Number of data entries found: ' G_len.
endif.
EndForm. "Sub_query_report
*&---------------------------------------------------------------------*
*& Form Sub_download_report
*&---------------------------------------------------------------------*
* Download Program code
*----------------------------------------------------------------------*
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 ' file has been downloaded to: ' P_filenm ' folder! ‘
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
*&---------------------------------------------------------------------*
* Process the file name and put it in the inner table
*----------------------------------------------------------------------*
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.
* Empty the inner table
Free Gt_trdir.
EndForm. "Sub_process_report
*&---------------------------------------------------------------------*
*& Form Sub_create_fieldcat
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
Form Sub_create_fieldcat.
Clear gt_fieldcat[].
Mcr_field ' Tabix ' sequence number ' 10 '.
Mcr_field ' name ' program name ' 15 '.
Mcr_field ' Cnam ' program creator person ' 20 '.
Mcr_field ' UNAM ' last modified man ' 20 '.
Mcr_field ' Code ' program describes ' 30 '.
EndForm. "Sub_create_fieldcat
*&---------------------------------------------------------------------*
*& Form Sub_init_layout
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
Form Sub_init_layout.
Wa_layout-zebra = ' X '.
Wa_layout-window_titlebar = ' Development program Name list '.
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
exception s
Program_error = 1
others = 2.
EndForm. "Sub_display_as_alv
*@--------------------------------------------------------------------*
*@ Form sub_ User_command
*@--------------------------------------------------------------------*
*-->R_UCOMM transaction function code
*-->rs_selfield ALV Related data
*---------------------------------------------------------------------*
Form Sub_user_command using r_ucomm like Sy-ucomm
Rs_selfield type Slis_selfield.
Case R_ucomm.
When ' &ic1 '. "Double-click the function code of the event
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 '. The download code
Perform sub_ucomm_down.
Endcase.
* Refresh ALV Screen report
Rs_selfield-refresh = ' X '.
EndForm. "Sub_user_command
*@---------------------------------------------------------------------*
*@ FORM Sub_set_pf_status *
*@---------------------------------------------------------------------*
* Set ALV Menu
* Through SE41, copy the program Saplslvc_fullscreen status Standard_fullscreen come over
*@---------------------------------------------------------------------*
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
*&---------------------------------------------------------------------*
* Download the program code for the selected line
*----------------------------------------------------------------------*
Form Sub_ucomm_down.
Loop at Gt_result where box = ' X '.
* Get the file name
Clear G_filenm.
Concatenate p_filenm gt_result-name '-'
Gt_result-code '. txt '
Into G_filenm.
* Get program code
Clear gt_report[].
If Gt_result-name is not initial.
Read report Gt_result-name to Gt_report.
* LOOP at Gt_report.
* Concatenate Gt_report G1 into G1.
* Endloop.
endif.
* Download Program
Perform sub_download_report using G_FILENM.
Endloop.
EndForm. "Sub_ucomm_down
yuse_down-Batch Download