免费开源的网站系统搜易网提供的技术服务
有时候需要查找某个具体的内容,在哪个文件内。数据量大的时候可以利用程序查找
选择界面:
路径,和文件名都可以模糊搜查
search string:你要查找的信息。
代码参考如下:
report z00R010 NO STANDARD PAGE HEADING MESSAGE-ID zzLINE-COUNT 65 LINE-SIZE 255.*-----------------------------------------------------------------------
* Tables
*-----------------------------------------------------------------------
tables: z00files.*-----------------------------------------------------------------------
* Selection Screen
*-----------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001 .PArameters: p_Dir type z00files-zto_dir default '/SAPINTER/AG'.
parameters: p_File type z00files-zto_name obligatory.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002 .
parameters: p_text(50) type c obligatory.
SELECTION-SCREEN END OF BLOCK b2.
*Write no text - only file name
parameters: p_ntxt radiobutton group rb1.
*Write First text
parameters: p_ftxt radiobutton group rb1.
*WRite All text
parameters: p_atxt radiobutton group rb1.DATA: gv_infile(200) TYPE c,gv_lines type i,gv_split type c value '/',gv_commndl(500).*internal table for storing filenames to be processed.
data: begin of i_filetab occurs 10,name(500),date(8),time(8),end of i_filetab.data: begin of i_comtab occurs 10,name(500),date(8),time(8),end of i_comtab.data: ipath(100) occurs 0.constants: gc_x value 'X',gc_R value 'R',gc_Y value 'Y',gc_N value 'N'.*-----------------------------------------------------------------------
* Initialization
*-----------------------------------------------------------------------
initialization.
*------------include z01init.
*-----------------------------------------------------------------------
* Start of selection
*-----------------------------------------------------------------------
at SELECTION-SCREEN.if p_file co '* '.message e001 with 'Enter full or partial file name'.endif.start-of-selection.
*----------------WRite: / 'Search Directory:', p_Dir.WRite: / 'Search File Name:', p_file.write: / 'Search Text :', p_Text.if p_nTxt = gc_X.write: / 'Do not display any results - only file names'.elseif p_Ftxt = gc_X.write: / 'Display only first result found'.else.write: / 'Display all results'.endif.*Explore path nameperform open_files.*Check if any founddescribe table i_filetab lines gv_lines.write: / 'Files to check :', gv_lines.*Process files and search for given textif gv_lines > 0.perform process_files.endif.*&---------------------------------------------------------------------*
*& Form open_files
*&---------------------------------------------------------------------*
form open_files.data: lv_fil(50).*find files from given directoryrefresh i_filetab.clear i_filetab.concatenate '\' p_file into lv_fil.concatenate 'find' p_Dir '-name' lv_fil '-printf''''%TY%Tm%Td\t%p\n'''into gv_commndl separated by space.* write :/ gv_commndl.call 'SYSTEM' id 'COMMAND' field gv_commndlid 'TAB' field i_filetab-*sys*.endform. " open_files
*&---------------------------------------------------------------------*
*& Form process-files
*&---------------------------------------------------------------------*
form process_files.data: lv_len type i.data: lv_restname(500) type c.data: lv_name(100) type c.*End of File indicatordata: lv_eof type c.data: lv_open type c.data: lv_Count type i.data: lv_found type c.data: lv_pos type i.data: lv_msg(50) type c.DATA: istring TYPE string.*==================*
*EXPLORE SUBFOLDERS
*==================*
*only consider exact path (ignore main folder)lv_len = strlen( p_dir ) + 1.loop at i_filetab.*No spaces allowed in input file path
* lv_len = strlen( gv_infile ).lv_len = strlen( i_filetab-name ).i_filetab-date = i_filetab-name(8).gv_infile = i_filetab-name+9(lv_len).lv_len = strlen( gv_infile ).if gv_infile(lv_len) ca ' '.lv_msg = 'infile contains spaces'(013).write: / lv_msg, gv_infile.message s001 with lv_msg gv_infile.continue.endif.*======================*
*CHECK STATUS OF INFILE -
*======================*lv_Eof = gc_N.lv_Found = gc_N.open dataset gv_infile for input in text modeencoding default with smart linefeed ignoring conversion errors.if sy-subrc = 0.
*SEarch for text in the file and list if founddo.read dataset gv_infile into istring.if sy-subrc > 0.exit.endif.if istring cs p_text.
*LIst file name firs timeif lv_Found = gc_n.
*underline for text to followif not p_nTxt = gc_X.uline.endif.lv_Found = gc_Y.add 1 to lv_count.write: / 'File Date=', i_filetab-date, 'Name=', gv_Infile.endif.if not p_ntxt = gc_X.write: / istring.endif.*EXit after first record foundif p_ftxt = gc_x.lv_Eof = gc_Y.exit.endif.endif.enddo.close dataset gv_infile.endif.endloop.uline.write: / 'Results found in ', lv_count, 'Files'.uline.endform. " process-files
table:
Field | Data element | Data type | length | decimal | description |
MANDT | MANDT | CLNT | 3 | 0 | Client |
WERKS | WERKS_D | CHAR | 4 | 0 | Plant |
ZFILE | CHAR | 40 | 0 | File description | |
ZFROM_DIR | Z00_DIRECTORY | CHAR | 100 | 0 | Directory Path |
ZTO_DIR | Z00_DIRECTORY | CHAR | 100 | 0 | Directory Path |
ZFROM_NAME | CHAR | 50 | 0 | From File name | |
ZTO_NAME | CHAR | 50 | 0 | To File name | |
ZDIRECTION | Z00_DIRECTION | CHAR | 1 | 0 | Interface Direction |
ZEXPLORE | CHAR | 1 | 0 | Include subfolders | |
ZTIMESTAMP | CHAR | 1 | 0 | Timestamp new file | |
ZAPPEND | CHAR | 1 | 0 | Append to existing file | |
ZREPLACE | CHAR | 1 | 0 | Replace existing file | |
ZSKIP | CHAR | 1 | 0 | Skip if duplicate found | |
ZOWNER | CHAR | 12 | 0 | Notify owner if problems | |
ZSTART | CHAR | 1 | 0 | Start program immediately | |
ZJOBGRP | BTCJOBGRP | CHAR | 12 | 0 | Summary of jobs for a group |
ZJOB | BTCJOB | CHAR | 32 | 0 | Background Job Name |
ZPROG | BTCREP | CHAR | 40 | 0 | Name of internal report for batch job |
ZVAR | BTCVARIANT | CHAR | 14 | 0 | Name of variant within a step |
ZFILE_PAR | CHAR | 8 | 0 | Input file parm in Variant | |
ZBATCH | CHAR | 12 | 0 | Batch User | |
ZINACTIVE | CHAR | 1 | 0 | Set as inactive | |
ZEOF | CHAR | 10 | 0 | End of File indicator | |
ZSAPRET | Z00_SAPRET | NUMC | 4 | 0 | SAPINTER Retention Period |
ZARCH | Z00_ARCH_IND | CHAR | 1 | 0 | Archive Indicator |
ZARCHRET | Z00_ARCHRET | NUMC | 2 | 0 | Archive Retention Period |