‎2007 Sep 27 3:18 AM
Currently i have this codes below. But the table populated does not have field name. I do not know what i have to add to make the field name appear in the table.
Can anyone help me?
===========================================================
REPORT ZRECT1.
PARAMETERS: p_table TYPE dntab-tabname DEFAULT 'ZSTUD03' OBLIGATORY.
TYPE-POOLS : abap.
CLASS lcl_event_receiver DEFINITION DEFERRED.
DATA: o_grid TYPE REF TO cl_gui_alv_grid,
o_custom_container TYPE REF TO cl_gui_custom_container,
o_event_receiver TYPE REF TO lcl_event_receiver.
FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE,
<fs_warea> TYPE ANY,
<fs_field> TYPE ANY.
DATA: o_table TYPE REF TO data,
o_line TYPE REF TO data,
w_fcat TYPE lvc_s_fcat,
i_fcat TYPE lvc_t_fcat,
i_sort TYPE lvc_t_sort,
i_layo TYPE lvc_s_layo.
DATA : i_nametab TYPE TABLE OF dntab,
w_nametab TYPE dntab.
----
CLASS lcl_event_receiver DEFINITION
----
*
----
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive,
handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS. "lcl_event_receiver DEFINITION
&----
*& Classes implementation section
&----
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_toolbar.
CONSTANTS:
c_button_normal TYPE i VALUE 0,
c_separator TYPE i VALUE 1.
DATA: ls_toolbar TYPE stb_button.
CLEAR ls_toolbar.
APPEND ls_toolbar TO e_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE 'EDIT' TO ls_toolbar-function.
MOVE icon_system_copy TO ls_toolbar-icon.
MOVE 'Sets Grid in Edit Mode' TO ls_toolbar-quickinfo.
MOVE 'Edit' TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
MOVE 'UPDATE' TO ls_toolbar-function.
MOVE icon_system_save TO ls_toolbar-icon.
MOVE 'Updates all the changed data' TO ls_toolbar-quickinfo.
MOVE 'Update' TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
MOVE 'DELETE' TO ls_toolbar-function.
MOVE icon_delete TO ls_toolbar-icon.
MOVE 'Deletes the current record' TO ls_toolbar-quickinfo.
MOVE 'Delete' TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar
Method that check the events in the created buttons. *
METHOD handle_user_command.
CASE e_ucomm.
WHEN 'EDIT'.
CALL METHOD o_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
WHEN 'UPDATE'.
PERFORM update_modified_information.
WHEN 'DELETE'.
PERFORM delete_modified_information.
ENDCASE.
ENDMETHOD. "handle_user_command
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
START-OF-SELECTION.
CALL SCREEN 9000.
&----
*& Module STATUS_9000 OUTPUT
&----
text
----
MODULE STATUS_9000 OUTPUT.
SET PF-STATUS 'SE16'.
SET TITLEBAR 'SE16'.
ENDMODULE. " STATUS_9000 OUTPUT
&----
*& Module USER_COMMAND_9000 INPUT
&----
text
----
MODULE USER_COMMAND_9000 INPUT.
CASE sy-ucomm .
WHEN 'BACK' OR 'EXIT'.
SET SCREEN 0.
LEAVE SCREEN.
WHEN OTHERS.
MESSAGE 'Function Not Defined' TYPE 'I'.
ENDCASE.
ENDMODULE. " USER_COMMAND_9000 INPUT
&----
*& Module init_9000 OUTPUT
&----
text
----
MODULE init_9000 OUTPUT.
IF o_custom_container IS INITIAL.
Create a custom container
CREATE OBJECT o_custom_container
EXPORTING
container_name = 'CONTAINER'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CREATE OBJECT o_grid
EXPORTING
i_parent = o_custom_container
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS = 5 .
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CREATE OBJECT o_event_receiver. "Creating event receiver object
SET HANDLER o_event_receiver->handle_user_command FOR o_grid.
SET HANDLER o_event_receiver->handle_toolbar FOR o_grid.
CALL METHOD o_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 0.
ENDIF.
ENDMODULE. " init_9000 OUTPUT
&----
*& Module build_struct_9000 OUTPUT
&----
text
----
MODULE build_struct_9000 OUTPUT.
Create dynamic Internal Table
CREATE DATA o_table TYPE TABLE OF (p_table) .
ASSIGN o_table->* TO <fs_table>.
Create dynamic work area
CREATE DATA o_line LIKE LINE OF <fs_table>.
ASSIGN o_line->* TO <fs_warea>.
Field Catalogue
CALL FUNCTION 'NAMETAB_GET'
EXPORTING
langu = sy-langu
tabname = p_table
TABLES
nametab = i_nametab.
LOOP AT i_nametab INTO w_nametab .
w_fcat-col_pos = w_nametab-position.
w_fcat-fieldname = w_nametab-fieldname .
w_fcat-datatype = w_nametab-datatype.
w_fcat-inttype = w_nametab-inttype.
w_fcat-intlen = w_nametab-intlen.
w_fcat-decimals = w_nametab-decimals.
IF w_nametab-keyflag NE 'X'.
w_fcat-edit = 'X'.
ENDIF.
APPEND w_fcat TO i_fcat.
ENDLOOP.
ENDMODULE. " build_struct_9000 OUTPUT
&----
*& Module display_in_grid_9000 OUTPUT
&----
text
----
MODULE display_in_grid_9000 OUTPUT.
SELECT * FROM (p_table) INTO TABLE <fs_table>.
IF sy-subrc EQ 0.
CALL METHOD o_grid->set_table_for_first_display
EXPORTING
i_save = 'A'
i_default = 'X'
is_layout = i_layo
CHANGING
it_outtab = <fs_table>
it_fieldcatalog = i_fcat
it_sort = i_sort
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDMODULE. " display_in_grid_9000 OUTPUT
&----
*& Form update_modified_information
&----
text
----
--> p1 text
<-- p2 text
----
FORM update_modified_information .
UPDATE (p_table) FROM TABLE <fs_table>.
CALL METHOD o_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 0.
ENDFORM. " update_modified_information
&----
*& Form delete_modified_information
&----
text
----
--> p1 text
<-- p2 text
----
FORM delete_modified_information .
DATA: lv_line TYPE i,
lv_count TYPE i VALUE 0.
DATA: i_index_rows TYPE lvc_t_row,
w_index_rows LIKE lvc_s_row.
Reading the index of the selected row in the ALV grid.
CALL METHOD o_grid->get_selected_rows
IMPORTING
et_index_rows = i_index_rows.
DESCRIBE TABLE i_index_rows LINES lv_line.
IF lv_line LT 1.
MESSAGE 'Select atleast 1 row' TYPE 'I'.
EXIT.
ELSE.
LOOP AT i_index_rows INTO w_index_rows .
lv_line = w_index_rows-index - lv_count.
READ TABLE <fs_table> INTO <fs_warea> INDEX lv_line.
DELETE <fs_table> INDEX lv_line.
DELETE (p_table) FROM <fs_warea>.
lv_count = lv_count + 1.
ENDLOOP.
CALL METHOD o_grid->refresh_table_display.
CALL METHOD o_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 0.
ENDIF.
ENDFORM. " delete_modified_information
‎2007 Sep 27 3:44 AM
Hi Jocelyn,
Exactly this table is an add-on table with Z*, and the fieldcat may include part of filed of this add-on table, but maybe not all.
So it's not possible to find the exactly filed of this table, you need to ask the author who gives you the code.
BR
Bob
‎2007 Sep 28 3:32 AM