You are on page 1of 33

Common error - ALV Fatal Error - GUI Cannot be reached

Purpose: This document details about the common problem faced by many consultant
s: Fatal Error GUI cannot be reached in ALV Grid Control.
The problem: SAP has provided us with some demo programs on ALV. We would use one
of them in our scenario. BCALV_GRID_DEMO is the demo program provided by SAP for
ALV Grid Control. When you execute the program in foreground, you get the simil
ar following output:

When you schedule the same program in background, your job is cancelled due to a
n error. Screenshot of the same is shown below:

Reason:
ALV Grid control is based on the custom controls on the screen. When the program
is scheduled in background, it tries to create GUI related front-end objects an
d hence the error Fatal Error GUI cannot be reached. This type of problem is commo
n with all the programs that use the ALV grid control to display the output.
Solution:
Whenever we execute this type of programs in background, we should be passing a
blank docking container instead of the custom container as parent to our grid co
ntrol. The docking container doesnt need any of the custom controls on the screen
; instead it attaches an area to any or all of the four edges of the screen (top
, left, right or bottom). The behavior of the areas in the container is determin
ed by the sequence in which they are initialized. Docking Containers are attache
d to the screen from the inside out. This means that when you create a second co
ntainer, it is attached to the edge of the screen, and the container that was al
ready there is pushed outwards. Let us modify the standard program (by taking a
copy of it) to enable it to execute it in background.
Following modifications have to be made:
Define a docking container in the program
data: or_doc type ref to cl_gui_docking_container .
At the time of creating a custom container, check if the program is being
executed in background or foreground. If the program is scheduled in background
, then create a docking container instead of custom container.
if cl_gui_alv_grid=>offline( ) is initial.
create object or_custom_container
exporting container_name = c_container.
create object or_grid
exporting i_parent = or_custom_container.
else .
create object or_grid
exporting i_parent = or_doc .
endif .
OO ALV WITH CONTAINERS
Introduction
As we know that a SAP Container is a control that accommodates other controls, s
uch as the SAP Tree Control, SAP Picture Control, SAP Text edit Control, SAP Spl
itter Control, and so on. It manages these controls logically in a collection, a
nd provides a physical area in which they are displayed. All controls live in a
container. Since containers are themselves controls, you can nest them. There ar
e five kinds of SAP Containers:
SAP Custom Container: display controls in an area defined on a normal screen usi
ng the Screen Painter. Class: CL_GUI_CUSTOM_CONTAINER
SAP Dialog Box Container: display controls in a modal dialog box or full screen.
Class: CL_GUI_DIALOGBOX_CONTAINER
SAP Docking Container: The SAP Docking Container allows you to attach a control
to any of the four edges of a screen as a resizable screen area. You can also de
tach it so that it becomes an independent modal dialog box. Class: CL_GUI_DOCKIN
G_CONTAINER
SAP Splitter Container: to display more than one control in a given area by divi
ding it into cells. Class: CL_GUI_SPLITTER_CONTAINER
SAP Easy Splitter Container: this container allows us to divide an area into tw
o cells with a control in each. The cells are separated by a moveable splitter b
ar.
Class: CL_GUI_EASY_SPLITTER_CONTAINER.
1. OO ALV USING DOCKING CONTAINER
data : o_dock type ref to cl_gui_docking_container,
o_alv type ref to cl_gui_alv_grid,
it_spfli type table of spfli,
wa_spfli type spfli,
ok_code type sy-ucomm.
select-options : p_carr for wa_spfli-carrid.
start-of-selection.
perform data_fetch.
call screen 100.
form DATA_FETCH .
select * from spfli into table it_spfli where carrid in p_carr.
endform. " DATA_FETCH
module STATUS_0100 output.
SET PF-STATUS 'STATUS'.
SET TITLEBAR 'TITLE'.
endmodule. " STATUS_0100 OUTPUT
module USER_COMMAND_0100 input.
case ok_code.
when 'BACK' OR 'EXIT' OR 'CANCEL'.
LEAVE TO SCREEN 0.
endcase.
endmodule. " USER_COMMAND_0100 INPUT
module DISPLAY_ALV output.
if o_dock is initial.
* EITHER PROVIDE SIDE AND EXTENSION OR RATIO TO CREATE A DOCKING CONTAINER*
CREATE OBJECT o_dock
EXPORTING
side = o_dock->dock_at_left " dock_at_right,dock_at_top,dock_at_bottom
extension = 2000.
* CREATE OBJECT o_dock
* EXPORTING
* ratio = 60.
endif.
if o_alv is initial.
CREATE OBJECT o_alv
EXPORTING
i_parent = o_dock.
CALL METHOD o_alv->set_table_for_first_display
EXPORTING
i_structure_name = 'SPFLI'
CHANGING
it_outtab = it_spfli.
endif.
endmodule. " DISPLAY_ALV OUTPUT
SCREEN FLOW LOGIC
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
MODULE DISPLAY_ALV.
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
2. OO ALV USING CUSTOM CONTAINER
DATA : o_cust TYPE REF TO cl_gui_custom_container,
o_alv TYPE REF TO cl_gui_alv_grid,
it_spfli TYPE TABLE OF spfli,
wa_spfli TYPE spfli,
ok_code TYPE sy-ucomm.
SELECT-OPTIONS : p_carr FOR wa_spfli-carrid.
START-OF-SELECTION.
PERFORM data_fetch.
CALL SCREEN 100.
FORM data_fetch .
SELECT * FROM spfli INTO TABLE it_spfli WHERE carrid IN p_carr.
ENDFORM. " DATA_FETCH
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS'.
SET TITLEBAR 'TITLE'.
ENDMODULE. " STATUS_0100 OUTPUT
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
MODULE display_alv OUTPUT.
CREATE OBJECT o_cust
EXPORTING
container_name = 'CUSTOM'.
CREATE OBJECT o_alv
EXPORTING
i_parent = O_CUST.
CALL METHOD o_alv->set_table_for_first_display
EXPORTING
i_structure_name = 'SPFLI'
CHANGING
it_outtab = IT_SPFLI.
ENDMODULE. " DISPLAY_ALV OUTPUT
SCREEN FLOW LOGIC
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
MODULE DISPLAY_ALV.
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.


3. OO ALV USING CUSTOM CONTAINER WITH DOUBLE CLICK EVENT
TYPES : BEGIN OF tab,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
countryfr TYPE spfli-countryfr,
cityfrom TYPE spfli-cityfrom,
airpfrom TYPE spfli-airpfrom,
countryto TYPE spfli-countryto,
cityto TYPE spfli-cityto,
airpto TYPE spfli-airpto,
END OF tab.
DATA : it_spfli TYPE TABLE OF tab,
wa_spfli TYPE tab,
ok_code TYPE sy-ucomm,
o_cust TYPE REF TO cl_gui_custom_container,
o_alv TYPE REF TO cl_gui_alv_grid,
it_fcat TYPE lvc_t_fcat,
wa_fcat TYPE lvc_s_fcat .
DATA : IT_SFLIGHT TYPE TABLE OF SFLIGHT.
DATA : O_DOCK TYPE REF TO CL_GUI_DOCKING_CONTAINER,
O_ALV1 TYPE REF TO CL_GUI_ALV_GRID.
SELECT-OPTIONS : s_carr FOR wa_spfli-carrid.
CLASS HANDLE_EVENT DEFINITION.
PUBLIC SECTION.
CLASS-METHODS : HANDLE_DOUBLE_CLICK
FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID IMPORTING e_row .
ENDCLASS.
CLASS HANDLE_EVENT IMPLEMENTATION.
METHOD handle_double_click.
READ TABLE IT_SPFLI INTO WA_SPFLI INDEX E_ROW.
SELECT * FROM SFLIGHT INTO TABLE IT_SFLIGHT WHERE CARRID = WA_SPFLI-CARRID.
CALL SCREEN 200.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
PERFORM DATA_FETCH.
PERFORM BUILD_FIELDCATALOG.
CALL SCREEN 100.
form DATA_FETCH .
SELECT carrid
connid
countryfr
cityfrom
airpfrom
countryto
cityto
airpto FROM spfli INTO TABLE it_spfli WHERE carrid IN s_carr.
endform. " DATA_FETCH
form BUILD_FIELDCATALOG .
CLEAR wa_fcat.
WA_FCAT-col_pos = 1.
WA_FCAT-fieldname = 'CARRID'.
WA_FCAT-tabname = 'IT_SPFLI'.
WA_FCAT-COLTEXT = 'CARRID'.
APPEND wa_fcat TO IT_FCAT.
CLEAR wa_fcat.
WA_FCAT-col_pos = 2.
WA_FCAT-fieldname = 'CONNID'.
WA_FCAT-tabname = 'IT_SPFLI'.
WA_FCAT-COLTEXT = 'CONNID'.
APPEND wa_fcat TO IT_FCAT.
CLEAR wa_fcat.
WA_FCAT-col_pos = 3.
WA_FCAT-fieldname = 'COUNTRYFR'.
WA_FCAT-tabname = 'IT_SPFLI'.
WA_FCAT-COLTEXT = 'COUNTRY FROM'.
APPEND wa_fcat TO IT_FCAT.
CLEAR wa_fcat.
WA_FCAT-col_pos = 4.
WA_FCAT-fieldname = 'CITYFROM'.
WA_FCAT-tabname = 'IT_SPFLI'.
WA_FCAT-COLTEXT = 'COUNTRY TO'..
APPEND wa_fcat TO IT_FCAT.
CLEAR wa_fcat.
WA_FCAT-col_pos = 5.
WA_FCAT-fieldname = 'AIRPFROM'.
WA_FCAT-tabname = 'IT_SPFLI'.
WA_FCAT-COLTEXT = 'AIRPORT FROM'.
APPEND wa_fcat TO IT_FCAT.
CLEAR wa_fcat.
WA_FCAT-col_pos = 6.
WA_FCAT-fieldname = 'COUNTRYTO'.
WA_FCAT-tabname = 'IT_SPFLI'.
WA_FCAT-COLTEXT = 'COUNTRY TO'.
APPEND wa_fcat TO IT_FCAT.
CLEAR wa_fcat.
WA_FCAT-col_pos = 7.
WA_FCAT-fieldname = 'CITYTO'.
WA_FCAT-tabname = 'IT_SPFLI'.
WA_FCAT-COLTEXT = 'CITY TO'.
APPEND wa_fcat TO IT_FCAT.
CLEAR wa_fcat.
WA_FCAT-col_pos = 8.
WA_FCAT-fieldname = 'AIRPTO'.
WA_FCAT-tabname = 'IT_SPFLI'.
WA_FCAT-COLTEXT = 'AIRPORT TO'.
APPEND wa_fcat TO IT_FCAT.
CLEAR wa_fcat.
endform. " BUILD_FIELDCATALOG
module STATUS_0100 output.
SET PF-STATUS 'STAT'.
SET TITLEBAR 'TITLT'.
endmodule. " STATUS_0100 OUTPUT
module DISPLAY_ALV output.
IF o_cust IS NOT BOUND.
CREATE OBJECT o_cust
EXPORTING
container_name = 'CONTAINER'.
ENDIF.
IF O_ALV IS NOT BOUND.
CREATE OBJECT o_alv
EXPORTING
i_parent = O_CUST.
SET HANDLER HANDLE_EVENT=>HANDLE_DOUBLE_CLICK FOR O_ALV.
CALL METHOD o_alv->set_table_for_first_display
CHANGING
it_outtab = IT_SPFLI
it_fieldcatalog = IT_FCAT.
ENDIF.
endmodule. " DISPLAY_ALV OUTPUT
module USER_COMMAND_0100 input.
CASE OK_CODE.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
endmodule. " USER_COMMAND_0100 INPUT
module STATUS_0200 output.
SET PF-STATUS 'STSA'.
* SET TITLEBAR 'xxx'.
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.
CALL METHOD o_alv1->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
it_outtab = IT_SFLIGHT.
ENDIF.
CALL METHOD o_alv1->refresh_table_display.
endmodule. " STATUS_0200 OUTPUT
module USER_COMMAND_0200 input.
CASE OK_CODE.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
endmodule. " USER_COMMAND_0200 INPUT
SCREEN 100 FLOW LOGIC
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
MODULE DISPLAY_ALV.
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.

SCREEN 200 FLOW LOGIC
PROCESS BEFORE OUTPUT.
MODULE STATUS_0200.
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0200.
4. SPLITTING CUSTOM CONTAINER BY SPLITTER CONTAINER AND DISPLAYING INTERACTIVE A
LV
DATA : it_spfli TYPE TABLE OF spfli,
wa_spfli TYPE spfli,
it_sflight TYPE TABLE OF sflight,
wa_sflight TYPE sflight,
o_cust TYPE REF TO cl_gui_custom_container,
o_spli TYPE REF TO cl_gui_splitter_container,
o_ref1 TYPE REF TO cl_gui_container,
o_ref2 TYPE REF TO cl_gui_container,
o_alv1 TYPE REF TO cl_gui_alv_grid,
o_alv2 TYPE REF TO cl_gui_alv_grid,
ok_code TYPE sy-ucomm.
CLASS handle_event DEFINITION.
PUBLIC SECTION.
CLASS-METHODS handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row.
ENDCLASS. "HANDLE_EVENT DEFINITION
CLASS handle_event IMPLEMENTATION.
METHOD handle_double_click.
READ TABLE it_spfli INTO wa_spfli INDEX e_row.SELECT * FROM sflight INTO TAB
LE it_sflight WHERE carrid = wa_spfli-carrid.
IF o_alv2 IS NOT BOUND.
CREATE OBJECT o_alv2
EXPORTING
i_parent = o_ref2.
CALL METHOD o_alv2->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
it_outtab = it_sflight.
ENDIF.
CALL METHOD o_alv2->refresh_table_display.
ENDMETHOD. "HANDLE_DOUBLE_CLICK
ENDCLASS. "HANDLE_EVENT IMPLEMENTATION
START-OF-SELECTION.
PERFORM fetch_data_from_spfli.
CALL SCREEN 100.
*----------------------------------------------------------------------*
FORM fetch_data_from_spfli .
SELECT * FROM spfli INTO TABLE it_spfli.
ENDFORM. " FETCH_DATA_FROM_SPFLI
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS'.
SET TITLEBAR 'TITLE'.
ENDMODULE. " STATUS_0100 OUTPUT
MODULE split_container OUTPUT.
IF o_cust IS NOT BOUND.
CREATE OBJECT o_cust
EXPORTING
container_name = 'CONTAINER'.
CREATE OBJECT o_spli
EXPORTING
parent = o_cust
rows = 2
columns = 1.
CALL METHOD o_spli->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = o_ref1.
CALL METHOD o_spli->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = o_ref2.
ENDIF.
ENDMODULE. " SPLIT_CONTAINER OUTPUT
MODULE display_alv OUTPUT.
IF o_alv1 IS NOT BOUND.
CREATE OBJECT o_alv1
EXPORTING
i_parent = o_ref1.
SET HANDLER handle_event=>handle_double_click 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'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
SCREEN 100 FLOW LOGIC
PROCESS BEFORE OUTPUT.
MODULE status_0100.
MODULE split_container.
MODULE display_alv.
PROCESS AFTER INPUT.
MODULE user_command_0100.


5. OO ALV WITH TOP_OF_PAGE EVENT TO DISPLAY HEADER
DATA : it_spfli TYPE TABLE OF spfli,
wa_spfli TYPE spfli,
o_cust TYPE REF TO cl_gui_custom_container,
o_spli TYPE REF TO cl_gui_splitter_container,
o_ref1 TYPE REF TO cl_gui_container,
o_ref2 TYPE REF TO cl_gui_container,
o_alv TYPE REF TO cl_gui_alv_grid,
o_docu TYPE REF TO cl_dd_document,
ok_code TYPE sy-ucomm.
*----------------------------------------------------------------------*
CLASS handle_event DEFINITION.
PUBLIC SECTION.
CLASS-METHODS : page_head FOR EVENT
top_of_page OF cl_gui_alv_grid
IMPORTING e_dyndoc_id table_index.


ENDCLASS. "HANDLE_EVENT DEFINITION
*----------------------------------------------------------------------*
CLASS handle_event IMPLEMENTATION.
METHOD page_head.
*----------------try this one---------------------------------*
DATA : text TYPE sdydo_text_element.
text = 'FLIGHT DETAILS'.
CALL METHOD o_docu->add_text
EXPORTING
text = text
sap_color = cl_dd_document=>list_positive
sap_fontsize = cl_dd_document=>large.
CALL METHOD o_docu->add_picture
EXPORTING
picture_id = 'HEADER'. " Object uploaded by OAER Transaction
CALL METHOD o_docu->display_document
EXPORTING
parent = o_ref1.
*----------------------or try this --------------------------------*
DATA : text TYPE sdydo_text_element .
DATA : date TYPE char10.
WRITE sy-datum TO date USING EDIT MASK '__/__/____'. CONCATENATE : 'FLIGHT D
ETAILS ON ' date INTO text SEPARATED BY space.
CALL METHOD o_docu->add_text
EXPORTING
text = text
sap_style = cl_dd_document=>heading
sap_color = cl_dd_document=>list_heading_int
sap_fontsize = cl_dd_document=>large.
CALL METHOD o_docu->new_line.
CLEAR text.
CONCATENATE : 'BY USER :' sy-uname INTO text SEPARATED BY space.
CALL METHOD o_docu->add_text
EXPORTING
text = text
sap_style = cl_dd_document=>heading
sap_color = cl_dd_document=>list_heading_int
sap_fontsize = cl_dd_document=>large.
CALL METHOD o_docu->set_document_background
EXPORTING
picture_id = 'HEADER1'. " Object uploaded by OAER Transaction
CALL METHOD o_docu->display_document
EXPORTING
reuse_control = 'X'
parent = o_ref1.
ENDMETHOD. "PAGE_HEAD
ENDCLASS. "HANDLE_EVENT IMPLEMENTATION
START-OF-SELECTION.
PERFORM fetch_data_from_spfli.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
FORM fetch_data_from_spfli .
SELECT * FROM spfli INTO TABLE it_spfli.
ENDFORM. " FETCH_DATA_FROM_SPFLI
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS'.
SET TITLEBAR 'TITLE'.
ENDMODULE. " STATUS_0100 OUTPUT
*----------------------------------------------------------------------*
MODULE split_container OUTPUT.
IF o_cust IS NOT BOUND.
CREATE OBJECT o_cust
EXPORTING
container_name = 'CONTAINER'.
CREATE OBJECT o_spli
EXPORTING
parent = o_cust
rows = 2
columns = 1.
CALL METHOD o_spli->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = o_ref1.
CALL METHOD o_spli->set_row_height
EXPORTING
id = 1
height = 35.
CALL METHOD o_spli->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = o_ref2.
CREATE OBJECT o_docu
EXPORTING
style = 'ALV_GRID'.
ENDIF.
ENDMODULE. " SPLIT_CONTAINER OUTPUT
*----------------------------------------------------------------------*
MODULE display_alv OUTPUT.
IF o_alv IS NOT BOUND.
CREATE OBJECT o_alv
EXPORTING
i_parent = o_ref2.
SET HANDLER handle_event=>page_head FOR o_alv.
CALL METHOD o_alv->set_table_for_first_display
EXPORTING
i_structure_name = 'SPFLI'
CHANGING
it_outtab = it_spfli.
CALL METHOD o_alv->list_processing_events
EXPORTING
i_event_name = 'TOP_OF_PAGE'
i_dyndoc_id = o_docu.
ENDIF.
ENDMODULE. " DISPLAY_ALV OUTPUT
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'BACK'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
SCREEN 100 FLOW LOGIC
PROCESS BEFORE OUTPUT.
MODULE status_0100.
MODULE split_container.
MODULE display_alv.
PROCESS AFTER INPUT.
MODULE user_command_0100.

6. OO ALV WITH SUBTOTAL AND TOTAL TEXT
TYPES : BEGIN OF tab,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
fldate TYPE sflight-fldate,
price TYPE sflight-price,
text1(20), " FOR TOTAL TEXT
text2(20), " FOR SUBTOTAL TEXT
END OF tab.
DATA : it_flight TYPE TABLE OF tab,
wa_flight TYPE tab,
it_fcat TYPE lvc_t_fcat,
wa_fcat TYPE lvc_s_fcat,
wa_layo TYPE lvc_s_layo,
it_sort TYPE lvc_t_sort,
wa_sort TYPE lvc_s_sort,
o_cust TYPE REF TO cl_gui_custom_container,
o_alv TYPE REF TO cl_gui_alv_grid,
ok_code TYPE sy-ucomm.
START-OF-SELECTION.
PERFORM fetch_data.
PERFORM build_text.
PERFORM build_fieldcat.
PERFORM build_layout.
PERFORM build_sort.
END-OF-SELECTION.
CALL SCREEN 100.
*----------------------------------------------------------------------*
FORM fetch_data .
SELECT carrid
connid
fldate price FROM sflight INTO CORRESPONDING FIELDS OF TABLE it_fl
ight.
SORT it_flight BY carrid ASCENDING.
ENDFORM. " FETCH_DATA
*----------------------------------------------------------------------*
FORM build_text .
DATA : carr TYPE sflight-carrid,
txt TYPE char20.
LOOP AT it_flight INTO wa_flight.
wa_flight-text1 = 'Total Price = '.
IF wa_flight-carrid NE carr.
carr = wa_flight-carrid.
CONCATENATE 'Subtotal (' carr ') =' INTO txt SEPARATED BY space.
ENDIF.
wa_flight-text2 = txt.
MODIFY it_flight FROM wa_flight.
ENDLOOP.
ENDFORM. " BUILD_TEXT
*----------------------------------------------------------------------*
FORM build_fieldcat .
wa_fcat-col_pos = 1.
wa_fcat-fieldname = 'TEXT1'.
wa_fcat-tech = 'X'.
wa_fcat-no_out = 'X'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 2.
wa_fcat-fieldname = 'TEXT2'.
wa_fcat-tech = 'X'.
wa_fcat-no_out = 'X'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 3.
wa_fcat-fieldname = 'CARRID'.
wa_fcat-tabname = 'IT_FLIGHT'.
wa_fcat-scrtext_m = 'CARRID'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 4.
wa_fcat-fieldname = 'CONNID'.
wa_fcat-tabname = 'IT_FLIGHT'.
wa_fcat-scrtext_m = 'CONNID'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 5.
wa_fcat-fieldname = 'FLDATE'.
wa_fcat-tabname = 'IT_FLIGHT'.
wa_fcat-scrtext_m = 'FLIGHT DATE'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 6.
wa_fcat-fieldname = 'PRICE'.
wa_fcat-tabname = 'IT_FLIGHT'.
wa_fcat-scrtext_m = 'PRICE'.
wa_fcat-do_sum = 'X'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ENDFORM. " BUILD_FIELDCAT
*----------------------------------------------------------------------*
FORM build_layout .
wa_layo-cwidth_opt = 'X'.
wa_layo-zebra = 'X'.
wa_layo-no_totline = 'X'.
ENDFORM. " BUILD_LAYOUT
*----------------------------------------------------------------------*
FORM build_sort .
wa_sort-spos = 1.
wa_sort-fieldname = 'TEXT1'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO it_sort.
CLEAR wa_sort.
wa_sort-spos = 2.
wa_sort-fieldname = 'TEXT2'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO it_sort.
CLEAR wa_sort.
ENDFORM. " BUILD_SORT
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS'.
ENDMODULE. " STATUS_0100 OUTPUT
*----------------------------------------------------------------------*
MODULE display_alv_grid OUTPUT.
IF o_cust IS NOT BOUND.
CREATE OBJECT o_cust
EXPORTING
container_name = 'CONT'."CREATE A CUSTOM CONT WITH NAME 'CONT'
ENDIF.
IF o_alv IS NOT BOUND.
CREATE OBJECT o_alv
EXPORTING
i_parent = o_cust.
ENDIF.
CALL METHOD o_alv->set_table_for_first_display
EXPORTING
is_layout = wa_layo
CHANGING
it_outtab = it_flight
it_fieldcatalog = it_fcat
it_sort = it_sort.
ENDMODULE. " DISPLAY_ALV_GRID OUTPUT
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'BACK'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*----------------------------------------------------------------------*
SCREEN 100 FLOW LOGIC
PROCESS BEFORE OUTPUT.
MODULE status_0100.
MODULE display_alv_grid.
PROCESS AFTER INPUT.
MODULE user_command_0100.

6. OO ALV WITH HIDING TOOLBAR
DATA : it_spfli TYPE TABLE OF spfli,
wa_spfli TYPE spfli,
ok_code TYPE sy-ucomm,
o_cust TYPE REF TO cl_gui_custom_container,
o_alv TYPE REF TO cl_gui_alv_grid,
lt_exclude TYPE ui_functions,
ls_exclude TYPE ui_func,
ls_layo TYPE lvc_s_layo.
START-OF-SELECTION.
PERFORM data_fetch.
PERFORM build_layout.
PERFORM fill_fcode.
END-OF-SELECTION.
CALL SCREEN 100.
*----------------------------------------------------------------------*
FORM data_fetch .
SELECT * FROM spfli INTO TABLE it_spfli .
SORT it_spfli BY carrid connid.
ENDFORM. " DATA_FETCH
*----------------------------------------------------------------------*
FORM build_layout .
*ls_layo-no_toolbar = 'X'. " To hide all toolbar buttons
ENDFORM.
*----------------------------------------------------------------------*
FORM fill_fcode .
ls_exclude = cl_gui_alv_grid=>mc_fc_subtot.
APPEND ls_exclude TO lt_exclude.
CLEAR ls_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_sort_asc.
APPEND ls_exclude TO lt_exclude.
CLEAR ls_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_sort_dsc.
APPEND ls_exclude TO lt_exclude.
CLEAR ls_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_filter.
APPEND ls_exclude TO lt_exclude.
CLEAR ls_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_detail.
APPEND ls_exclude TO lt_exclude.
CLEAR ls_exclude.
ENDFORM. " FILL_FCODE
*----------------------------------------------------------------------*
MODULE display_alv OUTPUT.
IF o_cust IS NOT BOUND.
CREATE OBJECT o_cust
EXPORTING
container_name = 'CONT'.
ENDIF.
IF o_alv IS NOT BOUND.
CREATE OBJECT o_alv
EXPORTING
i_parent = o_cust.
ENDIF.
CALL METHOD o_alv->set_table_for_first_display
EXPORTING
i_structure_name = 'SPFLI'
it_toolbar_excluding = lt_exclude
is_layout = ls_layo
CHANGING
it_outtab = it_spfli.
ENDMODULE. " DISPLAY_ALV OUTPUT
" BUILD_LAYOUT
SCREEN 100 FLOW LOGIC
PROCESS BEFORE OUTPUT.
* MODULE status_0100.
MODULE display_alv.
PROCESS AFTER INPUT.
* MODULE user_command_0100.
*----------------------------------------------------------------------*
OUTPUT BEFORE & AFTER HIDING TOOLBAR BUTTONS



*----------------------------------------------------------------------*
6. OO ALV WITH EDIT & SAVE FUNCTIONALITY & ADDING BUTTON IN ALV TOOLBAR
TYPE-POOLS : icon.
TYPES : BEGIN OF tab,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
countryfr TYPE spfli-countryfr,
cityfrom TYPE spfli-cityfrom,
airpfrom TYPE spfli-airpfrom,
countryto TYPE spfli-countryto,
cityto TYPE spfli-cityto,
airpto TYPE spfli-airpto,
END OF tab.
DATA : it_spfli TYPE TABLE OF tab,
it_spfli_old TYPE TABLE OF tab,
it_spfli_new TYPE TABLE OF spfli,
wa_spfli_new TYPE spfli,
wa_spfli TYPE tab,
ok_code TYPE sy-ucomm,
o_cust TYPE REF TO cl_gui_custom_container,
o_alv TYPE REF TO cl_gui_alv_grid,
it_fcat TYPE lvc_t_fcat,
is_fcat TYPE lvc_s_fcat,
is_layo TYPE lvc_s_layo,
check.
*----------------------------------------------------------------------*
* CLASS HANDLE_EVENT DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS handle_event DEFINITION.
PUBLIC SECTION.
CLASS-METHODS : handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object
e_interactive.
CLASS-METHODS : handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS. "HANDLE_EVENT DEFINITION
*----------------------------------------------------------------------*
CLASS handle_event IMPLEMENTATION.
METHOD handle_toolbar.
* *ADDING A SAVE BUTTONN TO THE ALV TOOLBAR *
DATA : is_btn TYPE stb_button.
is_btn-function = 'SAVE'.
is_btn-icon = icon_system_save.
is_btn-text = 'SAVE'.
is_btn-quickinfo = 'SAVE'.
is_btn-disabled = ' '.
APPEND is_btn TO e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar
METHOD handle_user_command .
CASE e_ucomm.
WHEN 'SAVE'. " WILL TRIGGER WHEN CLICK ON ALV TOOLBAR 'SAVE' BUTTON
PERFORM update_data_base.
ENDCASE.
ENDMETHOD. "handle_user_command
ENDCLASS. "HANDLE_EVENT IMPLEMENTATION
START-OF-SELECTION.
PERFORM data_fetch.
PERFORM buld_fieldcat.
PERFORM buld_layout.
END-OF-SELECTION.
CALL SCREEN 100.
*----------------------------------------------------------------------*
FORM data_fetch .
SELECT carrid
connid
countryfr
cityfrom
airpfrom
countryto
cityto
airpto FROM spfli INTO TABLE it_spfli .
SORT it_spfli BY carrid connid.
it_spfli_old = it_spfli.
ENDFORM. " DATA_FETCH
*----------------------------------------------------------------------*
MODULE display_alv OUTPUT.
IF o_cust IS NOT BOUND.
CREATE OBJECT o_cust
EXPORTING
container_name = 'CONT'.
ENDIF.
IF o_alv IS NOT BOUND.
CREATE OBJECT o_alv
EXPORTING
i_parent = o_cust.
SET HANDLER handle_event=>handle_toolbar FOR o_alv.
SET HANDLER handle_event=>handle_user_command FOR o_alv.
CALL METHOD o_alv->set_table_for_first_display
EXPORTING
is_layout = is_layo
CHANGING
it_outtab = it_spfli
it_fieldcatalog = it_fcat.
CALL METHOD o_alv->set_toolbar_interactive .
ENDIF.
CALL METHOD o_alv->refresh_table_display.
ENDMODULE. " DISPLAY_ALV OUTPUT
*----------------------------------------------------------------------*
FORM buld_fieldcat .
is_fcat-col_pos = 1 .
is_fcat-fieldname = 'CARRID'.
is_fcat-tabname = 'IT_SPFLI'.
is_fcat-scrtext_l = 'Carrer No.'.
is_fcat-key = 'X'.
APPEND is_fcat TO it_fcat.
CLEAR is_fcat.
is_fcat-col_pos = 2 .
is_fcat-fieldname = 'CONNID'.
is_fcat-tabname = 'IT_SPFLI'.
is_fcat-scrtext_l = 'Conn No.'.
is_fcat-key = 'X'.
APPEND is_fcat TO it_fcat.
CLEAR is_fcat.
is_fcat-col_pos = 3 .
is_fcat-fieldname = 'COUNTRYFR'.
is_fcat-tabname = 'IT_SPFLI'.
is_fcat-scrtext_l = 'Country From'.
APPEND is_fcat TO it_fcat.
CLEAR is_fcat.
is_fcat-col_pos = 4 .
is_fcat-fieldname = 'CITYFROM'.
is_fcat-tabname = 'IT_SPFLI'.
is_fcat-scrtext_l = 'City From'.
is_fcat-edit = 'X'. " MAKES ONLY THIS FIELD AS EDITABLE
APPEND is_fcat TO it_fcat.
CLEAR is_fcat.
is_fcat-col_pos = 5 .
is_fcat-fieldname = 'AIRP FROM'.
is_fcat-tabname = 'IT_SPFLI'.
is_fcat-scrtext_l = 'Airp From'.
APPEND is_fcat TO it_fcat.
CLEAR is_fcat.
is_fcat-col_pos = 6.
is_fcat-fieldname = 'COUNTRYTO'.
is_fcat-tabname = 'IT_SPFLI'.
is_fcat-scrtext_l = 'Country To'.
APPEND is_fcat TO it_fcat.
CLEAR is_fcat.
is_fcat-col_pos = 7 .
is_fcat-fieldname = 'CITYTO'.
is_fcat-tabname = 'IT_SPFLI'.
is_fcat-scrtext_l = 'City To'.
is_fcat-edit = 'X'. " MAKES ONLY THIS FIELD AS EDITABLE
APPEND is_fcat TO it_fcat.
CLEAR is_fcat.
is_fcat-col_pos = 8 .
is_fcat-fieldname = 'AIRPTO'.
is_fcat-tabname = 'IT_SPFLI'.
is_fcat-scrtext_l = 'Airport To'.
APPEND is_fcat TO it_fcat.
CLEAR is_fcat.
ENDFORM. " BULD_FIELDCAT
*----------------------------------------------------------------------*
FORM buld_layout .
is_layo-col_opt = 'X'.
* is_layo-edit = 'X'. " ALL FIELDS ARE EDITABLE
ENDFORM. " BULD_LAYOUT
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS'.
ENDMODULE. " STATUS_0100 OUTPUT
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'SAVE'. " WILL TRIGGER WHEN CLICK ON STANDARD TOOLBAR SAVE BUTTON
PERFORM UPDATE_DATA_BASE.
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*----------------------------------------------------------------------*
form UPDATE_DATA_BASE .
CALL METHOD o_alv->check_changed_data
IMPORTING
e_valid = check.
IF it_spfli NE it_spfli_old.
LOOP AT it_spfli INTO wa_spfli.
MOVE-CORRESPONDING wa_spfli TO wa_spfli_new.
APPEND wa_spfli_new TO it_spfli_new.
ENDLOOP.
MODIFY spfli FROM TABLE it_spfli_new.
IF sy-subrc = 0..
MESSAGE 'DATABASE TABLE SPFLI UPDATED' TYPE 'S'.
ENDIF.
ENDIF.
endform. " UPDATE_DATA_BASE
7.WORK WITH TEXT EDITOR IN CUSTOM CONTAINER
TYPE-POOLS : abap.
DATA : o_text TYPE REF TO cl_gui_textedit,
o_cust TYPE REF TO cl_gui_custom_container,
ok_code TYPE sy-ucomm,
mode TYPE i VALUE cl_gui_textedit=>false,
it_text TYPE TABLE OF char65,
wa_text TYPE char65.
START-OF-SELECTION.
wa_text = '*---------------------Write Your Comment ----------------------*'.
APPEND wa_text TO it_text.
CALL SCREEN 100.
*----------------------------------------------------------------------*
MODULE create_comment_box OUTPUT.
IF o_cust IS NOT BOUND.
CREATE OBJECT o_cust
EXPORTING
container_name = 'CONT'.
ENDIF.
IF o_text IS NOT BOUND.
CREATE OBJECT o_text
EXPORTING
parent = o_cust.
CALL METHOD o_text->set_toolbar_mode
EXPORTING
toolbar_mode = 0.
CALL METHOD o_text->set_statusbar_mode
EXPORTING
statusbar_mode = 0.
ENDIF.
CALL METHOD o_text->set_text_as_stream
EXPORTING
text = it_text.
ENDMODULE. " CREATE_COMMENT_BOX OUTPUT
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
LEAVE PROGRAM.
WHEN 'SAVE'.
CALL METHOD o_text->get_text_as_stream
EXPORTING
only_when_modified = cl_gui_textedit=>true
IMPORTING
text = it_text.
WHEN 'TOGG'.
IF ( mode = cl_gui_textedit=>true ).
mode = cl_gui_textedit=>false.
ELSE.
mode = cl_gui_textedit=>true.
ENDIF.
CALL METHOD o_text->set_readonly_mode
EXPORTING
readonly_mode = mode.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*----------------------------------------------------------------------*

MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS'. " SET (SAVE, BACK,EXIT,CANCEL) IN PF-STATUS
ENDMODULE. " STATUS_0100 OUTPUT
SCREEN 100 FLOW LOGIC
PROCESS BEFORE OUTPUT.
MODULE status_0100.
MODULE create_comment_box.
PROCESS AFTER INPUT.
MODULE user_command_0100.
8. OO ALV USING DOCKING CONTAINER & COLORING ROWS BASED ON CONDITION
*coloring particular rows in alv on condition*
TYPE-POOLS : col.
TYPES : BEGIN OF tab,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
fldate TYPE sflight-fldate,
price TYPE sflight-price,
seatsmax TYPE sflight-seatsmax,
seatsocc TYPE sflight-seatsocc,
color(4),
END OF tab.
DATA : it_flight TYPE TABLE OF tab,
wa_flight TYPE tab,
ok_code TYPE syst-ucomm,
o_alv TYPE REF TO cl_gui_alv_grid,
o_dock TYPE REF TO cl_gui_docking_container,
is_layo TYPE lvc_s_layo,
it_fcat TYPE lvc_t_fcat,
is_fcat TYPE lvc_s_fcat.
START-OF-SELECTION.
PERFORM data_fetch.
PERFORM build_fieldcatalog.
PERFORM build_layout.
END-OF-SELECTION.
CALL SCREEN 100.
*----------------------------------------------------------------------*
FORM data_fetch .
SELECT carrid
connid
fldate
price
seatsmax seatsocc FROM sflight INTO CORRESPONDING FIELDS OF TABLE it_f
light.
CONCATENATE 'C' col_group '10' INTO wa_flight-color.
MODIFY it_flight FROM wa_flight TRANSPORTING color WHERE price > 5000.
ENDFORM. " DATA_FETCH
*----------------------------------------------------------------------*
FORM build_fieldcatalog .
is_fcat-col_pos = 1.
is_fcat-fieldname = 'CARRID'.
is_fcat-tabname = 'IT_FLIGHT'.
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'.
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'.
APPEND is_fcat TO it_fcat.
CLEAR is_fcat.
is_fcat-col_pos = 4.
is_fcat-fieldname = 'PRICE'.
is_fcat-tabname = 'IT_FLIGHT'.
APPEND is_fcat TO it_fcat.
CLEAR is_fcat.
is_fcat-col_pos = 5.
is_fcat-fieldname = 'SEATSMAX'.
is_fcat-tabname = 'IT_FLIGHT'.
APPEND is_fcat TO it_fcat.
CLEAR is_fcat.
is_fcat-col_pos = 6.
is_fcat-fieldname = 'SEATSOCC'.
is_fcat-tabname = 'IT_FLIGHT'.
APPEND is_fcat TO it_fcat.
CLEAR is_fcat.
ENDFORM. " BUILD_FIELDCATALOG
*----------------------------------------------------------------------*
FORM build_layout .
is_layo-info_fname = 'COLOR'.
ENDFORM. " BUILD_LAYOUT
*----------------------------------------------------------------------*
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 = 500.
ENDIF.
if o_alv is not bound.
CREATE OBJECT o_alv
EXPORTING
i_parent = o_dock.
CALL METHOD o_alv->set_table_for_first_display
EXPORTING
is_layout = is_layo
CHANGING
it_outtab = it_flight
it_fieldcatalog = it_fcat.
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
*----------------------------------------------------------------------*
SCREEN 100 FLOW LOGIC
PROCESS BEFORE OUTPUT.
MODULE status_0100.
MODULE display_alv.
PROCESS AFTER INPUT.
MODULE user_command_0100.
*----------------------------------------------------------------------*
9. 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.
CLASS-METHODS : 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.
*----------------------------------------------------------------------*
10. OO TREE ALV USING CL_SIMPLE_TREE_MODEL
DATA : it_scarr TYPE TABLE OF scarr,
wa_scarr TYPE scarr,
it_spfli TYPE TABLE OF spfli,
wa_spfli TYPE spfli,
it_flight TYPE TABLE OF sflight,
wa_flight TYPE sflight,
ok_code TYPE sy-ucomm,
o_tree TYPE REF TO cl_simple_tree_model,
o_dock TYPE REF TO cl_gui_docking_container.
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 process_container OUTPUT.
IF o_dock IS NOT BOUND.
CREATE OBJECT o_dock
EXPORTING
ratio = 30.
ENDIF.
ENDMODULE. " PROCESS_CONTAINER OUTPUT
*----------------------------------------------------------------------*
MODULE process_tree OUTPUT.
IF o_tree IS NOT BOUND.
CREATE OBJECT o_tree
EXPORTING node_selection_mode = cl_simple_tree_model=>node_sel_mode_single
.
CALL METHOD o_tree->create_tree_control
EXPORTING
parent = o_dock.
PERFORM add_nodes USING o_tree.
ENDIF.
ENDMODULE. " PROCESS_TREE OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*----------------------------------------------------------------------*
FORM add_nodes USING obj_tree TYPE REF TO cl_simple_tree_model.
DATA : wa_node TYPE treemsnodt.
DATA : date_text TYPE char10.
CALL METHOD obj_tree->add_node
EXPORTING
node_key = 'ROOT'
isfolder = 'X'
text = 'FLIGHT DETAILS'
expander = 'X'.
LOOP AT it_scarr INTO wa_scarr.
wa_node-node_key = wa_scarr-carrid.
wa_node-text = wa_scarr-carrname.
CALL METHOD obj_tree->add_node
EXPORTING
node_key = wa_node-node_key
relative_node_key = 'ROOT'
relationship = cl_simple_tree_model=>relat_last_child
isfolder = 'X'
text = wa_node-text
expander = 'X'.
ENDLOOP.
LOOP AT it_spfli INTO wa_spfli.
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 wa_node-text SEPARATED BY space.
CALL METHOD obj_tree->add_node
EXPORTING
node_key = wa_node-node_key
relative_node_key = wa_node-relatkey
relationship = cl_simple_tree_model=>relat_last_child
isfolder = 'X'
text = wa_node-text
expander = 'X'.
ENDLOOP.
LOOP AT it_flight INTO wa_flight.
CONCATENATE wa_flight-carrid
wa_flight-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 date_text.
wa_node-text = date_text.
CALL METHOD obj_tree->add_node
EXPORTING
node_key = wa_node-node_key
relative_node_key = wa_node-relatkey
relationship = cl_simple_tree_model=>relat_last_child
isfolder = space
text = wa_node-text
expander = space.
ENDLOOP.
ENDFORM. " ADD_NODES
*----------------------------------------------------------------------*
SCREEN 100 FLOW LOGIC
PROCESS BEFORE OUTPUT.
MODULE status_0100.
MODULE process_container.
MODULE process_tree.
PROCESS AFTER INPUT.
MODULE user_command_0100.
*----------------------------------------------------------------------*
OUTPUT

*----------------------------------------------------------------------*
11. 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.
*----------------------------------------------------------------------*