Skip to Content
Technical Articles
Author's profile photo Jörg Krause

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.

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

class zcl_dv17_inclex_main definition
        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.

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 ) ) ).

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

  method explode_to_clipboard.
    export_to_clipboard( explode( source_program ) ).

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

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

  method show_exploded_includes.
          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.

  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.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Edo von Glan
      Edo von Glan

      Nice, works for me.

      You have to remember to manually delete the orphaned includes afterwards.

      Maybe the report could WRITE a reminder with their names?

      Author's profile photo Jörg Krause
      Jörg Krause
      Blog Post Author

      This is of course an excellent idea. I updated the blog - the new source will show all sources that have been read in a SALV table now.

      Author's profile photo Edo von Glan
      Edo von Glan

      I had trouble exploding a program that used

      INCLUDE TYPE ...

      so I changed the following bit:

        method explode_line.
          data(match) = match( val = line regex = `^ *include` case = abap_false ).
          data(match_exception) = match( val = line regex = `include +type ` case = abap_false ). " don't explode INCLUDE TYPE
          if match is not initial and match_exception is initial.
      Author's profile photo Jörg Krause
      Jörg Krause
      Blog Post Author

      Thanksalot! I incorporated this immediately in my version.