2008 Feb 07 5:22 AM
hi experts,
i have a requirement to create a alv grid report and in the output one column should be editable.(till here every thing is correct what i did)
i have to create a 'update' button to the tool bar of alv output screen so that if i enter my own data in the editable screen,and press 'update' button then my database table should be updated..
can anyone tell me how to create 'update' button and write code for that.
my code is as below:
TABLES: vbak,vbap.
TYPE-POOLS: slis. "ALV Declarations
*Data Declaration
*----
TYPES: BEGIN OF t_final,
vbeln LIKE vbak-vbeln,
erdat LIKE vbak-erdat,
matnr LIKE vbap-matnr,
posnr LIKE vbap-posnr,
END OF t_final.
DATA: i_final TYPE STANDARD TABLE OF t_final INITIAL SIZE 0,
wa_final TYPE t_final.
*ALV data declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gd_tab_group TYPE slis_t_sp_group_alv,
gd_layout TYPE slis_layout_alv,
gd_repid LIKE sy-repid.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
PERFORM data_retrieval.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM display_alv_report.
&----
*& Form BUILD_FIELDCATALOG
&----
Build Fieldcatalog for ALV Report
----
FORM build_fieldcatalog.
fieldcatalog-fieldname = 'VBELN'.
fieldcatalog-seltext_m = 'sales order'.
fieldcatalog-col_pos = 0.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'ERDAT'.
fieldcatalog-seltext_m = 'date'.
fieldcatalog-col_pos = 1.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'material no.'.
fieldcatalog-col_pos = 2.
fieldcatalog-edit = 'X'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'POSNR'.
fieldcatalog-seltext_m = 'line item no.'.
fieldcatalog-col_pos = 3.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
ENDFORM. " BUILD_FIELDCATALOG
&----
*& Form BUILD_LAYOUT
&----
Build layout for ALV grid report
----
FORM build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
gd_layout-totals_only = 'X'.
gd_layout-f2code = 'DISP'. "Sets fcode for when double
"click(press f2)
gd_layout-zebra = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text = 'helllllo'.
ENDFORM. " BUILD_LAYOUT
&----
*& Form DISPLAY_ALV_REPORT
&----
Display report using ALV grid
----
FORM display_alv_report.
gd_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_special_groups = gd_tabgroup
IT_EVENTS = GT_XEVENTS
i_save = 'X'
is_variant = z_template
TABLES
t_outtab = I_FINAL
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " DISPLAY_ALV_REPORT
&----
*& Form DATA_RETRIEVAL
&----
Retrieve data form EKPO table and populate itab it_ekko
----
FORM data_retrieval.
SELECT avbeln aerdat bmatnr bposnr FROM vbak AS a
INNER JOIN vbap AS b ON avbeln = bvbeln
INTO TABLE i_final WHERE avbeln = bvbeln.
ENDFORM. " DATA_RETRIEVAL
points will be rewarded.
hi experts,
i have a requirement to create a alv grid report and in the output one column should be editable.(till here every thing is correct what i did)
i have to create a 'update' button to the tool bar of alv output screen so that if i enter my own data in the editable screen,and press 'update' button then my database table should be updated..
can anyone tell me how to create 'update' button and write code for that.
my code is as below:
TABLES: vbak,vbap.
TYPE-POOLS: slis. "ALV Declarations
*Data Declaration
*----
TYPES: BEGIN OF t_final,
vbeln LIKE vbak-vbeln,
erdat LIKE vbak-erdat,
matnr LIKE vbap-matnr,
posnr LIKE vbap-posnr,
END OF t_final.
DATA: i_final TYPE STANDARD TABLE OF t_final INITIAL SIZE 0,
wa_final TYPE t_final.
*ALV data declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gd_tab_group TYPE slis_t_sp_group_alv,
gd_layout TYPE slis_layout_alv,
gd_repid LIKE sy-repid.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
PERFORM data_retrieval.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM display_alv_report.
&----
*& Form BUILD_FIELDCATALOG
&----
Build Fieldcatalog for ALV Report
----
FORM build_fieldcatalog.
fieldcatalog-fieldname = 'VBELN'.
fieldcatalog-seltext_m = 'sales order'.
fieldcatalog-col_pos = 0.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'ERDAT'.
fieldcatalog-seltext_m = 'date'.
fieldcatalog-col_pos = 1.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'material no.'.
fieldcatalog-col_pos = 2.
fieldcatalog-edit = 'X'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'POSNR'.
fieldcatalog-seltext_m = 'line item no.'.
fieldcatalog-col_pos = 3.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
ENDFORM. " BUILD_FIELDCATALOG
&----
*& Form BUILD_LAYOUT
&----
Build layout for ALV grid report
----
FORM build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
gd_layout-totals_only = 'X'.
gd_layout-f2code = 'DISP'. "Sets fcode for when double
"click(press f2)
gd_layout-zebra = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text = 'helllllo'.
ENDFORM. " BUILD_LAYOUT
&----
*& Form DISPLAY_ALV_REPORT
&----
Display report using ALV grid
----
FORM display_alv_report.
gd_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_special_groups = gd_tabgroup
IT_EVENTS = GT_XEVENTS
i_save = 'X'
is_variant = z_template
TABLES
t_outtab = I_FINAL
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " DISPLAY_ALV_REPORT
&----
*& Form DATA_RETRIEVAL
&----
Retrieve data form EKPO table and populate itab it_ekko
----
FORM data_retrieval.
SELECT avbeln aerdat bmatnr bposnr FROM vbak AS a
INNER JOIN vbap AS b ON avbeln = bvbeln
INTO TABLE i_final WHERE avbeln = bvbeln.
ENDFORM. " DATA_RETRIEVAL
points will be rewarded.
2008 Feb 07 5:35 AM
Hi
use a check box in the table so that the user can check those check boxes in which the data is changed.
now in the user_command form
DATA ls_ref1 TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ls_ref1.
CALL METHOD ls_ref1->check_changed_data.
and use
case sy-ucomm.
when 'UPD'.
loop at itab where check = 'X'.
move these records to another internal table
endloop.
now update the records in new table in your database
endcase.
and finally
CALL METHOD ls_ref1->refresh_table_display.
this wil refresh the internal table
regards,
venkatesh
2008 Feb 07 5:42 AM
hi venkatesh,
thanks for the response.
i want this program to be done using reuse_alv_grid.
thanks in advance.
2008 Feb 07 8:08 AM
Hi there I can do this really easily BUT ONLY IN OO.
I wouldn't advise develeoping any NEW STUFF using the old Non OO function modules -- it's obsolete, makes for really horrible messy code, takes ages and often is impossible to modify reports easily.
Also the old FM stuff won't necessarily be around in future releases.
If I had any ABAPPERS still using the old non OO stuff for GRID reports I'd make them all re-write the stuff anyway.
I should definitely think again on this one.
In the OO method (which you don't want I know) it's really easy so I'll show you anyway.
The ON TOOLBAR method builds your toolbar
the ON USER COMMAND is entered when you press a toolbar button. The value of the function is in e_ucomm.
Easy isn't it. !!!
method constructor .
create object grid_container1
exporting
* container_name = 'CCONTAINER1'.
container_name = cfname.
create object grid1
exporting
i_parent = grid_container1.
set handler z_object->on_user_command for grid1.
set handler z_object->on_toolbar for grid1.
set handler z_object->handle_data_changed for grid1.
set handler z_object->handle_data_changed_finished for grid1.
set handler z_object->on_dubbelklik for grid1.
set handler z_object->on_hotspot for grid1.
call method grid1->register_edit_event
exporting
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
endmethod.
method on_toolbar .
type-pools icon.
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'EXCEL' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move icon_xxl to ls_toolbar-icon.
move 'Excel' to ls_toolbar-quickinfo.
move 'EXCEL' to ls_toolbar-text.
append ls_toolbar to e_object->mt_toolbar.
perform toolbar in program (caller) if found
using e_object.
* ...
endmethod.
method on_user_command .
* FOR EVENT before_user_command OF cl_gui_alv_grid
* IMPORTING
* e_ucomm
* sender
case e_ucomm.
when 'EXIT'.
leave program.
when 'EXCEL'.
call method me->download_to_excel.
when 'SAVE'.
when 'PROC'.
call method me->process.
when 'REFR'.
call method me->refresh.
when 'SWITCH'.
call method me->switch.
when 'TEST'.
call method me->get_cell.
endcase.
* ...
endmethod.
Cheers
jimbo.
2008 Feb 07 9:21 AM
Hi Nani
TO add a button on alv tool bar and to handle it
u have to use object oriented approach
for this u have to define class and implement class in which u will write code inside the method to hadle particlur event
here is the code for it.
&----
*& Class z_cl_9_u_EVENT_RECEIVER this class contains the definition
of methods for handling events
----
CLASS z_cl_9_u_event_receiver DEFINITION DEFERRED.
*
DATA : event_receiver TYPE REF TO z_cl_9_u_event_receiver.
*data: create object e1 type ref to cl_alv_event_toolbar_set.
*
&----
*& Class z_cl_9_u_EVENT_RECEIVER this class contains the definition
of methods for handling events
----
CLASS z_cl_9_u_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. "z_cl_9_u_EVENT_RECEIVER
CLASSES
CLASS lcl_event_receiver DEFINITION DEFERRED.
&----
*& Class (Implementation) z_cl_9_u_EVENT_RECEIVER
&----
Add a Update Button On ALV-Toolbar and put the logic
for handing that button
----
&----
*& Class z_cl_9_u_EVENT_RECEIVER this class contains the implementation
of methods for handling events.
----
CLASS z_cl_9_u_event_receiver IMPLEMENTATION.
&----
*& Method HANDLE_TOOLBAR is to handle toolbar.
In event handler method for event TOOLBAR: Append own functions
by using event parameter E_OBJECT.
----
METHOD handle_toolbar.
In event handler method for event TOOLBAR: Append own functions
by using event parameter E_OBJECT.
DATA: L_T_toolbar TYPE stb_button.
Append an icon to update tables if country is otherthan NZ.
IF g_flag = c_x AND g_back NE c_x.
CLEAR L_T_toolbar.
MOVE 0 TO L_T_toolbar-butn_type.
MOVE 'UPDATE' TO L_T_toolbar-function.
MOVE icon_modify TO L_T_toolbar-icon.
MOVE text-062 TO L_T_toolbar-quickinfo.
MOVE '' TO L_T_toolbar-text.
MOVE ' ' TO L_T_toolbar-disabled.
APPEND L_T_toolbar TO e_object->mt_toolbar.
In a self defined button, you can disable the button with option DISABLED = 'X'
ELSEIF g_back = c_x.
CLEAR L_T_toolbar.
L_T_toolbar-function = 'UPDATE'.
L_T_toolbar-butn_type = 0.
L_T_toolbar-icon = icon_modify.
L_T_toolbar-quickinfo = text-015.
L_T_toolbar-disabled = 'X'.
APPEND L_T_toolbar TO e_object->mt_toolbar.
CLEAR ok_code.
ENDIF.
ENDMETHOD. "handle_toolbar
*----
&----
*& Method HANDLE_USER_COMMAND does processing based on user inputs.
E_UCOMM has the user command.
----
METHOD handle_user_command.
In event handler method for event USER_COMMAND:
DATA: L_T_Rows TYPE lvc_t_row,
L_Size TYPE sy-tabix.
CASE e_ucomm.
WHEN 'UPDATE'.
REFRESH L_T_Rows.
CALL METHOD alv_grid->get_selected_rows
IMPORTING
et_index_rows = L_T_Rows.
CALL METHOD cl_gui_cfw=>flush.
DESCRIBE TABLE L_T_Rows LINES L_Size.
IF L_Size IS INITIAL.
MESSAGE i071.
ELSE.
Execute this subroutines to capture the changed data
in ALV and pass it to Ztables,
PERFORM f4700_update_table TABLES L_T_Rows.
PERFORM f4800_get_changed_data.
PERFORM f0500_get_analysis_details USING g_socnr g_matnr.
CALL METHOD alv_grid->refresh_table_display.
ENDIF.
ENDCASE.
ENDMETHOD. "handle_user_command
*----
ENDCLASS.
now call these methods wher eever u r calling the alv like in PBO of screen.
IF g_custom_container IS INITIAL.
g_t_lvc_s_layo-info_fname = c_l_line_colour.
g_t_lvc_s_layo-no_keyfix = '1'. "
CREATE OBJECT g_custom_container
EXPORTING container_name = 'CONTAINER_DETAIL'.
CREATE OBJECT alv_grid
EXPORTING i_parent = g_custom_container.
CALL METHOD alv_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'structre of table'
is_layout = g_t_lvc_s_layo
CHANGING
it_outtab = g_t_outtab[]
it_fieldcatalog = g_t_fieldcat.
*OLY EN01434 BEGIN
->Create Object to receive events and link them to handler methods.
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_user_command FOR alv_grid.
SET HANDLER event_receiver->handle_toolbar FOR alv_grid.
ELSE. "SUBSEQUENT ITERATIONS:
F g_custom_container IS INITIAL.
Layout field 'info-fname' points to the field/column in the
OUTTAB that controls the colour attribute. (OUTTAB is
maintained in function Y_DIP_METER_REC_CALCULATION).
g_t_lvc_s_layo-info_fname = c_l_line_colour.
g_t_lvc_s_layo-no_keyfix = '1'. "RSC18Sep02 - allow hor scroll
CREATE OBJECT g_custom_container
EXPORTING container_name = 'CONTAINER_DETAIL'.
CREATE OBJECT alv_grid
EXPORTING i_parent = g_custom_container.
CALL METHOD alv_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'ZV9NDMRA'
is_layout = g_t_lvc_s_layo
CHANGING
it_outtab = g_t_outtab[]
it_fieldcatalog = g_t_fieldcat.
*OLY EN01434 BEGIN
->Create Object to receive events and link them to handler methods.
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_user_command FOR alv_grid.
SET HANDLER event_receiver->handle_toolbar FOR alv_grid.
ELSE. "SUBSEQUENT ITERATIONS:
*********SAVE IMPORT PARMAETER IS ADDED BY NEEC
PERFORM f4900_set_excluding_buttons." USING sy-dynnr.
CALL METHOD alv_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'ZV9NDMRA'
is_layout = g_t_lvc_s_layo
it_toolbar_excluding = g_t_toolbar_excl
CHANGING
it_outtab = g_t_outtab[]
it_fieldcatalog = g_t_fieldcat.
CALL METHOD alv_grid->set_toolbar_interactive.
CALL METHOD alv_grid->refresh_table_display.
I hope it will help to sme extent
Rewards if helpful and if any help required reply back.....
CALL METHOD alv_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'ZV9NDMRA'
is_layout = g_t_lvc_s_layo
it_toolbar_excluding = g_t_toolbar_excl
CHANGING
it_outtab = g_t_outtab[]
it_fieldcatalog = g_t_fieldcat.
CALL METHOD alv_grid->set_toolbar_interactive.
CALL METHOD alv_grid->refresh_table_display.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |