Sie sind auf Seite 1von 8

ABAP Flow Chart Maker

This is a program, which reads any ABAP report, and can create a flowchart out of it. Its helpful for any
developer, who has to create a technical specification document. I have tested with the reports existing
in our system, and it seems to work fine. Please let me know if you face any issues, while using this.
Make sure to validate the flowchart created by the program, before attaching it to the technical
specification document.
Handles:

Events
Function Calls
Subroutine Calls
Method Calls
Module Pools

Sample Output:

Code:
report flow_chart.
include lcnetdat.
include lcnetcon.

"allg. Datendeklarationen
"Konstanten

*----------------------------------------------------------------------*
*
CLASS flow_chart DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class flow_chart definition.
public section.
data: begin of w_secs,
progm type sy-cprog,
type,
name type string,
start type i,
end
type i,
end
of w_secs,
t_secs like standard table of w_secs,
begin of w_nodes,
id
type i,
type,
name type string,
end
of w_nodes,
t_nodes like standard table of w_nodes,
begin of w_calls,
start,
type,
calledby type string,
ntype,
name type string,
end
of w_calls,
t_calls like standard table of w_calls.
data: l_comp type ref to cl_abap_compiler,
t_result type scr_glrefs,
w_result like line of t_result,
t_secst like t_secs,
l_match type i,
t_ref
type scr_refs,
w_ref
type line of scr_refs.
data: t_cprog type standard table of sy-cprog,
l_cprog type sy-cprog.
data: t_prog type standard table of char255,
l_prog type char255,
l_evnt type string,
t_stmt type standard table of sstmnt,
l_stmt type sstmnt,
t_strc type standard table of sstruc,
l_strc type sstruc,
l_tabix type i,
t_tokn type standard table of stokes.
methods get_chart importing p_cprog type sy-cprog.
methods find_data importing p_start type string p_end type string.

methods find_pattern importing p_full type string p_last type string p_type type string chang
ing p_subrc type i.
methods get_data importing value(p_pos) type i value(p_ntype) type char01 value(p_name) type
string.
endclass.
"flow_chart DEFINITION
*----------------------------------------------------------------------*
*
CLASS flow_chart IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class flow_chart implementation.
method get_chart.
call function 'RS_GET_ALL_INCLUDES'
exporting
program
= p_cprog
with_inactive_incls = 'X'
tables
includetab
= t_cprog
exceptions
not_existent
= 1
no_program
= 2
others
= 3.
append p_cprog to t_cprog.
loop at t_cprog into l_cprog.
read report l_cprog into t_prog.
scan abap-source t_prog tokens into t_tokn statements into t_stmt structures into t_strc.
w_secs-progm = l_cprog.
w_secs-type = 'F'.
call method find_data
exporting
p_start = 'FUNCTION'
p_end
= 'ENDFUNCTION'.
w_secs-type = 'S'.
call method find_data
exporting
p_start = 'FORM'
p_end
= 'ENDFORM'.
w_secs-type = 'D'.
call method find_data
exporting
p_start = 'MODULE'
p_end
= 'ENDMODULE'.
w_secs-type = 'M'.
call method find_data
exporting
p_start = 'METHOD'
p_end
= 'ENDMETHOD'.
w_secs-type = 'E'.
loop at t_strc into l_strc where type = 'E'.
read table t_stmt into l_stmt with key number = l_strc-stmnt_from.
read table t_prog into l_prog index l_stmt-trow.
translate l_prog to upper case.
translate l_prog using '. '.
w_secs-name = l_prog.
w_secs-start = l_stmt-trow.
read table t_stmt into l_stmt with key number = l_strc-stmnt_to.
w_secs-end = l_stmt-trow.
append w_secs to t_secs.
endloop.
endloop.

create object l_comp


exporting
p_name = p_cprog.
call method l_comp->get_all_refs
exporting
p_local = 'X'
importing
p_result = t_result.
loop at t_result into w_result.
call method find_pattern
exporting
p_full = '\PR:*\TY:*\ME:*'
p_last = '\ME:'
p_type = 'M'
changing
p_subrc = l_match.
if l_match ne 0.
call method find_pattern
exporting
p_full = '\TY:*\ME:*'
p_last = '\ME:'
p_type = 'C'
changing
p_subrc = l_match.
if l_match ne 0.
call method find_pattern
exporting
p_full = '\FU:*'
p_last = '\FU:'
p_type = 'F'
changing
p_subrc = l_match.
if l_match ne 0.
call method find_pattern
exporting
p_full = '\PR:*\FO:*'
p_last = '\FO:'
p_type = 'S'
changing
p_subrc = l_match.
if l_match ne 0.
continue.
endif.
endif.
endif.
endif.
refresh t_ref.
call method l_comp->get_single_ref
exporting
p_full_name
= w_result-full_name
p_grade
= 2
importing
p_result
= t_ref
exceptions
syntax_error
= 1
object_not_found = 2
ref_not_found
= 3
parameter_error = 4
others
= 5.

t_secst[] = t_secs[].
loop at t_ref into w_ref where grade ne 0.
loop at t_secst into w_secs where start <= w_ref-line and end >= w_refline and progm = w_ref-statement->source_info->name.
delete t_secst index sy-tabix.
w_calls-type
= w_secs-type.
w_calls-calledby = w_secs-name.
append w_calls to t_calls.
endloop.
endloop.
clear w_calls.
endloop.
data: w_cald like w_calls.
loop at t_calls into w_calls.
l_tabix = sy-tabix.
w_nodes-type = w_calls-type.
w_nodes-name = w_calls-calledby.
append w_nodes to t_nodes.
w_nodes-type = w_calls-ntype.
w_nodes-name = w_calls-name.
append w_nodes to t_nodes.
read table t_calls into w_cald with key name = w_calls-calledby ntype = w_calls-type.
if sy-subrc ne 0.
w_calls-start = 'X'.
modify t_calls from w_calls index l_tabix transporting start.
endif.
endloop.
sort t_nodes.
delete adjacent duplicates from t_nodes comparing all fields.
loop at t_nodes into w_nodes.
w_nodes-id = sy-tabix.
modify t_nodes from w_nodes index sy-tabix.
endloop.
loop at t_nodes into w_nodes.
net_nodes_tab-id
= w_nodes-id.
net_nodes_tab-type = 0.
case w_nodes-type.
when 'F'.
net_nodes_tab-type = 'F'.
when 'M'.
net_nodes_tab-type = 'I'.
when 'S'.
net_nodes_tab-type = 'S'.
when 'C'.
net_nodes_tab-type = '0'.
when 'E'.
net_nodes_tab-type = 'T'.
endcase.
append net_nodes_tab to net_nodes_tab[].
nvals_tab-id
= net_nodes_tab-id.
nvals_tab-fl
= net_const-text_index_0.
nvals_tab-val = w_nodes-name.
append nvals_tab to nvals_tab[].
if strlen( w_nodes-name ) > 19.
nvals_tab-fl
= net_const-text_index_1.
nvals_tab-val = w_nodes-name+19.
append nvals_tab to nvals_tab[].

endif.
endloop.
sort t_calls by type calledby.
loop at t_calls into w_calls where start is not initial.
delete t_calls index sy-tabix.
add 1 to lines_tab-id.
read table t_nodes into w_nodes with key type = w_calls-type name = w_calls-calledby.
if sy-subrc eq 0.
lines_tab-pre = w_nodes-id.
read table t_nodes into w_nodes with key type = w_calls-ntype name = w_calls-name.
if sy-subrc eq 0.
lines_tab-suc = w_nodes-id.
lines_tab-ab = net_const-aob_ea.
append lines_tab to lines_tab[].
endif.
endif.
call method get_data
exporting
p_pos
= 4
p_ntype = w_calls-ntype
p_name = w_calls-name.
endloop.
loop at lines_tab[] into lines_tab.
lvals_tab-id
= lines_tab-id.
lvals_tab-fl
= net_const-text_index_0.
lvals_tab-val = space.
append lvals_tab to lvals_tab[].
endloop.
profile-gruppe = 'SCTX'.
profile-name = 'CONTEXT'.
profile-index = 0.
do.
call function 'CNET_GRAPHIC_NETWORK'
exporting
stat
= stat
profile
= profile
wait_for_input = space
importing
m_typ
= m_typ
tables
clusters
= clusters_tab
cvals
= cvals_tab
deletions
= delete_tab
inodes
= inodes_tab
lines
= lines_tab
lvals
= lvals_tab
nodes
= net_nodes_tab
nvals
= nvals_tab
positions
= positions_tab.
case m_typ.
when net_const-m_typ_d.
exit.
when net_const-m_typ_i.
stat = net_const-stat_4.
endcase.
enddo.
endmethod.
"get_chart
method find_data.

data: l_tokn
w_tokn
l_tokt
l_cls

like
like
like
type

line of t_tokn,
l_tokn,
l_tokn,
i.

loop at t_tokn into w_tokn where str = p_start.


l_tabix = sy-tabix - 1.
read table t_tokn into l_tokn index l_tabix.
if l_tokn-row ne w_tokn-row.
l_tabix = sy-tabix + 2.
if p_start = 'METHOD'.
l_cls = sy-tabix + 1.
while l_cls > 0.
l_cls = l_cls - 1.
read table t_tokn into l_tokt index l_cls.
if l_tokt-str = 'IMPLEMENTATION'.
l_cls = l_cls - 1.
read table t_tokn into l_tokt index l_cls.
exit.
endif.
endwhile.
endif.
read table t_tokn into w_tokn index l_tabix.
w_secs-name = w_tokn-str.
if l_tokt-str is not initial.
concatenate l_tokt-str '->' w_secs-name into w_secs-name.
endif.
w_secs-start = w_tokn-row.
loop at t_tokn into w_tokn from l_tabix where str = p_end.
w_secs-end = w_tokn-row.
append w_secs to t_secs.
exit.
endloop.
endif.
endloop.
endmethod.
"find_data
*&---------------------------------------------------------------------*
*&
Form find_pattern
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
method find_pattern.
p_subrc = 4.
w_calls-ntype = p_type.
if w_result-full_name cp p_full.
find p_last in w_result-full_name match offset l_match.
l_match = l_match + 4.
find regex '\\..:' in w_result-full_name+l_match.
if sy-subrc ne 0.
case p_type.
when 'F'.
w_calls-name = w_result-full_name+l_match.
when 'M'.
w_calls-name = w_result-full_name+4.
find regex '\\..:' in w_calls-name match offset l_match.
l_match = l_match + 4.
w_calls-name = w_calls-name+l_match.
replace regex '\\..:' in w_calls-name with '->'.
when 'C'.
w_calls-name = w_result-full_name+4.
replace regex '\\..:' in w_calls-name with '->'.

when 'S'.
w_calls-name = w_result-full_name+l_match.
endcase.
clear p_subrc.
endif.
endif.
endmethod.
"find_pattern
*&---------------------------------------------------------------------*
*&
Form get_data
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
method get_data.
data: l_pos type i,
l_calls like w_calls.
l_pos = p_pos + 3.
loop at t_calls into l_calls where calledby = p_name and type = p_ntype.
delete t_calls index sy-tabix.
read table t_nodes into w_nodes with key type = l_calls-type name = l_calls-calledby.
if sy-subrc eq 0.
add 1 to lines_tab-id.
lines_tab-pre = w_nodes-id.
read table t_nodes into w_nodes with key type = l_calls-ntype name = l_calls-name.
if sy-subrc eq 0.
lines_tab-suc = w_nodes-id.
lines_tab-ab = net_const-aob_ea.
append lines_tab to lines_tab[].
endif.
endif.
call method get_data
exporting
p_pos
= l_pos
p_ntype = l_calls-ntype
p_name = l_calls-name.
endloop.
endmethod.
"get_data
endclass.
"flow_chart IMPLEMENTATION
parameters: p_cprog type sy-cprog.
start-of-selection.
data: l_chart type ref to flow_chart.
create object l_chart.
call method l_chart->get_chart
exporting
p_cprog = p_cprog.

Das könnte Ihnen auch gefallen