Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
jrgkraus
Active Contributor
861
Did you ever navigate with eclipse ADT in a report that uses includes for modularization? It's quite inconvenient because the outline window "sees" only what's in the actual include. Moreover CTRL+O does not show the whole outline as well. And in the project explorer, where the complete outline is available, you loose focus on the main program as soon as you enter into an include.

So I tend to get rid of all theses includes before applying some change to such a program. You know - open the include with F3, select all, copy to clipboard, close include, delete include line, paste.... what a mess.

Crawling the web I did not find any tool that does this for me (decades ago, the editor hat a feature "explode all includes"). So I decided to create one myself.

Here's the code in ABAP 7.5:
*&---------------------------------------------------------------------*
*& Report ZP_DV17_EXPLODE_INCLUDE
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
report zp_dv17_explode_include.

parameters report type rs38m-programm.

at selection-screen on value-request for report.
call function 'REPOSITORY_INFO_SYSTEM_F4'
exporting
object_type = 'PROG'
object_name = report
suppress_selection = 'X'
importing
object_name_selected = report
exceptions
cancel = 0.

class zcl_dv17_inclex_main definition
final
create public.
public section.

methods explode_to_clipboard
importing source_program type repid.

methods show_exploded_includes.

protected section.
private section.
types source_line type c length 255.
types source_lines type standard table of source_line with empty key.
types: begin of source,
repid type repid,
end of source,
sources type standard table of source with empty key.


data exploded_sources type sources.

methods explode
importing source type repid
returning value(result) type source_lines.

methods explode_line
importing line type source_line
returning value(result) type source_lines.

methods extract_source_name
importing line type source_line
returning value(result) type repid.

methods export_to_clipboard
importing value(source_lines) type source_lines.
endclass.



class zcl_dv17_inclex_main implementation.


method explode.
data source_lines type source_lines.
read report source into source_lines.
insert value #( repid = source ) into table exploded_sources.
result =
value #(
for line in source_lines
( lines of explode_line( line ) ) ).
endmethod.


method explode_line.
data(match) = match( val = line regex = `^ *include` case = abap_false ).
if match is not initial.
result = explode(
extract_source_name( line ) ).
else.
result = value #( ( line ) ).
endif.
endmethod.


method explode_to_clipboard.
export_to_clipboard( explode( source_program ) ).
endmethod.


method export_to_clipboard.
data clipboard_return type i.
cl_gui_frontend_services=>clipboard_export(
importing data = source_lines
changing rc = clipboard_return ).
if clipboard_return = 0.
message 'Exploded lines are in the clipboard now' type 'I'.
endif.
endmethod.


method extract_source_name.
result =
to_upper(
match(
val = segment( val = condense( line ) index = 2 )
regex = '\w+' ) ).
endmethod.


method show_exploded_includes.
try.
cl_salv_table=>factory(
importing r_salv_table = data(alv)
changing t_table = exploded_sources ).
alv->get_display_settings( )->set_list_header( 'Exploded sources' ).
alv->display( ).
catch cx_salv_error.
endtry.
endmethod.
endclass.

start-of-selection.
data(app) = new zcl_dv17_inclex_main( ).
app->explode_to_clipboard( report ).
app->show_exploded_includes( ).

The program loops the code and explodes each include that has been found. Explosion is performed recursively on each include found, so multilevel includes are no problem.

In the end, the exploded code is being put into the clipboard so you can paste it wherever you want with CTRL+V.

You will then get a list of all sources that have been merged together. This can be helpful to delete the unused includes afterwards.
4 Comments
Labels in this area