OO ALV USING DIALOGBOX CONTAINER


TYPES BEGIN OF tab1,
carrid     TYPE sflight-carrid,
connid     TYPE sflight-connid,
fldate     TYPE sflight-fldate,
price      TYPE sflight-price,
seatsmax   TYPE sflight-seatsmax,
seatsocc   TYPE sflight-seatsocc,
END OF tab1.
DATA : it_spfli    TYPE TABLE OF spfli,
wa_spfli    LIKE LINE OF it_spfli,
it_flight   TYPE TABLE OF tab1,
wa_flight   LIKE LINE OF it_flight,
ok_code     TYPE ui_func,
o_alv1      TYPE REF TO cl_gui_alv_grid,
o_alv2      TYPE REF TO cl_gui_alv_grid,
o_dock      TYPE REF TO cl_gui_docking_container,
o_dial      TYPE REF TO cl_gui_dialogbox_container,
it_fcat     TYPE lvc_t_fcat,
is_fcat     TYPE lvc_s_fcat,

          alv_ok_code    TYPE sy-ucomm VALUE ‘INCLUDE’.


*———————————————————–*
CLASS handle DEFINITION.
PUBLIC SECTION.

    CLASS-METHODS : handle_double_click

                    FOR EVENT double_click OF cl_gui_alv_grid

                    IMPORTING e_row.

    CLASS-METHODS : handle_close

                    FOR EVENT close OF cl_gui_dialogbox_container

                    IMPORTING sender. “triggers when user clicks                              ” the close button on the dialog box

    CLASS-METHODS : on_toolbar

                    FOR EVENT toolbar OF cl_gui_alv_grid

                    IMPORTING e_object.

    CLASSMETHODS : on_user_command

                   FOR EVENT user_command OF cl_gui_alv_grid

                   IMPORTING e_ucomm.  

ENDCLASS.                    “handle DEFINITION

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

CLASS handle IMPLEMENTATION.

  METHOD handle_double_click.

    READ TABLE it_spfli INTO wa_spfli INDEX e_row-index.

    IF sy-subrc = 0.

      SELECT carrid

             connid

             fldate

             price

             seatsmax

             seatsocc FROM sflight INTO TABLE it_flight WHERE carrid = wa_spfli-carrid.

    ENDIF.

    PERFORM build_fieldcat.

    CREATE OBJECT o_dial

      EXPORTING

        width   = 800

        height  = 200

        top     = 120

        left    120

        caption = ‘Flight Details’.

    SET HANDLER handle=>handle_close FOR o_dial.

    CREATE OBJECT o_alv2

      EXPORTING

        i_parent = o_dial.

    CALL METHOD o_alv2->set_table_for_first_display

      CHANGING

        it_outtab       = it_flight

        it_fieldcatalog = it_fcat.


    CALL METHOD o_alv2->refresh_table_display.

    REFRESH it_fcat.

  ENDMETHOD.                    “handle_double_click


  METHOD handle_close.

    CALL METHOD sender->set_visible

      EXPORTING

        visible = space.

  ENDMETHOD.                    “handle_close


  METHOD on_toolbar.

    DATA btn TYPE stb_button.

    CASE alv_ok_code.

      WHEN ‘INCLUDE’.

        btn-function = ‘EXCLUDE’.

        btn-icon = icon_pdir_foreward_switch.

      WHEN ‘EXCLUDE’.

        CLEAR e_object->mt_toolbar.

        btn-function = ‘INCLUDE’.

        btn-icon = icon_pdir_back_switch.

    ENDCASE.

    INSERT btn INTO TABLE e_object->mt_toolbar.

  ENDMETHOD.                    “on_toolbar


  METHOD on_user_command.

    CASE e_ucomm.

      WHEN ‘INCLUDE’ OR ‘EXCLUDE’.

        alv_ok_code = e_ucomm.

        CALL METHOD o_alv1->set_toolbar_interactive.

    ENDCASE.

  ENDMETHOD.                    “on_user_command

 

ENDCLASS.                    “handle IMPLEMENTATION


START-OF-SELECTION.

  PERFORM data_fetch.


END-OF-SELECTION.

  CALL SCREEN 100.


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

FORM data_fetch .

  SELECT FROM spfli INTO TABLE it_spfli UP TO 20 ROWS.

ENDFORM.                    ” DATA_FETCH

*&———————————————————-*

*&      Module  STATUS_0100  OUTPUT

*&———————————————————–*

*       text

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

MODULE status_0100 OUTPUT.

  SET PF-STATUS ‘STATUS’.

*  SET TITLEBAR ‘xxx’.

ENDMODULE.                 ” STATUS_0100  OUTPUT

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

MODULE display_alv OUTPUT.

  IF o_dock IS NOT BOUND.

    CREATE OBJECT o_dock

      EXPORTING

        side      = cl_gui_docking_container=>dock_at_left

        extension = 5000.

  ENDIF.

  IF o_alv1 IS NOT BOUND.

    CREATE OBJECT o_alv1

      EXPORTING

        i_parent = o_dock.

    SET HANDLER handle=>handle_double_click FOR o_alv1.

     SET HANDLER handle=>on_toolbar FOR o_alv1.
SET HANDLER handle=>on_user_command FOR o_alv1. 

    CALL METHOD o_alv1->set_table_for_first_display

      EXPORTING

        i_structure_name = ‘SPFLI’

      CHANGING

        it_outtab        = it_spfli.


  ENDIF.

ENDMODULE.                 ” DISPLAY_ALV  OUTPUT

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

MODULE user_command_0100 INPUT.

  CASE  ok_code.

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

      LEAVE PROGRAM.

  ENDCASE.

ENDMODULE.                 ” USER_COMMAND_0100  INPUT


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

FORM build_fieldcat .

  is_fcat-col_pos = 1.

  is_fcat-fieldname = ‘CARRID’.

  is_fcat-tabname = ‘IT_FLIGHT’.

  is_fcat-scrtext_l = ‘CARRID’.

  is_fcat-key = ‘X’.

  APPEND is_fcat TO it_fcat.

  CLEAR is_fcat.


is_fcat-col_pos = 1.

  is_fcat-fieldname = ‘CONNID’.

  is_fcat-tabname = ‘IT_FLIGHT’.

  is_fcat-key = ‘X’.

  is_fcat-scrtext_l = ‘CONNID’.

  APPEND is_fcat TO it_fcat.

  CLEAR is_fcat.


is_fcat-col_pos = 3.

  is_fcat-fieldname = ‘FLDATE’.

  is_fcat-tabname = ‘IT_FLIGHT’.

  is_fcat-key = ‘X’.

  is_fcat-scrtext_l = ‘FLDATE’.

  APPEND is_fcat TO it_fcat.

  CLEAR is_fcat.


is_fcat-col_pos = 4.

  is_fcat-fieldname = ‘PRICE’.

  is_fcat-tabname = ‘IT_FLIGHT’.

  is_fcat-scrtext_l = ‘PRICE’.

  APPEND is_fcat TO it_fcat.

  CLEAR is_fcat.


is_fcat-col_pos = 5.

  is_fcat-fieldname = ‘SEATSMAX’.

  is_fcat-tabname = ‘IT_FLIGHT’.

  is_fcat-scrtext_l = ‘MAX SEAT’.

  APPEND is_fcat TO it_fcat.

  CLEAR is_fcat.


is_fcat-col_pos = 6.

  is_fcat-fieldname = ‘SEATSOCC’.

  is_fcat-tabname = ‘IT_FLIGHT’.

  is_fcat-scrtext_l = ‘OCCUPIED SEAT’.

  APPEND is_fcat TO it_fcat.

  CLEAR is_fcat.

ENDFORM.                    ” BUILD_FIELDCAT

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

SCREEN 100 FLOW LOGIC

PROCESS BEFORE OUTPUT.
MODULE status_0100.
MODULE display_alv.

PROCESS AFTER INPUT.
MODULE user_command_0100.

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


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 )

Connecting to %s