SPAN {
font-family: "Courier New";
font-size: 10pt;
color: #000000;
background: #FFFFFF;
}
.L0S31 {
font-style: italic;
color: #808080;
}
.L0S32 {
color: #3399FF;
}
.L0S33 {
color: #4DA619;
}
.L0S52 {
color: #0000FF;
}
REPORT ZPPPR_RB_LIST MESSAGE-ID s1 NO STANDARD PAGE HEADING LINE-SIZE 512..
TYPE-POOLS: slis.
DATA: gs_layout TYPE slis_layout_alv,
gt_fieldcat TYPE slis_t_fieldcat_alv,
l_grid_title(70) TYPE c VALUE '生产日报后台数据下载'.
DATA git_listheader TYPE slis_t_listheader.
DATA git_events TYPE slis_t_event.
DATA: BEGIN OF file_list OCCURS 100,
dirname TYPE DIRNAME_AL11, " name of directory
name TYPE FILENAME_AL11," name of entry
type(10) TYPE c, " type of entry.
len(8) TYPE p, " length in bytes.
owner(8) TYPE c, " owner of the entry.
mtime(6) TYPE p, " last mod. date, sec since 1970
mode(9) TYPE c, " like "rwx-r-x--x": prot. mode
useable(1) TYPE c,
subrc(4) TYPE c,
errno(3) TYPE c,
errmsg(40) TYPE c,
mod_date TYPE d,
mod_time(8) TYPE c, " hh:mm:ss
seen(1) TYPE c,
changed(1) TYPE c,
line_color(4) TYPE c, "颜色处理
END OF file_list.
DATA file_list_wa like file_list.
DATA: BEGIN OF searchpoints OCCURS 10,
dirname TYPE DIRNAME_AL11, " name of directory.
sp_name TYPE FILENAME_AL11," name of entry. (may end with *)
sp_cs(10) TYPE c, " ContainsString pattern for name
END OF searchpoints.
DATA: BEGIN OF file,
dirname TYPE DIRNAME_AL11, " name of directory
name TYPE FILENAME_AL11," name of entry
type(10) TYPE c, " type of entry.
len(8) TYPE p, " length in bytes.
owner(8) TYPE c, " owner of the entry.
mtime(6) TYPE p, " last mod.date, sec since 1970
mode(9) TYPE c, " like "rwx-r-x--x": prot. mode
useable(1) TYPE c,
subrc(4) TYPE c,
errno(3) TYPE c,
errmsg(40) TYPE c,
mod_date TYPE d,
mod_time(8) TYPE c, " hh:mm:ss
seen(1) TYPE c,
changed(1) TYPE c,
END OF file.
data:sap_no(1) VALUE ' '
, g_repid TYPE sy-repid
,gv_pfkey TYPE sy-pfkey
,gv_flag TYPE i VALUE 0
,sap_yes(1) VALUE 'X'
, srt(1) VALUE 'T'
, no_cs VALUE ' '. " no MUST_ContainString.
data:gt_outtab1 TYPE STANDARD TABLE OF cst_rswatch02_alv,
gs_outtab1 TYPE cst_rswatch02_alv.
DATA: gt_outtab TYPE STANDARD TABLE OF cst_rswatch01_alv.
DATA: gr_table TYPE REF TO cl_salv_table.
DATA list_filename TYPE DIRNAME_AL11.
DATA list_file_only(1).
CONSTANTS: gc_true TYPE sap_bool VALUE 'X'.
*&---------------------------------------------------------------------*
*& Form get_directory
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
START-OF-SELECTION.
AUTHORITY-CHECK OBJECT 'S_ADMI_FCD'
ID 'S_ADMI_FCD'
FIELD 'ST0R'.
IF sy-subrc <> 0.
MESSAGE s202 WITH 'S_ADMI_FCD'.
ELSE.
perFORM get_directory.
ENDIF.
*&---------------------------------------------------------------------*
*& Form get_directory
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_directory.
*--- C5056155 Start Of Comments --------------------------------------*
* SET PF-STATUS 'L100'.
SET TITLEBAR '100'.
*--- C5056155 End Of Comments --------------------------------------*
REFRESH file_list.
REFRESH searchpoints.
searchpoints-dirname = '/usr/sap/tmp'.
searchpoints-dirname = '/down'.
*-- C5056155 --- End of ALV ---------------------------------------*
searchpoints-sp_name = '*' .
searchpoints-sp_cs = '' .
APPEND searchpoints.
LOOP AT searchpoints.
PERFORM fill_file_list USING searchpoints-dirname
searchpoints-sp_name
searchpoints-sp_cs
.
ENDLOOP.
* srt = 'N'.
SORT file_list BY MOD_DATE DESCENDING MOD_TIME DESCENDING.
PERFORM show_file_list.
* LEAVE TO LIST-PROCESSING.
ENDFORM. "GET_DIRECTORY.
*&---------------------------------------------------------------------*
*& Form show_file_list
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM show_file_list.
FILE_LIST_wa-line_color = 'C610'.
MODIFY FILE_LIST FROM FILE_LIST_wa
TRANSPORTING line_color WHERE MOD_DATE = SY-DATUM.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
CLEAR ls_fieldcat.
LS_FIELDCAT-TABNAME = 'FILE_LIST'. LS_FIELDCAT-FIELDNAME = 'DIRNAME'. LS_FIELDCAT-SELTEXT_L = 'DIRNAME'. APPEND LS_FIELDCAT TO GT_FIELDCAT. CLEAR LS_FIELDCAT.
LS_FIELDCAT-TABNAME = 'FILE_LIST'. LS_FIELDCAT-FIELDNAME = 'NAME'. LS_FIELDCAT-SELTEXT_L = 'NAME'. APPEND LS_FIELDCAT TO GT_FIELDCAT. CLEAR LS_FIELDCAT.
LS_FIELDCAT-TABNAME = 'FILE_LIST'. LS_FIELDCAT-FIELDNAME = 'TYPE'. LS_FIELDCAT-SELTEXT_L = 'TYPE'. APPEND LS_FIELDCAT TO GT_FIELDCAT. CLEAR LS_FIELDCAT.
LS_FIELDCAT-TABNAME = 'FILE_LIST'. LS_FIELDCAT-FIELDNAME = 'LEN'. LS_FIELDCAT-SELTEXT_L = 'LEN'. APPEND LS_FIELDCAT TO GT_FIELDCAT. CLEAR LS_FIELDCAT.
LS_FIELDCAT-TABNAME = 'FILE_LIST'. LS_FIELDCAT-FIELDNAME = 'OWNER'. LS_FIELDCAT-SELTEXT_L = 'OWNER'. APPEND LS_FIELDCAT TO GT_FIELDCAT. CLEAR LS_FIELDCAT.
LS_FIELDCAT-TABNAME = 'FILE_LIST'. LS_FIELDCAT-FIELDNAME = 'MTIME'. LS_FIELDCAT-SELTEXT_L = 'MTIME'. APPEND LS_FIELDCAT TO GT_FIELDCAT. CLEAR LS_FIELDCAT.
LS_FIELDCAT-TABNAME = 'FILE_LIST'. LS_FIELDCAT-FIELDNAME = 'MODE'. LS_FIELDCAT-SELTEXT_L = 'MODE'. APPEND LS_FIELDCAT TO GT_FIELDCAT. CLEAR LS_FIELDCAT.
LS_FIELDCAT-TABNAME = 'FILE_LIST'. LS_FIELDCAT-FIELDNAME = 'USEABLE'. LS_FIELDCAT-SELTEXT_L = 'USEABLE'. APPEND LS_FIELDCAT TO GT_FIELDCAT. CLEAR LS_FIELDCAT.
LS_FIELDCAT-TABNAME = 'FILE_LIST'. LS_FIELDCAT-FIELDNAME = 'SUBRC'. LS_FIELDCAT-SELTEXT_L = 'SUBRC'. APPEND LS_FIELDCAT TO GT_FIELDCAT. CLEAR LS_FIELDCAT.
LS_FIELDCAT-TABNAME = 'FILE_LIST'. LS_FIELDCAT-FIELDNAME = 'ERRNO'. LS_FIELDCAT-SELTEXT_L = 'ERRNO'. APPEND LS_FIELDCAT TO GT_FIELDCAT. CLEAR LS_FIELDCAT.
LS_FIELDCAT-TABNAME = 'FILE_LIST'. LS_FIELDCAT-FIELDNAME = 'ERRMSG'. LS_FIELDCAT-SELTEXT_L = 'ERRMSG'. APPEND LS_FIELDCAT TO GT_FIELDCAT. CLEAR LS_FIELDCAT.
LS_FIELDCAT-TABNAME = 'FILE_LIST'. LS_FIELDCAT-FIELDNAME = 'MOD_DATE'. LS_FIELDCAT-SELTEXT_L = 'MOD_DATE'. APPEND LS_FIELDCAT TO GT_FIELDCAT. CLEAR LS_FIELDCAT.
LS_FIELDCAT-TABNAME = 'FILE_LIST'. LS_FIELDCAT-FIELDNAME = 'MOD_TIME'. LS_FIELDCAT-SELTEXT_L = 'MOD_TIME'. APPEND LS_FIELDCAT TO GT_FIELDCAT. CLEAR LS_FIELDCAT.
LS_FIELDCAT-TABNAME = 'FILE_LIST'. LS_FIELDCAT-FIELDNAME = 'SEEN'. LS_FIELDCAT-SELTEXT_L = 'SEEN'. APPEND LS_FIELDCAT TO GT_FIELDCAT. CLEAR LS_FIELDCAT.
LS_FIELDCAT-TABNAME = 'FILE_LIST'. LS_FIELDCAT-FIELDNAME = 'CHANGED'. LS_FIELDCAT-SELTEXT_L = 'CHANGED'. APPEND LS_FIELDCAT TO GT_FIELDCAT. CLEAR LS_FIELDCAT.
gs_layout-zebra = 'X'.
gs_layout-colwidth_optimize = 'X'.
gs_layout-info_fieldname = 'LINE_COLOR'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
i_grid_title = l_grid_title
is_layout = gs_layout
it_fieldcat = gt_fieldcat[]
i_save = 'X'
it_events = git_events[]"alv表头赋值
i_callback_user_command = 'FRM_UCOMM'
TABLES
t_outtab = file_list
EXCEPTIONS
program_error = 1
OTHERS = 2.
endform. "show_file_list
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form frm_ucomm
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM frm_ucomm USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN '&IC1'.
READ TABLE file_list INDEX rs_selfield-tabindex.
IF sy-subrc = 0 AND rs_selfield-fieldname = 'NAME'.
perform down_file.
elseif sy-subrc = 0 AND rs_selfield-fieldname = 'TYPE'.
PERFORM show_file.
ENDIF.
ENDCASE.
ENDFORM. "FRM_UCOMM
*&---------------------------------------------------------------------*
*& Form down_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form down_file.
DATA: dset TYPE string,
subrc LIKE sy-subrc,
leng TYPE i,
pathname type string,
fsize TYPE i VALUE 0,
buf TYPE c LENGTH 1000,
tblob LIKE TABLE OF buf.
* dset = '/home/comp/data/test.pdf'.
CONCATENATE searchpoints-dirname '/' file_list-name into dset.
CONCATENATE 'd:\' file_list-name into pathname .
OPEN DATASET dset FOR INPUT IN BINARY MODE.
IF sy-subrc <> 0.
MESSAGE 'Error: open dataset.' TYPE 'E'.
ENDIF.
WHILE subrc = 0.
leng = 0.
READ DATASET dset INTO buf ACTUAL LENGTH leng.
subrc = sy-subrc.
CHECK leng > 0.
fsize = fsize + leng.
APPEND buf TO tblob.
ENDWHILE.
CLOSE DATASET dset.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = fsize
filename = pathname"'c:\test.pdf'
filetype = 'BIN'
TABLES
data_tab = tblob
EXCEPTIONS
OTHERS = 9.
endform. "down_file
*&---------------------------------------------------------------------*
*& Form fill_file_list
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->A_DIR_NAME text
* -->A_GENERIC_NAME text
* -->A_MUST_CS text
*----------------------------------------------------------------------*
FORM fill_file_list USING a_dir_name a_generic_name a_must_cs.
" Routine von M. Mittelstein
******************************************************************CAS***
* Es wird eine Liste von Dateinamen in die Tabelle FILE_LIST gelesen.
*
* A_DIR_NAME ....... directory name
* A_GENERIC_NAME ... generic filename (may end with *)
* A_MUST_CS ........ a contains pattern for legal filenames OR NO_CS
*
DATA: errcnt(2) TYPE p VALUE 0.
IF a_dir_name IS INITIAL.
MESSAGE e220. " 'Place cursor on valid line !'.
ENDIF.
CALL 'C_DIR_READ_FINISH' " just to be sure
ID 'ERRNO' FIELD file_list-errno
ID 'ERRMSG' FIELD file_list-errmsg.
CALL 'C_DIR_READ_START' ID 'DIR' FIELD a_dir_name
ID 'FILE' FIELD a_generic_name
ID 'ERRNO' FIELD file-errno
ID 'ERRMSG' FIELD file-errmsg.
IF sy-subrc <> 0.
* message i204 with sy-subrc 'C_DIR_READ_START'
* ' ' a_dir_name.
* message i204 with sy-subrc 'C_DIR_READ_START...'
* file-errno file-errmsg.
MESSAGE e204 WITH file_list-errmsg file-errmsg.
ENDIF.
DO.
CLEAR file.
CALL 'C_DIR_READ_NEXT'
ID 'TYPE' FIELD file-type
ID 'NAME' FIELD file-name
ID 'LEN' FIELD file-len
ID 'OWNER' FIELD file-owner
ID 'MTIME' FIELD file-mtime
ID 'MODE' FIELD file-mode
ID 'ERRNO' FIELD file-errno
ID 'ERRMSG' FIELD file-errmsg.
file-dirname = a_dir_name.
MOVE sy-subrc TO file-subrc.
CASE sy-subrc.
WHEN 0.
CLEAR: file-errno, file-errmsg.
CASE file-type(1).
WHEN 'F'. " normal file.
PERFORM filename_useable USING file-name file-useable.
WHEN 'f'. " normal file.
PERFORM filename_useable USING file-name file-useable.
WHEN OTHERS. " directory, device, fifo, socket,...
MOVE sap_no TO file-useable.
ENDCASE.
IF file-len = 0.
MOVE sap_no TO file-useable.
ENDIF.
WHEN 1.
EXIT.
WHEN OTHERS. " SY-SUBRC >= 2
ADD 1 TO errcnt.
IF errcnt > 10.
EXIT.
ENDIF.
IF sy-subrc = 5.
MOVE: '???' TO file-type,
'???' TO file-owner,
'???' TO file-mode.
ELSE.
* ULINE.
* WRITE: / 'C_DIR_READ_NEXT', 'SUBRC', SY-SUBRC.
ENDIF.
MOVE sap_no TO file-useable.
ENDCASE.
PERFORM p6_to_date_time_tz(rstr0400) USING file-mtime
file-mod_time
file-mod_date.
* * Does the filename contains the requested pattern?
* * Then store it, else forget it.
IF a_must_cs = no_cs
.
MOVE-CORRESPONDING file TO file_list.
APPEND file_list.
ELSE.
IF file-name CS a_must_cs.
MOVE-CORRESPONDING file TO file_list.
APPEND file_list.
ENDIF.
ENDIF.
ENDDO.
CALL 'C_DIR_READ_FINISH'
ID 'ERRNO' FIELD file_list-errno
ID 'ERRMSG' FIELD file_list-errmsg.
IF sy-subrc <> 0.
WRITE: / 'C_DIR_READ_FINISH', 'SUBRC', sy-subrc.
ENDIF.
IF srt = 'T'.
SORT file_list BY mtime DESCENDING name ASCENDING.
ELSE.
SORT file_list BY name ASCENDING mtime DESCENDING.
ENDIF.
delete file_list where useable <> 'X'.
ENDFORM. "FILL_FILE_LIST
*&---------------------------------------------------------------------*
*& Form show_file_list
*&---------------------------------------------------------------------*
* text
*----
*EJECT
FORM filename_useable USING a_name a_useable.
*----================------------------------
DATA l_name(75).
l_name = a_name.
IF l_name(4) = 'core'.
a_useable = sap_no.
ELSE.
a_useable = sap_yes.
ENDIF.
ENDFORM. "FILENAME_USEABLE
*&---------------------------------------------------------------------*
*& Form show_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM show_file .
data: buffer(512).
LEAVE TO LIST-PROCESSING.
FORMAT INTENSIFIED OFF.
CONCATENATE FILE_LIST-dirname '/' file_list-name into list_filename .
OPEN DATASET list_filename IN TEXT MODE ENCODING DEFAULT FOR INPUT
IGNORING CONVERSION ERRORS.
IF sy-subrc = 0.
TRY.
DO.
READ DATASET list_filename INTO buffer.
IF sy-subrc <> 0.
EXIT.
ELSE.
IF buffer <> space."added to display blank lines in a file
NEW-LINE.
WRITE AT 1(512) buffer.
ELSE.
SKIP.
ENDIF.
ENDIF.
ENDDO.
CATCH cx_sy_conversion_error.
WRITE: / ' '.
MESSAGE S333 WITH TEXT-023.
ENDTRY.
CLOSE DATASET list_filename.
ELSE.
WRITE: / ' '.
MESSAGE S333 WITH TEXT-018.
ENDIF.
ENDFORM. "show_file
阅读(3898) | 评论(0) | 转发(0) |