‎2005 Oct 11 5:02 AM
Hi experts,
i am new to classes.
i am using on example progrma from book.
in this example i have used two global classes one local class.
here i have created on screen 100. and i am going to display alv grid from sflight table data on this screen.
i am using CARRID using as a input and when i press enter
the data will display on the screen as alv grid.
i am using CL_GUI_CUSTOM_CONTAINER, CL_GUI_ALV_GRID class for GUI.
now my problem is ALV GRID is displaying and when i enetered input the data is not diaplying on the grid.
i debugged the program..
data is getting into the internal table SFLIGHT_TAB, but not dispalying on the screen(ALV GRID).
to display the data i am using method REFRESH_TABLE_DISPLAY.
any help please
‎2005 Oct 11 5:09 AM
Hi,
Could u please post the code
U can also verify ur code with the code below:
DATA: w_variant TYPE disvariant, " Enable variant saving
w_layout TYPE lvc_s_layo, " Define the layout structure
w_output TYPE ZLIGHT_STRUC.
************************************************************************
* Constants Declaration
************************************************************************
CONSTANTS: c_a TYPE c VALUE 'A'. "All Layouts
***********************************************************************
* Object Declarations
************************************************************************
DATA : o_alvgrid TYPE REF TO cl_gui_alv_grid,
o_container TYPE REF TO cl_gui_custom_container.
MODULE status_9001 OUTPUT.
IF o_dockingcontainer IS INITIAL.
SET PF-STATUS 'ZSTATUS'.
SET TITLEBAR 'ZTITLE'.
*Create Objects
PERFORM f9000_objects_create.
*Build field catalog
PERFORM f9200_build_field_cat TABLES i_fieldcat
USING 'ZLIGHT_STRUC'.
*Layout
PERFORM f9400_layout USING sy-title 'X' 'X' p_layout.
*Display data
PERFORM f9500_display_data TABLES i_output
i_fieldcat
USING w_layout.
ENDIF.
ENDMODULE. " STATUS_9001 OUTPUT
*&---------------------------------------------------------------------
*& Module USER_COMMAND_9001 INPUT
*&---------------------------------------------------------------------
* This is used for PAI details
*----------------------------------------------------------------------
MODULE user_command_9001 INPUT.
CASE sy-ucomm.
WHEN 'EXIT' OR 'CANC'.
PERFORM f9600_free_objects:
USING o_alvgrid 'ALV' text-e02,
USING o_dockingcontainer 'DOCKING'
text-e01.
LEAVE PROGRAM.
WHEN 'BACK'.
PERFORM f9600_free_objects:
USING o_alvgrid 'ALV' text-e02,
USING o_dockingcontainer 'DOCKING'
text-e01.
SET SCREEN '0'.
LEAVE SCREEN.
WHEN OTHERS.
ENDCASE.
ENDMODULE. " USER_COMMAND_9001 INPUT
*&---------------------------------------------------------------------*
*& Form f9000_objects_create
*&---------------------------------------------------------------------*
* This form creates the objects that we later reference.
*----------------------------------------------------------------------*
FORM f9000_objects_create.
* Check to see if we are runnng on online
IF cl_gui_alv_grid=>offline( ) IS INITIAL.
CREATE OBJECT o_dockingcontainer
EXPORTING
ratio = '95'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6.
IF sy-subrc NE 0.
* MESSAGE i001 WITH text-e01.
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
CREATE OBJECT o_alvgrid
EXPORTING
i_parent = o_container.
FORM f9200_build_field_cat TABLES p_fieldcat STRUCTURE lvc_s_fcat
USING value(p_structure).
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = p_structure
CHANGING
ct_fieldcat = p_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE i277.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " f9200_build_field_cat
*&---------------------------------------------------------------------*
*& Form f9400_layout
*&---------------------------------------------------------------------*
* This form sets how the grid will look.
* The title, alternate colouring on lines, if the column widths are
* optimised for the data contents and the display variant if_used.
*----------------------------------------------------------------------*
* -->P_SY_TITLE - Title bar text
* -->P_0015 - Alternating line color (striped)
* -->P_0016 - Selection mode
* -->P_0017 - Optimize column width
* -->P_P_DISVAR - Report name
*----------------------------------------------------------------------*
FORM f9400_layout USING value(ptitle)
value(pzebra)
value(pmode)
value(pwidth)
value(pvariant).
w_layout-grid_title = ptitle.
w_layout-zebra = pzebra.
w_layout-sel_mode = pmode.
w_layout-cwidth_opt = pwidth.
w_variant-handle = pvariant.
w_variant-report = sy-repid.
ENDFORM. " f9400_layout
*&---------------------------------------------------------------------*
*& Form f9500_display_data
*&---------------------------------------------------------------------*
* Display the output data
*----------------------------------------------------------------------*
* -->P_IOUTPUT - Output table to be displayed in the ALV
* -->P_groups - Field groups
* -->P_exclude - Excluded toolbar standard functions
* -->P_fieldcat - Field catalog
* -->P_layout - Layout
*----------------------------------------------------------------------*
FORM f9500_display_data TABLES p_output
p_groups
p_exclude
p_fieldcat
USING value(p_layout).
CALL METHOD o_alvgrid->set_table_for_first_display
EXPORTING
is_variant = w_variant
i_save = c_a
is_layout = p_layout
CHANGING
it_outtab = p_output[]
it_fieldcatalog = p_fieldcat[]
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE i278.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " f9500_display_data
*&---------------------------------------------------------------------*
*& Form f9600_free_objects
*&---------------------------------------------------------------------*
* This form handles the freeing of the following objects
* ALV Docking Container
*----------------------------------------------------------------------*
* -->P_O_ALVGRID - Object to be freed
* -->P_0020 - Type of the object
* -->P_0021 - Object text
*----------------------------------------------------------------------*
FORM f9600_free_objects USING pobject
value(ptype)
value(ptext).
DATA: l_objectalv TYPE REF TO cl_gui_alv_grid.
* Need to type the field symbol or it does not work
CASE ptype.
WHEN 'ALV'.
l_objectalv = pobject.
IF NOT ( l_objectalv IS INITIAL ).
CALL METHOD l_objectalv->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
CLEAR: pobject, l_objectalv.
PERFORM f9700_error_handle USING ptext.
ENDIF.
WHEN 'DOCKING'.
DATA: lobjectdock TYPE REF TO cl_gui_docking_container.
lobjectdock = pobject.
IF NOT ( lobjectdock IS INITIAL ).
CALL METHOD lobjectdock->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
CLEAR: pobject, lobjectdock.
PERFORM f9700_error_handle USING ptext.
ENDIF.
WHEN 'CONTAINER'.
DATA: lobjectcontainer TYPE REF TO cl_gui_container.
lobjectcontainer = pobject.
IF NOT ( lobjectcontainer IS INITIAL ).
CALL METHOD lobjectcontainer->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
CLEAR: pobject, lobjectcontainer.
PERFORM f9700_error_handle USING ptext.
ENDIF.
WHEN OTHERS.
sy-subrc = 1.
PERFORM f9700_error_handle USING
text-e04.
ENDCASE.
ENDFORM. " f9600_free_objects
*&---------------------------------------------------------------------*
*& Form f9700_error_handle
*&---------------------------------------------------------------------*
* This form is used to handle errors
*----------------------------------------------------------------------*
* -->P_PTEXT - Text holding the messsage to be displayed as
* information
*----------------------------------------------------------------------*
FORM f9700_error_handle USING value(ptext).
IF sy-subrc NE 0.
* Add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = text-e03
txt2 = sy-subrc
txt1 = ptext.
ENDIF.
ENDFORM. " f9700_error_handle
ENDFORM. " f9000_objects_createAlso refer this link
‎2005 Oct 11 5:09 AM
Hi,
Could u please post the code
U can also verify ur code with the code below:
DATA: w_variant TYPE disvariant, " Enable variant saving
w_layout TYPE lvc_s_layo, " Define the layout structure
w_output TYPE ZLIGHT_STRUC.
************************************************************************
* Constants Declaration
************************************************************************
CONSTANTS: c_a TYPE c VALUE 'A'. "All Layouts
***********************************************************************
* Object Declarations
************************************************************************
DATA : o_alvgrid TYPE REF TO cl_gui_alv_grid,
o_container TYPE REF TO cl_gui_custom_container.
MODULE status_9001 OUTPUT.
IF o_dockingcontainer IS INITIAL.
SET PF-STATUS 'ZSTATUS'.
SET TITLEBAR 'ZTITLE'.
*Create Objects
PERFORM f9000_objects_create.
*Build field catalog
PERFORM f9200_build_field_cat TABLES i_fieldcat
USING 'ZLIGHT_STRUC'.
*Layout
PERFORM f9400_layout USING sy-title 'X' 'X' p_layout.
*Display data
PERFORM f9500_display_data TABLES i_output
i_fieldcat
USING w_layout.
ENDIF.
ENDMODULE. " STATUS_9001 OUTPUT
*&---------------------------------------------------------------------
*& Module USER_COMMAND_9001 INPUT
*&---------------------------------------------------------------------
* This is used for PAI details
*----------------------------------------------------------------------
MODULE user_command_9001 INPUT.
CASE sy-ucomm.
WHEN 'EXIT' OR 'CANC'.
PERFORM f9600_free_objects:
USING o_alvgrid 'ALV' text-e02,
USING o_dockingcontainer 'DOCKING'
text-e01.
LEAVE PROGRAM.
WHEN 'BACK'.
PERFORM f9600_free_objects:
USING o_alvgrid 'ALV' text-e02,
USING o_dockingcontainer 'DOCKING'
text-e01.
SET SCREEN '0'.
LEAVE SCREEN.
WHEN OTHERS.
ENDCASE.
ENDMODULE. " USER_COMMAND_9001 INPUT
*&---------------------------------------------------------------------*
*& Form f9000_objects_create
*&---------------------------------------------------------------------*
* This form creates the objects that we later reference.
*----------------------------------------------------------------------*
FORM f9000_objects_create.
* Check to see if we are runnng on online
IF cl_gui_alv_grid=>offline( ) IS INITIAL.
CREATE OBJECT o_dockingcontainer
EXPORTING
ratio = '95'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6.
IF sy-subrc NE 0.
* MESSAGE i001 WITH text-e01.
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
CREATE OBJECT o_alvgrid
EXPORTING
i_parent = o_container.
FORM f9200_build_field_cat TABLES p_fieldcat STRUCTURE lvc_s_fcat
USING value(p_structure).
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = p_structure
CHANGING
ct_fieldcat = p_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE i277.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " f9200_build_field_cat
*&---------------------------------------------------------------------*
*& Form f9400_layout
*&---------------------------------------------------------------------*
* This form sets how the grid will look.
* The title, alternate colouring on lines, if the column widths are
* optimised for the data contents and the display variant if_used.
*----------------------------------------------------------------------*
* -->P_SY_TITLE - Title bar text
* -->P_0015 - Alternating line color (striped)
* -->P_0016 - Selection mode
* -->P_0017 - Optimize column width
* -->P_P_DISVAR - Report name
*----------------------------------------------------------------------*
FORM f9400_layout USING value(ptitle)
value(pzebra)
value(pmode)
value(pwidth)
value(pvariant).
w_layout-grid_title = ptitle.
w_layout-zebra = pzebra.
w_layout-sel_mode = pmode.
w_layout-cwidth_opt = pwidth.
w_variant-handle = pvariant.
w_variant-report = sy-repid.
ENDFORM. " f9400_layout
*&---------------------------------------------------------------------*
*& Form f9500_display_data
*&---------------------------------------------------------------------*
* Display the output data
*----------------------------------------------------------------------*
* -->P_IOUTPUT - Output table to be displayed in the ALV
* -->P_groups - Field groups
* -->P_exclude - Excluded toolbar standard functions
* -->P_fieldcat - Field catalog
* -->P_layout - Layout
*----------------------------------------------------------------------*
FORM f9500_display_data TABLES p_output
p_groups
p_exclude
p_fieldcat
USING value(p_layout).
CALL METHOD o_alvgrid->set_table_for_first_display
EXPORTING
is_variant = w_variant
i_save = c_a
is_layout = p_layout
CHANGING
it_outtab = p_output[]
it_fieldcatalog = p_fieldcat[]
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE i278.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " f9500_display_data
*&---------------------------------------------------------------------*
*& Form f9600_free_objects
*&---------------------------------------------------------------------*
* This form handles the freeing of the following objects
* ALV Docking Container
*----------------------------------------------------------------------*
* -->P_O_ALVGRID - Object to be freed
* -->P_0020 - Type of the object
* -->P_0021 - Object text
*----------------------------------------------------------------------*
FORM f9600_free_objects USING pobject
value(ptype)
value(ptext).
DATA: l_objectalv TYPE REF TO cl_gui_alv_grid.
* Need to type the field symbol or it does not work
CASE ptype.
WHEN 'ALV'.
l_objectalv = pobject.
IF NOT ( l_objectalv IS INITIAL ).
CALL METHOD l_objectalv->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
CLEAR: pobject, l_objectalv.
PERFORM f9700_error_handle USING ptext.
ENDIF.
WHEN 'DOCKING'.
DATA: lobjectdock TYPE REF TO cl_gui_docking_container.
lobjectdock = pobject.
IF NOT ( lobjectdock IS INITIAL ).
CALL METHOD lobjectdock->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
CLEAR: pobject, lobjectdock.
PERFORM f9700_error_handle USING ptext.
ENDIF.
WHEN 'CONTAINER'.
DATA: lobjectcontainer TYPE REF TO cl_gui_container.
lobjectcontainer = pobject.
IF NOT ( lobjectcontainer IS INITIAL ).
CALL METHOD lobjectcontainer->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
CLEAR: pobject, lobjectcontainer.
PERFORM f9700_error_handle USING ptext.
ENDIF.
WHEN OTHERS.
sy-subrc = 1.
PERFORM f9700_error_handle USING
text-e04.
ENDCASE.
ENDFORM. " f9600_free_objects
*&---------------------------------------------------------------------*
*& Form f9700_error_handle
*&---------------------------------------------------------------------*
* This form is used to handle errors
*----------------------------------------------------------------------*
* -->P_PTEXT - Text holding the messsage to be displayed as
* information
*----------------------------------------------------------------------*
FORM f9700_error_handle USING value(ptext).
IF sy-subrc NE 0.
* Add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = text-e03
txt2 = sy-subrc
txt1 = ptext.
ENDIF.
ENDFORM. " f9700_error_handle
ENDFORM. " f9000_objects_createAlso refer this link
‎2005 Oct 11 5:12 AM
You need to use set_table_for_first_display method first and then use the refresh(if you are changing the display after the initial display of the grid).
Srinivas
‎2005 Oct 11 5:24 AM
i am using
CALL METHOD ALV_LIST->SET_TABLE_FOR_FIRST_DISPLAY and
CALL METHOD ALV_LIST->REFRESH_TABLE_DISPLAY but the data is not displaying.
here i am pasting the code ..
could you find where i am doing mistake please..
&----
& Include YCL_TOP Module poo
*& *
&----
PROGRAM YM_CLASS_ALV .
&----
*& Class APPLICATION
&----
Text
----
tables: SFLIGHT.
CLASS APPLICATION DEFINITION.
PUBLIC SECTION.
DATA: SFLIGHT_TAB TYPE TABLE OF SFLIGHT.
METHODS: CONSTRUCTOR,
READ_DATA IMPORTING L_CARRID TYPE SFLIGHT-CARRID,
FILL_LIST.
PRIVATE SECTION.
DATA: SFLIGHT_TAB TYPE TABLE OF SFLIGHT,
DATA: CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
ALV_LIST TYPE REF TO CL_GUI_ALV_GRID.
ENDCLASS. "APPLICATION
&----
*& Class (Implementation) APPLICATION
&----
Text
----
CLASS APPLICATION IMPLEMENTATION.
METHOD CONSTRUCTOR.
CREATE OBJECT CONTAINER
EXPORTING CONTAINER_NAME = 'SLV_DATA'.
CREATE OBJECT ALV_LIST
EXPORTING I_PARENT = CONTAINER.
CALL METHOD ALV_LIST->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_STRUCTURE_NAME = 'SFLIGHT'
CHANGING
IT_OUTTAB = SFLIGHT_TAB.
ENDMETHOD.
METHOD READ_DATA.
SELECT * FROM SFLIGHT INTO TABLE SFLIGHT_TAB WHERE CARRID = L_CARRID.
ENDMETHOD.
METHOD FILL_LIST.
CALL METHOD ALV_LIST->REFRESH_TABLE_DISPLAY.
ENDMETHOD.
ENDCLASS. "APPLICATION
DATA OBJECT_REF TYPE REF TO APPLICATION.
&----
*& Include YCL_O01 *
&----
&----
*& Module STATUS_0100 OUTPUT
&----
text
----
MODULE STATUS_0100 OUTPUT.
CREATE OBJECT OBJECT_REF.
SET PF-STATUS 'SCREENCL100'.
SET TITLEBAR 'xxx'.
CALL METHOD OBJECT_REF->FILL_LIST.
ENDMODULE. " STATUS_0100 OUTPUT
&----
*& Include YCL_I01 *
&----
&----
*& Module USER_COMMAND_0100 INPUT
&----
text
----
MODULE USER_COMMAND_0100 INPUT.
IF SY-UCOMM = 'EXIT'..
LEAVE PROGRAM.
ELSE.
SY-UCOMM = 'DETAILS'.
CALL METHOD OBJECT_REF->READ_DATA
EXPORTING L_CARRID = SFLIGHT-CARRID.
ENDIF.
ENDMODULE. " USER_COMMAND_0100 INPUT
‎2005 Oct 11 5:32 AM
Hi,
Where u r calling the screen?
Copy and paste this code and execute this
*&---------------------------------------------------------------------*
*& Class APPLICATION
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
tables: SFLIGHT.
<u><b>START-OF-SELECTION.</b></u>
CLASS APPLICATION DEFINITION.
PUBLIC SECTION.
DATA: SFLIGHT_TAB TYPE TABLE OF SFLIGHT.
METHODS: CONSTRUCTOR,
READ_DATA IMPORTING L_CARRID TYPE SFLIGHT-CARRID.
<b>*FILL_LIST.</b>
PRIVATE SECTION.
* DATA: SFLIGHT_TAB TYPE TABLE OF SFLIGHT,
DATA: CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
ALV_LIST TYPE REF TO CL_GUI_ALV_GRID.
ENDCLASS. "APPLICATION
*&---------------------------------------------------------------------*
*& Class (Implementation) APPLICATION
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
CLASS APPLICATION IMPLEMENTATION.
METHOD CONSTRUCTOR.
CREATE OBJECT CONTAINER
EXPORTING CONTAINER_NAME = 'SLV_DATA'.
CREATE OBJECT ALV_LIST
EXPORTING I_PARENT = CONTAINER.
CALL METHOD ALV_LIST->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_STRUCTURE_NAME = 'SFLIGHT'
CHANGING
IT_OUTTAB = SFLIGHT_TAB.
ENDMETHOD.
METHOD READ_DATA.
SELECT * FROM SFLIGHT INTO TABLE SFLIGHT_TAB WHERE CARRID = L_CARRID.
ENDMETHOD.
<b>*METHOD FILL_LIST.
*
*CALL METHOD ALV_LIST->REFRESH_TABLE_DISPLAY.
*
*ENDMETHOD.</b>
ENDCLASS. "APPLICATION
DATA OBJECT_REF TYPE REF TO APPLICATION.
<u><b>END-OF-SELECTION.
CALL SCREEN 0100.</b></u>
*&---------------------------------------------------------------------*
*& Include YCL_O01 *
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
CREATE OBJECT OBJECT_REF.
SET PF-STATUS 'SCREENCL100'.
* SET TITLEBAR 'xxx'.
<b>*CALL METHOD OBJECT_REF->FILL_LIST.</b>
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Include YCL_I01 *
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
IF SY-UCOMM = 'EXIT'.
LEAVE PROGRAM.
ELSE.
SY-UCOMM = 'DETAILS'.
CALL METHOD OBJECT_REF->READ_DATA
EXPORTING L_CARRID = SFLIGHT-CARRID.
ENDIF.
ENDMODULE. " USER_COMMAND_0100 INPUTSee the changes which i diid i have marked it in bold.
I got the output. Also see to that the output table is having any vaues. If not append values in debugging mode and try this out. Its working fine.
Reward points and close the thread.
Message was edited by: Judith Jessie Selvi
‎2005 Oct 11 10:32 AM
Hi,
If ur problem got solved reward full points to those who solved ur problem or u can get back with queries.