OO COLUMNTREE ALV USING CL_COLUMN_TREE_MODEL


TYPE-POOLS : icon.

DATA : it_scarr TYPE SORTED TABLE OF scarr  WITH UNIQUE KEY carrid,

            wa_scarr LIKE LINE OF it_scarr,

       it_spfli TYPE SORTED TABLE OF spfli  WITH UNIQUE KEY carrid connid,

         wa_spfli LIKE LINE OF it_spfli,

       it_flight TYPE SORTED TABLE OF sflight  WITH UNIQUE KEY carrid connid        fldate,

       wa_flight LIKE LINE OF it_flight,

       ok_code TYPE sy-ucomm,

       o_dock TYPE REF TO cl_gui_docking_container,

       o_col_tree TYPE REF TO cl_column_tree_model,

       wa_header TYPE treemhhdr.


START-OF-SELECTION.

  PERFORM data_fetch.


END-OF-SELECTION.

  CALL SCREEN 100.

*———————————————————————-*

FORM data_fetch .

  SELECT FROM scarr INTO TABLE it_scarr.

  IF it_scarr  IS NOT INITIAL.

    SELECT FROM spfli INTO TABLE  it_spfli

    FOR ALL ENTRIES IN it_scarr WHERE carrid = it_scarr-carrid.

    IF it_spfli IS NOT INITIAL.

    SELECT FROM sflight INTO TABLE  it_flight

    FOR ALL ENTRIES IN it_spfli WHERE carrid = it_spfli-carrid

                                  AND connid = it_spfli-connid.

    ENDIF.

  ENDIF.

ENDFORM.                    ” DATA_FETCH

*————————————————————-*

MODULE status_0100 OUTPUT.

  SET PF-STATUS ‘STATUS’.

*  SET TITLEBAR ‘xxx’.


ENDMODULE.                 ” STATUS_0100  OUTPUT

*———————————————————–*

MODULE container_processing OUTPUT.

  IF o_dock IS NOT BOUND.

    CREATE OBJECT o_dock

      EXPORTING

        ratio = 80.

  ENDIF.

ENDMODULE.                 ” CONTAINER_PROCESSING  OUTPUT

*———————————————————*

MODULE columntree_processing OUTPUT.

  wa_header-heading = ‘Flight Details’.

  wa_header-t_image = icon_ws_plane .

  wa_header-tooltip = ‘PLANE’.

  wa_header-width = 65.

  CREATE OBJECT o_col_tree

  EXPORTING

 node_selection_mod = cl_column_tree_model=>node_sel_mode_single

 hierarchy_column_name = ‘MAIN’

hierarchy_header      = wa_header.


CALL METHOD o_col_tree->create_tree_control

    EXPORTING

      parent = o_dock.

  PERFORM add_columns USING o_col_tree.

  PERFORM add_nodes USING o_col_tree.

ENDMODULE.                 ” COLUMNTREE_PROCESSING  OUTPUT

*———————————————————–*

MODULE user_command_0100 INPUT.

  CASE ok_code.

    WHEN ‘BACK’ OR ‘EXIT’ OR ‘CANCEL’.

      LEAVE PROGRAM.

  ENDCASE.

ENDMODULE.                 ” USER_COMMAND_0100  INPUT

*———————————————————–*

FORM add_columns USING col_tree TYPE REF TO cl_column_tree_model.

  CALL METHOD col_tree->add_column

    EXPORTING

      name        = ‘PRICE’

      width       = 40

      header_text = ‘Ticket Price’.

  CALL METHOD col_tree->add_column

    EXPORTING

      name        = ‘CURRENCY’

      width       = 20

      header_text = ‘Currency In:’.

  CALL METHOD col_tree->add_column

    EXPORTING

      name        = ‘PLANETYPE’

      width       = 20

      header_text = ‘Type Of Plane’.

  CALL METHOD col_tree->add_column

    EXPORTING

      name        = ‘ICON’

      width       = 15

      header_text = ‘Icon’.

  CALL METHOD col_tree->add_column

    EXPORTING

      name        = ‘SEATSFREE’

      width       = 40

      header_text = ‘available Seats’.


ENDFORM.                    ” ADD_COLUMNS

*———————————————————–*

FORM add_nodes USING col_tree TYPE REF TO cl_column_tree_model.

  DATA : wa_node TYPE treemcnodt,

         it_item TYPE treemcitab,

         text1   TYPE char40,

         text2   type char10,

         text3   type char40,

         text4   type char40.

  PERFORM fill_item_table USING ‘FLIGHTS’

                                 space

                                 space

                                 space

                                 space

                        CHANGING it_item.


CALL METHOD col_tree->add_node

    EXPORTING

      node_key   = ‘ROOT’

      isfolder   = ‘X’

      item_table = it_item.

  REFRESH it_item.


LOOP AT  it_scarr INTO wa_scarr.

    CLEAR wa_node.

    wa_node-node_key = wa_scarr-carrid.

    PERFORM fill_item_table USING wa_scarr-carrname

                                  space

                                  space

                                  space

                                  space

                        CHANGING it_item.

CALL METHOD col_tree->add_node

      EXPORTING

        node_key          = wa_node-node_key

        relative_node_key = ‘ROOT’

     relationship      = cl_column_tree_model=>relat_last_child

        isfolder          = ‘X’

        expander          = ‘X’

        item_table        = it_item.

    REFRESH it_item.

  ENDLOOP.


LOOP AT  it_spfli INTO wa_spfli.

    CLEAR wa_node.

    CONCATENATE wa_spfli-carrid wa_spfli-connid

           INTO wa_node-node_key SEPARATED BY space.

    wa_node-relatkey = wa_spfli-carrid.

    CONCATENATE wa_spfli-carrid wa_spfli-connid ‘:’

                wa_spfli-cityfrom ‘->’ wa_spfli-cityto

          INTO text1 SEPARATED BY space.

    PERFORM fill_item_table USING  text1

                                  space

                                  space

                                  space

                                  space

                        CHANGING it_item.


CALL METHOD col_tree->add_node

      EXPORTING

        node_key          = wa_node-node_key

        relative_node_key = wa_node-relatkey

   relationship      = cl_column_tree_model=>relat_last_child

        isfolder          = ‘X’

        expander          = ‘X’

        item_table        = it_item.

    REFRESH it_item.

  ENDLOOP.

LOOP AT  it_flight INTO wa_flight.

    CLEAR wa_node.

    CONCATENATE wa_flight-carrid

                wa_spfli-connid

                wa_flight-fldate

           INTO wa_node-node_key SEPARATED BY space.

    concatenate wa_flight-carrid

                wa_flight-connid

           into wa_node-relatkey separated by space.

    write wa_flight-fldate to text2.

    write wa_flight-price to text3 currency wa_flight-currency.

    if wa_flight-seatsmax >= wa_flight-seatsocc.

      text4 = wa_flight-seatsmax – wa_flight-seatsocc.

      endif.


PERFORM fill_item_table USING text2

                                  text3

                                  wa_flight-currency

                                  wa_flight-planetype

                                  text4

                        CHANGING it_item.


CALL METHOD col_tree->add_node

      EXPORTING

        node_key          = wa_node-node_key

        relative_node_key = wa_node-relatkey

   relationship      = cl_column_tree_model=>relat_last_child

        isfolder          = space

        expander          = space

        item_table        = it_item.

    REFRESH it_item.

  ENDLOOP.


ENDFORM.                    ” ADD_NODES

*————————————————————–*

FORM fill_item_table  USING    p_space1 TYPE c

                               p_space2 TYPE c

                               p_space3 TYPE c

                               p_space4 TYPE c

                               p_space5 TYPE c

                      CHANGING it_item TYPE treemcitab.

DATA : wa_item TYPE  treemcitem.

  CLEAR wa_item.


wa_item-class = cl_column_tree_model=>item_class_text.


wa_item-item_name = ‘MAIN’.

  wa_item-text = p_space1.

  INSERT wa_item INTO TABLE it_item.


wa_item-item_name = ‘PRICE’.

  wa_item-text = p_space2.

  INSERT wa_item INTO TABLE it_item.


wa_item-item_name = ‘CURRENCY’.

  wa_item-text = p_space3.

  INSERT wa_item INTO TABLE it_item.


wa_item-item_name = ‘PLANETYPE’.

  wa_item-text = p_space4.

  INSERT wa_item INTO TABLE it_item.


wa_item-item_name = ‘ICON’.

  IF NOT p_space5 IS INITIAL.

    IF p_space5 CO ‘ 0’.

      wa_item-t_image = icon_red_light.

    ELSE.

      wa_item-t_image = icon_green_light.

    ENDIF.

    CLEAR wa_item-text.

    INSERT wa_item INTO TABLE it_item.

  ENDIF.


wa_item-item_name = ‘SEATSFREE’.

  wa_item-text = p_space5.

  wa_item-t_image = space.

  INSERT wa_item INTO TABLE it_item.

ENDFORM.                    ” FILL_ITEM_TABLE

*————————————————————*

SCREEN 100 FLOW LOGIC

PROCESS BEFORE OUTPUT.

  MODULE status_0100.

  MODULE container_processing.

  MODULE columntree_processing.


PROCESS AFTER INPUT.

  MODULE user_command_0100.

*————————————————————-*

OUTPUT


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s