ABAP Code: Split Screen

Hi there fellow ABAPers... Do you have any requirement in your development which you need to split the screen? Let say, you need the left part as the menu and the right portion as the result being displayed? Well, thats not a problem now. Here is a code below which you can get the idea how to do it. Enjoy...

Sample Code:

* Classes *****************************************************

class screen_init definition create private.
  public section.
    class-methods init_screen.
    methods constructor.
  private section.
    data: splitter_h type ref to cl_gui_splitter_container,
          splitter_v type ref to cl_gui_splitter_container,
          picture type ref to cl_gui_picture,
          tree type ref to cl_gui_simple_tree.
    methods: fill_tree,
             fill_picture.
endclass.

*

class screen_handler definition.
  public section.
    methods: constructor importing container
               type ref to cl_gui_container,
             handle_node_double_click
               for event node_double_click
               of cl_gui_simple_tree
               importing node_key.
  private section.
    data: html_viewer type ref to cl_gui_html_viewer,
          list_viewer type ref to cl_gui_alv_grid.
    methods: fill_html importing carrid type spfli-carrid,
             fill_list importing carrid type spfli-carrid
                                 connid type spfli-connid.
endclass.

*

class screen_init implementation.

  method init_screen.
    data screen type ref to screen_init.
    create object screen.
  endmethod.

  method constructor.
    dataevents type cntl_simple_events,
          event like line of events,
          event_handler type ref to screen_handler,
          container_left type ref to cl_gui_container,
          container_right type ref to cl_gui_container,
          container_top type ref to cl_gui_container,
          container_bottom type ref to cl_gui_container.

    create object splitter_h
           exporting
           parent = cl_gui_container=>screen0
           rows = 1
           columns = 2.

    call method splitter_h->set_border
         exporting border = cl_gui_cfw=>false.

    call method splitter_h->set_column_mode
         exporting mode = splitter_h->mode_absolute.

    call method splitter_h->set_column_width
         exporting id = 1
         width = 107.

    container_left  = splitter_h->get_container( row = 1 column = 1 ).
    container_right = splitter_h->get_container( row = 1 column = 2 ).

    create object splitter_v
           exporting
           parent = container_left
           rows = 2
           columns = 1.

    call method splitter_v->set_border
         exporting border = cl_gui_cfw=>false.

    call method splitter_v->set_row_mode
         exporting mode = splitter_v->mode_absolute.

    call method splitter_v->set_row_height
         exporting id = 1
         height = 160.

    container_top    = splitter_v->get_container( row = 1 column = 1 ).
    container_bottom = splitter_v->get_container( row = 2 column = 1 ).

    create object picture
           exporting parent = container_top.

    create object tree
           exporting parent = container_bottom
                     node_selection_mode =
                            cl_gui_simple_tree=>node_sel_mode_single.
    create object  event_handler
           exporting container = container_right.

    event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
    event-appl_event = ' '.   "system event, does not trigger PAI
    append event to events.
    call method tree->set_registered_events
         exporting events = events.
    set handler event_handler->handle_node_double_click for tree.

    call method: me->fill_picture,
                 me->fill_tree.
  endmethod.

  method fill_picture.
    types pict_line(256type x.
    data  pict_tab type table of pict_line.
    data  url(255type c.

    import pict_tab = pict_tab from database abtree(pi) id 'FLIGHTS'.
    call function 'DP_CREATE_URL'
         exporting
              type    = 'IMAGE'
              subtype = 'GIF'
         tables
              data    = pict_tab
         changing
              url     = url.

    call method picture->load_picture_from_url exporting url = url.
    call method picture->set_display_mode
         exporting display_mode = picture->display_mode_fit_center.
  endmethod.

  method fill_tree.
    data: node_table type table of abdemonode,
          node type abdemonode,
          spfli_wa type spfli,
          spfli_tab type sorted table of spfli
                    with unique key carrid connid.

    select carrid connid
      from spfli
      into corresponding fields of table spfli_tab.

    node-hidden = ' '.                 " All nodes are visible,
    node-disabled = ' '.               " selectable,
    node-isfolder = 'X'.                                    " a folder,
    node-expander = ' '.               " have no '+' sign for expansion.
    loop at spfli_tab into spfli_wa.
      at new carrid.
        node-node_key = spfli_wa-carrid.
        clear node-relatkey.
        clear node-relatship.
        node-text = spfli_wa-carrid.
        node-n_image =   ' '.
        node-exp_image = ' '.
        append node to node_table.
      endat.
      at new connid.
        concatenate spfli_wa-carrid spfli_wa-connid into node-node_key.
        node-relatkey = spfli_wa-carrid.
        node-relatship = cl_gui_simple_tree=>relat_last_child.
        node-text = spfli_wa-connid.
        node-n_image =   '@AV@'.       "AV is the internal code
        node-exp_image = '@AV@'.       "for an airplane icon
      endat.
      append node to node_table.
    endloop.

    call method tree->add_nodes
         exporting table_structure_name = 'ABDEMONODE'
                   node_table = node_table.
  endmethod.

endclass.

*

class screen_handler implementation.

  method constructor.
    create object: html_viewer exporting parent = container,
                   list_viewer exporting i_parent = container.
  endmethod.

  method handle_node_double_click.
    data: carrid type spfli-carrid,
          connid type spfli-connid.

    carrid = node_key(2).
    connid = node_key+2(4).
    if connid is initial.
      call method: fill_html exporting carrid = carrid,
                   html_viewer->set_visible exporting visible = 'X',
                   list_viewer->set_visible exporting visible = ' '.
    else.
      call method: fill_list exporting carrid = carrid
                                       connid = connid,
                   list_viewer->set_visible exporting visible = 'X',
                   html_viewer->set_visible exporting visible = ' '.
    endif.

    call method cl_gui_cfw=>flush.
  endmethod.

  method fill_html.
    data url type scarr-url.

    select single url
    from   scarr
    into   url
    where  carrid = carrid.

    call method html_viewer->show_url exporting url = url.
  endmethod.

  method fill_list.
    data: flight_tab type table of demofli,
          begin of flight_title,
            carrname type scarr-carrname,
            cityfrom type spfli-cityfrom,
            cityto   type spfli-cityto,
          end of flight_title,
          list_layout type lvc_s_layo.

    select   single c~carrname p~cityfrom p~cityto
    into     corresponding fields of flight_title
    from     ( scarr as c
               inner join spfli   as p on c~carrid = p~carrid )
    where    p~carrid = carrid and
             p~connid = connid.

    select   fldate seatsmax seatsocc
    into     corresponding fields of table flight_tab
    from     sflight
    where    carrid = carrid and connid = connid
    order by fldate.

    concatenate flight_title-carrname
                connid
                flight_title-cityfrom
                flight_title-cityto
                into list_layout-grid_title separated by space.

    list_layout-smalltitle = 'X'.      "The list title has small fonts,
    list_layout-cwidth_opt = 'X'.      "the column width is adjusted,
    list_layout-no_toolbar = 'X'.      "the toolbar is suppressed.

    call method list_viewer->set_table_for_first_display
         exporting i_structure_name = 'DEMOFLI'
                   is_layout = list_layout
         changing  it_outtab         = flight_tab.
  endmethod.

endclass.


* Program execution ************************************************

load-of-program.
  call screen 100.

* Dialog Modules PBO

module status_0100 output.
  set pf-status 'SCREEN_100'.
  set titlebar 'TIT_100'.
  call method screen_init=>init_screen.
endmodule.

* Dialog Modules PAI

module cancel input.
  leave program.
endmodule.


Output:

No comments:

Post a Comment

How to download the data structure of tables in SE11?

Good morning people around the world. Its me again doing some blogs. Sharing to you some tips and tricks in the SAP world. Well, before I s...