EDUCAÇÃO E TECNOLOGIA

Exploding all includes of a report

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. parameters report type rs38m-programm. class application definition final create public. public section. methods explode_to_clipboard importing source_program type repid. protected section. private section. types source_line type c length 255. types source_lines type standard table of source_line with empty key. 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 application implementation. 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 explode. data source_lines type source_lines. read report source into source_lines. result = value #( for line in source_lines ( lines of explode_line( line ) ) ). endmethod. method explode_line. result = cond #( let match = match( val = line regex = `^ *include` case = abap_false ) in when match is initial then value #( ( line ) ) else explode( extract_source_name( line ) ) ). endmethod. method extract_source_name. result = to_upper( match( val = segment( val = condense( line ) index = 2 ) regex = '\w+' ) ). endmethod. endclass. start-of-selection. new application( )->explode_to_clipboard( report ).

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.