程序源代码字符搜索

*----------------------------------------------------------------------*
* Scan a set of reports for a particular string
*----------------------------------------------------------------------*
report rpr_abap_source_scan message-id 56
no standard page heading line-size 150.

tables: d020s,
tadir,
trdir,
tuchk3.

types: begin of result_ln,
repname like sy-repid,
dynnr like sy-dynnr,
line_no(6) type n,
* text like rstxp-tdline,
text type string,
sstring,
end of result_ln,

result_tab type result_ln occurs 0.

data: disptype value 'A',
dtab type result_tab with header line,
ftab type result_tab with header line,
hit_count type i,
tabix like sy-tabix,
* text_line like rstxp-tdline,
text_line type string,
top_flag.

data: begin of dyn occurs 0,
prog like d020s-prog,
dnum like d020s-dnum,
end of dyn,

begin of fm occurs 0,
obj_name like tadir-obj_name,
end of fm,

begin of irdir occurs 50,
name like trdir-name,
end of irdir,

begin of itab occurs 50,
repname like sy-repid,
end of itab,

itab_ii like itab occurs 50 with header line,

begin of rtab occurs 0,
* text like rpy_dyflow-line,
text(1000),
end of rtab,

rtab_lcase like line of rtab,
rtab_tmp like line of rtab.

selection-screen: begin of block a10 with frame title a10.
select-options: repname for trdir-name memory id scan_repid,
dynnr for d020s-dnum,
subc for trdir-subc,
appl for trdir-appl,
cnam for trdir-cnam,
unam for trdir-unam,
devclass for tadir-devclass.
selection-screen: end of block a10,
begin of block a20 with frame title a20.
select-options: sstring for tuchk3-object no intervals.
parameters: plusminu(2) type n default 2,
inclu as checkbox default 'X',
modiass as checkbox,
comment as checkbox,
mask as checkbox.
selection-screen: end of block a20,
begin of block a30 with frame title a30.
parameters: rb_code radiobutton group r10,
rb_dyn radiobutton group r10,
rb_all radiobutton group r10.
selection-screen: end of block a30.

data: string like sstring-low.

initialization.
a10 = 'Report/Dynpro Selektion'(a10).
a20 = 'Suchkriterien'(a20).
a30 = 'Suchbereich'(a30).

top-of-page.
perform top_of_page.

top-of-page during line-selection.
perform top_of_page.

at selection-screen.
if sstring[] is initial and modiass is initial.
message e016 with 'Bitte Suchstring eingeben'(003).
endif.

start-of-selection.
if not modiass is initial.
sstring-sign = 'I'.
sstring-option = 'EQ'.
sstring-low = '{'.
append sstring.
sstring-low = '}'.
append sstring.
endif.

read table sstring index 1.
describe table sstring lines sy-tfill.
if sy-tfill = 1.
string = sstring-low.
else.
concatenate sstring-low
'...'
into string separated by space.
endif.

set pf-status 'MAIN'.

if not devclass[] is initial.
select obj_name into table irdir
from tadir
where pgmid = 'R3TR'
and object = 'PROG'
and devclass in devclass.
"#EC CI_SGLSELECT

select obj_name into table fm
from tadir
where pgmid = 'R3TR'
and object = 'FUGR'
and devclass in devclass.
"#EC CI_SGLSELECT

loop at fm.
concatenate 'SAPL'
fm-obj_name into irdir.
append irdir.
endloop.
endif.

if not repname[] is initial.
select name appending table irdir
from trdir
where name in repname
and cnam in cnam
and unam in unam
and subc in subc
and appl in appl.
endif.

check not irdir[] is initial.

if rb_code is initial.
* Also scan dynpro flow logic
select prog dnum into table dyn
from d020s for all entries in irdir
where prog = irdir-name
and dnum in dynnr.
endif.

if not inclu is initial.
loop at irdir.
refresh itab_ii.
call function 'GET_INCLUDES'
exporting
progname = irdir-name
tables
incltab = itab_ii.

append lines of itab_ii to itab.
endloop.
endif.

append lines of irdir to itab.
sort itab.
delete adjacent duplicates from itab.

if rb_dyn is initial.
loop at itab.
read report itab-repname into rtab.
check sy-subrc = 0.
if not comment is initial.
delete rtab
where text(1) = '*'.
endif.

loop at sstring.
if mask is initial.
search rtab for sstring-low.
check sy-subrc = 0.
else.
sy-tabix = 1.
endif.

loop at rtab from sy-tabix.
tabix = sy-tabix.
rtab_lcase = rtab.
translate rtab to upper case.

case mask.
when space.
if rtab-text cs sstring-low.
perform: get_hit_set using rtab_lcase tabix space.
endif.

when others.
if rtab-text cp sstring-low.
perform: get_hit_set using rtab_lcase tabix space.
endif.
endcase.
endloop.
endloop.
endloop.
endif.

free: itab.

if rb_code is initial.
loop at dyn.
perform get_dynpro_flow_logic.

if not comment is initial.
delete rtab
where text(1) = '*'.
endif.

loop at sstring.
if mask is initial.
search rtab for sstring-low.
check sy-subrc = 0.
else.
sy-tabix = 1.
endif.

loop at rtab from sy-tabix.
tabix = sy-tabix.
rtab_lcase = rtab.
translate rtab to upper case.

case mask.
when space.
if rtab-text cs sstring-low.
perform: get_hit_set using rtab_lcase tabix 'D'.
endif.

when others.
if rtab-text cp sstring-low.
perform: get_hit_set using rtab_lcase tabix 'D'.
endif.
endcase.
endloop.
endloop.
endloop.
endif.

free: dyn.

end-of-selection.
if ftab[] is initial and dtab[] is initial.
message s016 with 'String'(006) string 'nicht gefunden'(m01).
exit.
endif.

sort: ftab by repname line_no sstring descending,
dtab by repname dynnr line_no sstring descending.

delete adjacent duplicates from: ftab comparing repname line_no,
dtab comparing repname dynnr line_no.

message s016 with hit_count 'Treffer f黵 String'(m02) string.

perform: display_ftab_alt,
display_dtab_alt.

at line-selection.
perform call_editor.

at user-command.
case sy-ucomm.
when 'TOGL'.
case disptype.
when 'M'.
disptype = 'A'.
perform: display_ftab_alt,
display_dtab_alt.
when 'A'.
disptype = 'M'.
perform: display_ftab,
display_dtab.
endcase.
sy-lsind = sy-lsind - 1.
endcase.

*---------------------------------------------------------------------*
* FORM APPEND_FTAB *
*---------------------------------------------------------------------*
form append_ftab using text like rtab_lcase
line_no like sy-tabix
sstring type c
source type c.

data: ln type result_ln.

ln-line_no = line_no.
ln-text = text.
ln-sstring = sstring.

if source is initial.
ln-repname = itab-repname.
append ln to ftab.
else.
ln-repname = dyn-prog.
ln-dynnr = dyn-dnum.
append ln to dtab.
clear: ln-dynnr.
endif.

if not ln-sstring is initial.
add 1 to hit_count.
endif.
endform.

*---------------------------------------------------------------------*
* FORM TOP_OF_PAGE *
*---------------------------------------------------------------------*
form top_of_page.
data: repname(50).

format intensified off.
uline /(150).
write: / sy-vline,
'Source Scan f黵 String:'(h01),
string color col_total,
48 'Datum:'(t01),
sy-datum dd/mm/yyyy,
66 'Zeit:'(t02),
sy-uzeit,
150 sy-vline.
uline /(150).
format intensified on.
write: / sy-vline.

if top_flag = 'A'.
repname = ftab-repname.
else.
concatenate dtab-repname
'Dynpro'(004)
dtab-dynnr
into repname separated by space.
endif.

case disptype.
when 'A'.
concatenate 'Zeile Source Code ('(001)
repname
')' into text_line.
write: text_line.
when 'M'.
if top_flag = 'A'.
write: 'Source Code ...'(002).
else.
write: 'Source Code ...'(005).
endif.
endcase.
write: 150 sy-vline.
uline (150).
endform.
*---------------------------------------------------------------------*
* FORM DISPLAY_FTAB *
*---------------------------------------------------------------------*
* Display search results
*---------------------------------------------------------------------*
form display_ftab.
check rb_dyn is initial.

top_flag = 'A'.

new-page.

loop at ftab.
format hotspot on.
if ftab-sstring is initial.
write: / sy-vline,
ftab-text intensified off.
else.
write: / sy-vline,
ftab-text intensified off color col_total.
endif.
write: sy-vline no-gap,
ftab-line_no no-gap intensified,
sy-vline no-gap,
ftab-repname no-gap intensified,
150 sy-vline no-gap.

hide: ftab-repname,
ftab-line_no.

at end of repname.
format hotspot off.
uline /(150).
endat.
endloop.
endform.
*---------------------------------------------------------------------*
* FORM DISPLAY_DTAB *
*---------------------------------------------------------------------*
* Display search results (dynpro)
*---------------------------------------------------------------------*
form display_dtab.
check rb_code is initial.

top_flag = 'D'.

new-page.

loop at dtab.
format hotspot on.
if dtab-sstring is initial.
write: / sy-vline,
dtab-text intensified off.
else.
write: / sy-vline,
dtab-text intensified off color col_total.
endif.
write: sy-vline no-gap,
dtab-line_no no-gap intensified,
sy-vline no-gap,
dtab-repname no-gap intensified,
dtab-dynnr no-gap intensified,
150 sy-vline no-gap.

hide: dtab-repname,
dtab-dynnr,
dtab-line_no.

at end of repname.
format hotspot off.
uline /(150).
endat.
endloop.
endform.

*---------------------------------------------------------------------*
* FORM DISPLAY_FTAB_ALT
*---------------------------------------------------------------------*
* Display hit list without report name on every line
*---------------------------------------------------------------------*
form display_ftab_alt.
check rb_dyn is initial.

top_flag = 'A'.

new-page.

loop at ftab.

at new repname.
format hotspot on.
if sy-tabix > 1.
new-page.
endif.
endat.

write: / sy-vline no-gap,
ftab-line_no no-gap,
sy-vline no-gap.

if ftab-sstring is initial.
write: ftab-text intensified off.
else.
write: ftab-text intensified off color col_total.
endif.

write: 150 sy-vline.

hide: ftab-repname,
ftab-line_no.

at end of repname.
format hotspot off.
uline /(150).
endat.
endloop.
endform.
*---------------------------------------------------------------------*
* FORM DISPLAY_DTAB_ALT
*---------------------------------------------------------------------*
* Display dynpro hit list without report name on every line
*---------------------------------------------------------------------*
form display_dtab_alt.
check rb_code is initial.

top_flag = 'D'.

new-page.

loop at dtab.

at new repname.
format hotspot on.
if sy-tabix > 1.
new-page.
endif.
endat.

write: / sy-vline no-gap,
dtab-line_no no-gap,
sy-vline no-gap.

if dtab-sstring is initial.
write: dtab-text intensified off.
else.
write: dtab-text intensified off color col_total.
endif.

write: 150 sy-vline.

hide: dtab-repname,
dtab-dynnr,
dtab-line_no.

at end of repname.
format hotspot off.
uline /(150).
endat.
endloop.
endform.
*----------------------------------------------------------------------*
* Form GET_PLUS_MINUS_X_LINES
*----------------------------------------------------------------------*
* Get x lines before the found string and x lines after
*----------------------------------------------------------------------*
form get_hit_set using value(ctext) like rtab_lcase
value(line_no) like sy-tabix
srce_type type c.

data: end type i,
start type i,
xtabix like sy-tabix.

if plusminu <= 0.
perform append_ftab using ctext line_no 'X' srce_type.
exit.
endif.

start = line_no - plusminu .
end = line_no + plusminu.

if start < 1.
start = 1.
endif.

while start <= end.
read table rtab into ctext index start.
if sy-subrc <> 0.
exit.
endif.
xtabix = sy-tabix.
if start = line_no.
perform append_ftab using ctext xtabix 'X' srce_type.
else.
perform append_ftab using ctext xtabix space srce_type.
endif.
add 1 to start.
endwhile.
endform. " GET_HIT_SET
*----------------------------------------------------------------------*
* Form CALL_EDITOR
*----------------------------------------------------------------------*
* Call ABAP or screen painter editor
*----------------------------------------------------------------------*
form call_editor.
clear: ftab,
dtab.

read line sy-lilli
field value ftab-repname
ftab-line_no
dtab-repname
dtab-dynnr
dtab-line_no.

if ftab-repname is initial and dtab-repname is initial.
message s016 with 'Ung黮tige Cursor Position'(m03).
exit.
endif.

if dtab-dynnr is initial.
* Call ABAP editor
call function 'EDITOR_PROGRAM'
exporting
display = 'X'
program = ftab-repname
topline = ftab-line_no
exceptions
others = 1.

set parameter id 'RID' field sy-repid.
else.
call function 'RS_SCRP'
exporting
abl_line = dtab-line_no
dynnr = dtab-dynnr
progname = dtab-repname
wanted_mode = 'SHOW'
exceptions
already_exists = 1
not_found = 2
not_executed = 3
others = 4.
endif.
endform. " CALL_EDITOR
*---------------------------------------------------------------------*
* Form GET_DYNPRO_FLOW_LOGIC
*----------------------------------------------------------------------*
* Get flow logic of the dynpro
*----------------------------------------------------------------------*
form get_dynpro_flow_logic.
data: dhead like d020s,
dfield like d021s occurs 0,
dflow like d022s occurs 0,
dmatch like d023s occurs 0,

begin of dynp_id,
prog like d020s-prog,
dnum like d020s-dnum,
end of dynp_id.

dynp_id-prog = dyn-prog.
dynp_id-dnum = dyn-dnum.

import dynpro dhead dfield dflow dmatch id dynp_id.

rtab[] = dflow[].
endform. " GET_DYNPRO_FLOW_LOGIC
*----------------------------------------------------------------------*
* Scan a set of reports for a particular string
*----------------------------------------------------------------------*
report rpr_abap_source_scan message-id 56
no standard page heading line-size 150.

tables: d020s,
tadir,
trdir,
tuchk3.

types: begin of result_ln,
repname like sy-repid,
dynnr like sy-dynnr,
line_no(6) type n,
* text like rstxp-tdline,
text type string,
sstring,
end of result_ln,

result_tab type result_ln occurs 0.

data: disptype value 'A',
dtab type result_tab with header line,
ftab type result_tab with header line,
hit_count type i,
tabix like sy-tabix,
* text_line like rstxp-tdline,
text_line type string,
top_flag.

data: begin of dyn occurs 0,
prog like d020s-prog,
dnum like d020s-dnum,
end of dyn,

begin of fm occurs 0,
obj_name like tadir-obj_name,
end of fm,

begin of irdir occurs 50,
name like trdir-name,
end of irdir,

begin of itab occurs 50,
repname like sy-repid,
end of itab,

itab_ii like itab occurs 50 with header line,

begin of rtab occurs 0,
* text like rpy_dyflow-line,
text(1000),
end of rtab,

rtab_lcase like line of rtab,
rtab_tmp like line of rtab.

selection-screen: begin of block a10 with frame title a10.
select-options: repname for trdir-name memory id scan_repid,
dynnr for d020s-dnum,
subc for trdir-subc,
appl for trdir-appl,
cnam for trdir-cnam,
unam for trdir-unam,
devclass for tadir-devclass.
selection-screen: end of block a10,
begin of block a20 with frame title a20.
select-options: sstring for tuchk3-object no intervals.
parameters: plusminu(2) type n default 2,
inclu as checkbox default 'X',
modiass as checkbox,
comment as checkbox,
mask as checkbox.
selection-screen: end of block a20,
begin of block a30 with frame title a30.
parameters: rb_code radiobutton group r10,
rb_dyn radiobutton group r10,
rb_all radiobutton group r10.
selection-screen: end of block a30.

data: string like sstring-low.

initialization.
a10 = 'Report/Dynpro Selektion'(a10).
a20 = 'Suchkriterien'(a20).
a30 = 'Suchbereich'(a30).

top-of-page.
perform top_of_page.

top-of-page during line-selection.
perform top_of_page.

at selection-screen.
if sstring[] is initial and modiass is initial.
message e016 with 'Bitte Suchstring eingeben'(003).
endif.

start-of-selection.
if not modiass is initial.
sstring-sign = 'I'.
sstring-option = 'EQ'.
sstring-low = '{'.
append sstring.
sstring-low = '}'.
append sstring.
endif.

read table sstring index 1.
describe table sstring lines sy-tfill.
if sy-tfill = 1.
string = sstring-low.
else.
concatenate sstring-low
'...'
into string separated by space.
endif.

set pf-status 'MAIN'.

if not devclass[] is initial.
select obj_name into table irdir
from tadir
where pgmid = 'R3TR'
and object = 'PROG'
and devclass in devclass.
"#EC CI_SGLSELECT

select obj_name into table fm
from tadir
where pgmid = 'R3TR'
and object = 'FUGR'
and devclass in devclass.
"#EC CI_SGLSELECT

loop at fm.
concatenate 'SAPL'
fm-obj_name into irdir.
append irdir.
endloop.
endif.

if not repname[] is initial.
select name appending table irdir
from trdir
where name in repname
and cnam in cnam
and unam in unam
and subc in subc
and appl in appl.
endif.

check not irdir[] is initial.

if rb_code is initial.
* Also scan dynpro flow logic
select prog dnum into table dyn
from d020s for all entries in irdir
where prog = irdir-name
and dnum in dynnr.
endif.

if not inclu is initial.
loop at irdir.
refresh itab_ii.
call function 'GET_INCLUDES'
exporting
progname = irdir-name
tables
incltab = itab_ii.

append lines of itab_ii to itab.
endloop.
endif.

append lines of irdir to itab.
sort itab.
delete adjacent duplicates from itab.

if rb_dyn is initial.
loop at itab.
read report itab-repname into rtab.
check sy-subrc = 0.
if not comment is initial.
delete rtab
where text(1) = '*'.
endif.

loop at sstring.
if mask is initial.
search rtab for sstring-low.
check sy-subrc = 0.
else.
sy-tabix = 1.
endif.

loop at rtab from sy-tabix.
tabix = sy-tabix.
rtab_lcase = rtab.
translate rtab to upper case.

case mask.
when space.
if rtab-text cs sstring-low.
perform: get_hit_set using rtab_lcase tabix space.
endif.

when others.
if rtab-text cp sstring-low.
perform: get_hit_set using rtab_lcase tabix space.
endif.
endcase.
endloop.
endloop.
endloop.
endif.

free: itab.

if rb_code is initial.
loop at dyn.
perform get_dynpro_flow_logic.

if not comment is initial.
delete rtab
where text(1) = '*'.
endif.

loop at sstring.
if mask is initial.
search rtab for sstring-low.
check sy-subrc = 0.
else.
sy-tabix = 1.
endif.

loop at rtab from sy-tabix.
tabix = sy-tabix.
rtab_lcase = rtab.
translate rtab to upper case.

case mask.
when space.
if rtab-text cs sstring-low.
perform: get_hit_set using rtab_lcase tabix 'D'.
endif.

when others.
if rtab-text cp sstring-low.
perform: get_hit_set using rtab_lcase tabix 'D'.
endif.
endcase.
endloop.
endloop.
endloop.
endif.

free: dyn.

end-of-selection.
if ftab[] is initial and dtab[] is initial.
message s016 with 'String'(006) string 'nicht gefunden'(m01).
exit.
endif.

sort: ftab by repname line_no sstring descending,
dtab by repname dynnr line_no sstring descending.

delete adjacent duplicates from: ftab comparing repname line_no,
dtab comparing repname dynnr line_no.

message s016 with hit_count 'Treffer f黵 String'(m02) string.

perform: display_ftab_alt,
display_dtab_alt.

at line-selection.
perform call_editor.

at user-command.
case sy-ucomm.
when 'TOGL'.
case disptype.
when 'M'.
disptype = 'A'.
perform: display_ftab_alt,
display_dtab_alt.
when 'A'.
disptype = 'M'.
perform: display_ftab,
display_dtab.
endcase.
sy-lsind = sy-lsind - 1.
endcase.

*---------------------------------------------------------------------*
* FORM APPEND_FTAB *
*---------------------------------------------------------------------*
form append_ftab using text like rtab_lcase
line_no like sy-tabix
sstring type c
source type c.

data: ln type result_ln.

ln-line_no = line_no.
ln-text = text.
ln-sstring = sstring.

if source is initial.
ln-repname = itab-repname.
append ln to ftab.
else.
ln-repname = dyn-prog.
ln-dynnr = dyn-dnum.
append ln to dtab.
clear: ln-dynnr.
endif.

if not ln-sstring is initial.
add 1 to hit_count.
endif.
endform.

*---------------------------------------------------------------------*
* FORM TOP_OF_PAGE *
*---------------------------------------------------------------------*
form top_of_page.
data: repname(50).

format intensified off.
uline /(150).
write: / sy-vline,
'Source Scan f黵 String:'(h01),
string color col_total,
48 'Datum:'(t01),
sy-datum dd/mm/yyyy,
66 'Zeit:'(t02),
sy-uzeit,
150 sy-vline.
uline /(150).
format intensified on.
write: / sy-vline.

if top_flag = 'A'.
repname = ftab-repname.
else.
concatenate dtab-repname
'Dynpro'(004)
dtab-dynnr
into repname separated by space.
endif.

case disptype.
when 'A'.
concatenate 'Zeile Source Code ('(001)
repname
')' into text_line.
write: text_line.
when 'M'.
if top_flag = 'A'.
write: 'Source Code ...'(002).
else.
write: 'Source Code ...'(005).
endif.
endcase.
write: 150 sy-vline.
uline (150).
endform.
*---------------------------------------------------------------------*
* FORM DISPLAY_FTAB *
*---------------------------------------------------------------------*
* Display search results
*---------------------------------------------------------------------*
form display_ftab.
check rb_dyn is initial.

top_flag = 'A'.

new-page.

loop at ftab.
format hotspot on.
if ftab-sstring is initial.
write: / sy-vline,
ftab-text intensified off.
else.
write: / sy-vline,
ftab-text intensified off color col_total.
endif.
write: sy-vline no-gap,
ftab-line_no no-gap intensified,
sy-vline no-gap,
ftab-repname no-gap intensified,
150 sy-vline no-gap.

hide: ftab-repname,
ftab-line_no.

at end of repname.
format hotspot off.
uline /(150).
endat.
endloop.
endform.
*---------------------------------------------------------------------*
* FORM DISPLAY_DTAB *
*---------------------------------------------------------------------*
* Display search results (dynpro)
*---------------------------------------------------------------------*
form display_dtab.
check rb_code is initial.

top_flag = 'D'.

new-page.

loop at dtab.
format hotspot on.
if dtab-sstring is initial.
write: / sy-vline,
dtab-text intensified off.
else.
write: / sy-vline,
dtab-text intensified off color col_total.
endif.
write: sy-vline no-gap,
dtab-line_no no-gap intensified,
sy-vline no-gap,
dtab-repname no-gap intensified,
dtab-dynnr no-gap intensified,
150 sy-vline no-gap.

hide: dtab-repname,
dtab-dynnr,
dtab-line_no.

at end of repname.
format hotspot off.
uline /(150).
endat.
endloop.
endform.

*---------------------------------------------------------------------*
* FORM DISPLAY_FTAB_ALT
*---------------------------------------------------------------------*
* Display hit list without report name on every line
*---------------------------------------------------------------------*
form display_ftab_alt.
check rb_dyn is initial.

top_flag = 'A'.

new-page.

loop at ftab.

at new repname.
format hotspot on.
if sy-tabix > 1.
new-page.
endif.
endat.

write: / sy-vline no-gap,
ftab-line_no no-gap,
sy-vline no-gap.

if ftab-sstring is initial.
write: ftab-text intensified off.
else.
write: ftab-text intensified off color col_total.
endif.

write: 150 sy-vline.

hide: ftab-repname,
ftab-line_no.

at end of repname.
format hotspot off.
uline /(150).
endat.
endloop.
endform.
*---------------------------------------------------------------------*
* FORM DISPLAY_DTAB_ALT
*---------------------------------------------------------------------*
* Display dynpro hit list without report name on every line
*---------------------------------------------------------------------*
form display_dtab_alt.
check rb_code is initial.

top_flag = 'D'.

new-page.

loop at dtab.

at new repname.
format hotspot on.
if sy-tabix > 1.
new-page.
endif.
endat.

write: / sy-vline no-gap,
dtab-line_no no-gap,
sy-vline no-gap.

if dtab-sstring is initial.
write: dtab-text intensified off.
else.
write: dtab-text intensified off color col_total.
endif.

write: 150 sy-vline.

hide: dtab-repname,
dtab-dynnr,
dtab-line_no.

at end of repname.
format hotspot off.
uline /(150).
endat.
endloop.
endform.
*----------------------------------------------------------------------*
* Form GET_PLUS_MINUS_X_LINES
*----------------------------------------------------------------------*
* Get x lines before the found string and x lines after
*----------------------------------------------------------------------*
form get_hit_set using value(ctext) like rtab_lcase
value(line_no) like sy-tabix
srce_type type c.

data: end type i,
start type i,
xtabix like sy-tabix.

if plusminu <= 0.
perform append_ftab using ctext line_no 'X' srce_type.
exit.
endif.

start = line_no - plusminu .
end = line_no + plusminu.

if start < 1.
start = 1.
endif.

while start <= end.
read table rtab into ctext index start.
if sy-subrc <> 0.
exit.
endif.
xtabix = sy-tabix.
if start = line_no.
perform append_ftab using ctext xtabix 'X' srce_type.
else.
perform append_ftab using ctext xtabix space srce_type.
endif.
add 1 to start.
endwhile.
endform. " GET_HIT_SET
*----------------------------------------------------------------------*
* Form CALL_EDITOR
*----------------------------------------------------------------------*
* Call ABAP or screen painter editor
*----------------------------------------------------------------------*
form call_editor.
clear: ftab,
dtab.

read line sy-lilli
field value ftab-repname
ftab-line_no
dtab-repname
dtab-dynnr
dtab-line_no.

if ftab-repname is initial and dtab-repname is initial.
message s016 with 'Ung黮tige Cursor Position'(m03).
exit.
endif.

if dtab-dynnr is initial.
* Call ABAP editor
call function 'EDITOR_PROGRAM'
exporting
display = 'X'
program = ftab-repname
topline = ftab-line_no
exceptions
others = 1.

set parameter id 'RID' field sy-repid.
else.
call function 'RS_SCRP'
exporting
abl_line = dtab-line_no
dynnr = dtab-dynnr
progname = dtab-repname
wanted_mode = 'SHOW'
exceptions
already_exists = 1
not_found = 2
not_executed = 3
others = 4.
endif.
endform. " CALL_EDITOR
*---------------------------------------------------------------------*
* Form GET_DYNPRO_FLOW_LOGIC
*----------------------------------------------------------------------*
* Get flow logic of the dynpro
*----------------------------------------------------------------------*
form get_dynpro_flow_logic.
data: dhead like d020s,
dfield like d021s occurs 0,
dflow like d022s occurs 0,
dmatch like d023s occurs 0,

begin of dynp_id,
prog like d020s-prog,
dnum like d020s-dnum,
end of dynp_id.

dynp_id-prog = dyn-prog.
dynp_id-dnum = dyn-dnum.

import dynpro dhead dfield dflow dmatch id dynp_id.

rtab[] = dflow[].
endform. " GET_DYNPRO_FLOW_LOGIC
*----------------------------------------------------------------------*
* Scan a set of reports for a particular string
*----------------------------------------------------------------------*
report rpr_abap_source_scan message-id 56
no standard page heading line-size 150.

tables: d020s,
tadir,
trdir,
tuchk3.

types: begin of result_ln,
repname like sy-repid,
dynnr like sy-dynnr,
line_no(6) type n,
* text like rstxp-tdline,
text type string,
sstring,
end of result_ln,

result_tab type result_ln occurs 0.

data: disptype value 'A',
dtab type result_tab with header line,
ftab type result_tab with header line,
hit_count type i,
tabix like sy-tabix,
* text_line like rstxp-tdline,
text_line type string,
top_flag.

data: begin of dyn occurs 0,
prog like d020s-prog,
dnum like d020s-dnum,
end of dyn,

begin of fm occurs 0,
obj_name like tadir-obj_name,
end of fm,

begin of irdir occurs 50,
name like trdir-name,
end of irdir,

begin of itab occurs 50,
repname like sy-repid,
end of itab,

itab_ii like itab occurs 50 with header line,

begin of rtab occurs 0,
* text like rpy_dyflow-line,
text(1000),
end of rtab,

rtab_lcase like line of rtab,
rtab_tmp like line of rtab.

selection-screen: begin of block a10 with frame title a10.
select-options: repname for trdir-name memory id scan_repid,
dynnr for d020s-dnum,
subc for trdir-subc,
appl for trdir-appl,
cnam for trdir-cnam,
unam for trdir-unam,
devclass for tadir-devclass.
selection-screen: end of block a10,
begin of block a20 with frame title a20.
select-options: sstring for tuchk3-object no intervals.
parameters: plusminu(2) type n default 2,
inclu as checkbox default 'X',
modiass as checkbox,
comment as checkbox,
mask as checkbox.
selection-screen: end of block a20,
begin of block a30 with frame title a30.
parameters: rb_code radiobutton group r10,
rb_dyn radiobutton group r10,
rb_all radiobutton group r10.
selection-screen: end of block a30.

data: string like sstring-low.

initialization.
a10 = 'Report/Dynpro Selektion'(a10).
a20 = 'Suchkriterien'(a20).
a30 = 'Suchbereich'(a30).

top-of-page.
perform top_of_page.

top-of-page during line-selection.
perform top_of_page.

at selection-screen.
if sstring[] is initial and modiass is initial.
message e016 with 'Bitte Suchstring eingeben'(003).
endif.

start-of-selection.
if not modiass is initial.
sstring-sign = 'I'.
sstring-option = 'EQ'.
sstring-low = '{'.
append sstring.
sstring-low = '}'.
append sstring.
endif.

read table sstring index 1.
describe table sstring lines sy-tfill.
if sy-tfill = 1.
string = sstring-low.
else.
concatenate sstring-low
'...'
into string separated by space.
endif.

set pf-status 'MAIN'.

if not devclass[] is initial.
select obj_name into table irdir
from tadir
where pgmid = 'R3TR'
and object = 'PROG'
and devclass in devclass.
"#EC CI_SGLSELECT

select obj_name into table fm
from tadir
where pgmid = 'R3TR'
and object = 'FUGR'
and devclass in devclass.
"#EC CI_SGLSELECT

loop at fm.
concatenate 'SAPL'
fm-obj_name into irdir.
append irdir.
endloop.
endif.

if not repname[] is initial.
select name appending table irdir
from trdir
where name in repname
and cnam in cnam
and unam in unam
and subc in subc
and appl in appl.
endif.

check not irdir[] is initial.

if rb_code is initial.
* Also scan dynpro flow logic
select prog dnum into table dyn
from d020s for all entries in irdir
where prog = irdir-name
and dnum in dynnr.
endif.

if not inclu is initial.
loop at irdir.
refresh itab_ii.
call function 'GET_INCLUDES'
exporting
progname = irdir-name
tables
incltab = itab_ii.

append lines of itab_ii to itab.
endloop.
endif.

append lines of irdir to itab.
sort itab.
delete adjacent duplicates from itab.

if rb_dyn is initial.
loop at itab.
read report itab-repname into rtab.
check sy-subrc = 0.
if not comment is initial.
delete rtab
where text(1) = '*'.
endif.

loop at sstring.
if mask is initial.
search rtab for sstring-low.
check sy-subrc = 0.
else.
sy-tabix = 1.
endif.

loop at rtab from sy-tabix.
tabix = sy-tabix.
rtab_lcase = rtab.
translate rtab to upper case.

case mask.
when space.
if rtab-text cs sstring-low.
perform: get_hit_set using rtab_lcase tabix space.
endif.

when others.
if rtab-text cp sstring-low.
perform: get_hit_set using rtab_lcase tabix space.
endif.
endcase.
endloop.
endloop.
endloop.
endif.

free: itab.

if rb_code is initial.
loop at dyn.
perform get_dynpro_flow_logic.

if not comment is initial.
delete rtab
where text(1) = '*'.
endif.

loop at sstring.
if mask is initial.
search rtab for sstring-low.
check sy-subrc = 0.
else.
sy-tabix = 1.
endif.

loop at rtab from sy-tabix.
tabix = sy-tabix.
rtab_lcase = rtab.
translate rtab to upper case.

case mask.
when space.
if rtab-text cs sstring-low.
perform: get_hit_set using rtab_lcase tabix 'D'.
endif.

when others.
if rtab-text cp sstring-low.
perform: get_hit_set using rtab_lcase tabix 'D'.
endif.
endcase.
endloop.
endloop.
endloop.
endif.

free: dyn.

end-of-selection.
if ftab[] is initial and dtab[] is initial.
message s016 with 'String'(006) string 'nicht gefunden'(m01).
exit.
endif.

sort: ftab by repname line_no sstring descending,
dtab by repname dynnr line_no sstring descending.

delete adjacent duplicates from: ftab comparing repname line_no,
dtab comparing repname dynnr line_no.

message s016 with hit_count 'Treffer f黵 String'(m02) string.

perform: display_ftab_alt,
display_dtab_alt.

at line-selection.
perform call_editor.

at user-command.
case sy-ucomm.
when 'TOGL'.
case disptype.
when 'M'.
disptype = 'A'.
perform: display_ftab_alt,
display_dtab_alt.
when 'A'.
disptype = 'M'.
perform: display_ftab,
display_dtab.
endcase.
sy-lsind = sy-lsind - 1.
endcase.

*---------------------------------------------------------------------*
* FORM APPEND_FTAB *
*---------------------------------------------------------------------*
form append_ftab using text like rtab_lcase
line_no like sy-tabix
sstring type c
source type c.

data: ln type result_ln.

ln-line_no = line_no.
ln-text = text.
ln-sstring = sstring.

if source is initial.
ln-repname = itab-repname.
append ln to ftab.
else.
ln-repname = dyn-prog.
ln-dynnr = dyn-dnum.
append ln to dtab.
clear: ln-dynnr.
endif.

if not ln-sstring is initial.
add 1 to hit_count.
endif.
endform.

*---------------------------------------------------------------------*
* FORM TOP_OF_PAGE *
*---------------------------------------------------------------------*
form top_of_page.
data: repname(50).

format intensified off.
uline /(150).
write: / sy-vline,
'Source Scan f黵 String:'(h01),
string color col_total,
48 'Datum:'(t01),
sy-datum dd/mm/yyyy,
66 'Zeit:'(t02),
sy-uzeit,
150 sy-vline.
uline /(150).
format intensified on.
write: / sy-vline.

if top_flag = 'A'.
repname = ftab-repname.
else.
concatenate dtab-repname
'Dynpro'(004)
dtab-dynnr
into repname separated by space.
endif.

case disptype.
when 'A'.
concatenate 'Zeile Source Code ('(001)
repname
')' into text_line.
write: text_line.
when 'M'.
if top_flag = 'A'.
write: 'Source Code ...'(002).
else.
write: 'Source Code ...'(005).
endif.
endcase.
write: 150 sy-vline.
uline (150).
endform.
*---------------------------------------------------------------------*
* FORM DISPLAY_FTAB *
*---------------------------------------------------------------------*
* Display search results
*---------------------------------------------------------------------*
form display_ftab.
check rb_dyn is initial.

top_flag = 'A'.

new-page.

loop at ftab.
format hotspot on.
if ftab-sstring is initial.
write: / sy-vline,
ftab-text intensified off.
else.
write: / sy-vline,
ftab-text intensified off color col_total.
endif.
write: sy-vline no-gap,
ftab-line_no no-gap intensified,
sy-vline no-gap,
ftab-repname no-gap intensified,
150 sy-vline no-gap.

hide: ftab-repname,
ftab-line_no.

at end of repname.
format hotspot off.
uline /(150).
endat.
endloop.
endform.
*---------------------------------------------------------------------*
* FORM DISPLAY_DTAB *
*---------------------------------------------------------------------*
* Display search results (dynpro)
*---------------------------------------------------------------------*
form display_dtab.
check rb_code is initial.

top_flag = 'D'.

new-page.

loop at dtab.
format hotspot on.
if dtab-sstring is initial.
write: / sy-vline,
dtab-text intensified off.
else.
write: / sy-vline,
dtab-text intensified off color col_total.
endif.
write: sy-vline no-gap,
dtab-line_no no-gap intensified,
sy-vline no-gap,
dtab-repname no-gap intensified,
dtab-dynnr no-gap intensified,
150 sy-vline no-gap.

hide: dtab-repname,
dtab-dynnr,
dtab-line_no.

at end of repname.
format hotspot off.
uline /(150).
endat.
endloop.
endform.

*---------------------------------------------------------------------*
* FORM DISPLAY_FTAB_ALT
*---------------------------------------------------------------------*
* Display hit list without report name on every line
*---------------------------------------------------------------------*
form display_ftab_alt.
check rb_dyn is initial.

top_flag = 'A'.

new-page.

loop at ftab.

at new repname.
format hotspot on.
if sy-tabix > 1.
new-page.
endif.
endat.

write: / sy-vline no-gap,
ftab-line_no no-gap,
sy-vline no-gap.

if ftab-sstring is initial.
write: ftab-text intensified off.
else.
write: ftab-text intensified off color col_total.
endif.

write: 150 sy-vline.

hide: ftab-repname,
ftab-line_no.

at end of repname.
format hotspot off.
uline /(150).
endat.
endloop.
endform.
*---------------------------------------------------------------------*
* FORM DISPLAY_DTAB_ALT
*---------------------------------------------------------------------*
* Display dynpro hit list without report name on every line
*---------------------------------------------------------------------*
form display_dtab_alt.
check rb_code is initial.

top_flag = 'D'.

new-page.

loop at dtab.

at new repname.
format hotspot on.
if sy-tabix > 1.
new-page.
endif.
endat.

write: / sy-vline no-gap,
dtab-line_no no-gap,
sy-vline no-gap.

if dtab-sstring is initial.
write: dtab-text intensified off.
else.
write: dtab-text intensified off color col_total.
endif.

write: 150 sy-vline.

hide: dtab-repname,
dtab-dynnr,
dtab-line_no.

at end of repname.
format hotspot off.
uline /(150).
endat.
endloop.
endform.
*----------------------------------------------------------------------*
* Form GET_PLUS_MINUS_X_LINES
*----------------------------------------------------------------------*
* Get x lines before the found string and x lines after
*----------------------------------------------------------------------*
form get_hit_set using value(ctext) like rtab_lcase
value(line_no) like sy-tabix
srce_type type c.

data: end type i,
start type i,
xtabix like sy-tabix.

if plusminu <= 0.
perform append_ftab using ctext line_no 'X' srce_type.
exit.
endif.

start = line_no - plusminu .
end = line_no + plusminu.

if start < 1.
start = 1.
endif.

while start <= end.
read table rtab into ctext index start.
if sy-subrc <> 0.
exit.
endif.
xtabix = sy-tabix.
if start = line_no.
perform append_ftab using ctext xtabix 'X' srce_type.
else.
perform append_ftab using ctext xtabix space srce_type.
endif.
add 1 to start.
endwhile.
endform. " GET_HIT_SET
*----------------------------------------------------------------------*
* Form CALL_EDITOR
*----------------------------------------------------------------------*
* Call ABAP or screen painter editor
*----------------------------------------------------------------------*
form call_editor.
clear: ftab,
dtab.

read line sy-lilli
field value ftab-repname
ftab-line_no
dtab-repname
dtab-dynnr
dtab-line_no.

if ftab-repname is initial and dtab-repname is initial.
message s016 with 'Ung黮tige Cursor Position'(m03).
exit.
endif.

if dtab-dynnr is initial.
* Call ABAP editor
call function 'EDITOR_PROGRAM'
exporting
display = 'X'
program = ftab-repname
topline = ftab-line_no
exceptions
others = 1.

set parameter id 'RID' field sy-repid.
else.
call function 'RS_SCRP'
exporting
abl_line = dtab-line_no
dynnr = dtab-dynnr
progname = dtab-repname
wanted_mode = 'SHOW'
exceptions
already_exists = 1
not_found = 2
not_executed = 3
others = 4.
endif.
endform. " CALL_EDITOR
*---------------------------------------------------------------------*
* Form GET_DYNPRO_FLOW_LOGIC
*----------------------------------------------------------------------*
* Get flow logic of the dynpro
*----------------------------------------------------------------------*
form get_dynpro_flow_logic.
data: dhead like d020s,
dfield like d021s occurs 0,
dflow like d022s occurs 0,
dmatch like d023s occurs 0,

begin of dynp_id,
prog like d020s-prog,
dnum like d020s-dnum,
end of dynp_id.

dynp_id-prog = dyn-prog.
dynp_id-dnum = dyn-dnum.

import dynpro dhead dfield dflow dmatch id dynp_id.

rtab[] = dflow[].
endform. " GET_DYNPRO_FLOW_LOGIC

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值