01-05-2008 4:01 PM
Hi,
i want to add / delete rows in an alv grid.I found BCALV_EDIT_04.but it is very complicated.can u tell me how can i do this?
01-05-2008 6:37 PM
Check this blog..
/people/srilatha.t/blog/2007/04/13/alv-grid--delete-row-function
Regards,
Maha
01-07-2008 4:23 AM
Hi burc,
Check this simple code.
****To identify the selected records to delete declare a field
****flag to layout
gs_layout-box_fieldname = 'FLAG'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = ws_repid
i_callback_pf_status_set = 'GUI_STAT'
i_callback_user_command = 'STAT'
is_layout = gs_layout
it_fieldcat = i_fieldcat[]
TABLES
t_outtab = i_zaw_pol_plan.
IF sy-subrc <> 0.
MESSAGE----
ENDIF.
ENDFORM. " change_data
**--Setting Status of outout screen
FORM gui_stat USING rt_extab TYPE slis_t_extab.
****In your PF status add button Delete
SET PF-STATUS 'STANDARD' EXCLUDING rt_extab.
SET TITLEBAR text-005.
ENDFORM.
**--Calling the subroutine when button clicked on output
FORM stat USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.
DATA selfield TYPE slis_selfield.
CASE r_ucomm.
**--When Delete Button Pressed
WHEN 'DELE'.
LOOP AT internal table WHERE flag EQ c_x.
DELETE the record from internal table or database
table
ENDLOOP.
ADD also same when press add button insert the records in internal table or database tables and refresh the output layout screen.
to refresh the screen aftyer adding or deleting write below code.
DATA ref1 TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref1.
CALL METHOD ref1->check_changed_data.
CALL METHOD ref1->refresh_table_display.
Don't forget to reward if useful....
ENDCASE.
ENDFORM.
01-07-2008 1:20 PM
Hi Guys
Why do you insist on using Dinosaur Technology (the old way) for ALV grids
The real SIMPLE way using the new cl_gui_alv_grid class is simply to display your table in EDIT mode; You'll then see on a standard toolbar the Insert / delete lines.
You don't need to do any special coding or event handling.
This also ensures the Grid is EDITABLE.
Here's a simple program that does just this. It reads 200 entries from VAPMA and displays them in an editable grid.
It will work for almost any structure as it builds a dynamic FCAT and Dynamic table.
Ensure you have a simple screen (100) with just a custom control on it called CCONTAINER1 and a simple ststus (SE41) with BACK EXIT and CANCEL buttons on it.
Here's the code
Program ZZZ_SIMPLE_EDITABLE_GRID.
* Define any structure
types: begin of s_elements,
vbeln type vapma-vbeln,
posnr type vapma-posnr,
matnr type vapma-matnr,
kunnr type vapma-kunnr,
werks type vapma-werks,
vkorg type vapma-vkorg,
vkbur type vapma-vkbur,
status type c,
end of s_elements.
* end of your structure
tables: vapma.
data lr_rtti_struc type ref to cl_abap_structdescr .
data:
zog like line of lr_rtti_struc->components .
data:
zogt like table of zog,
wa_it_fldcat type lvc_s_fcat,
it_fldcat type lvc_t_fcat ,
dy_line type ref to data,
dy_table type ref to data.
data: dref type ref to data.
field-symbols: <fs> type any,
<dyn_table> type standard table,
<dyn_wa>.
data grid_container1 type ref to cl_gui_custom_container .
data grid1 type ref to cl_gui_alv_grid .
data: ok_code type sy-ucomm.
data: STRUCT_GRID_LSET type lvc_s_layo.
*now I want to build a field catalog
* First get your data structure into a field symbol
create data dref type s_elements.
assign dref->* to <fs>.
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( <fs> ).
zogt[] = lr_rtti_struc->components.
loop at zogt into zog.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = zog-name .
wa_it_fldcat-datatype = zog-type_kind.
wa_it_fldcat-inttype = zog-type_kind.
wa_it_fldcat-intlen = zog-length.
wa_it_fldcat-decimals = zog-decimals.
wa_it_fldcat-coltext = zog-name.
wa_it_fldcat-lowercase = 'X'.
append wa_it_fldcat to it_fldcat .
endloop.
* Let's create a dynamic table and populate it
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = dy_table.
assign dy_table->* to <dyn_table>.
create data dy_line like line of <dyn_table>.
assign dy_line->* to <dyn_wa>.
* Fill the dynamic table
select vbeln posnr matnr kunnr werks vkorg vkbur
up to 200 rows
from vapma
into corresponding fields of table <dyn_table>.
* display grid via screen call.
call screen 100.
module status_0100 output.
if grid_container1 is initial.
create object grid_container1
exporting
container_name = 'CCONTAINER1'.
create object grid1
exporting
i_parent = grid_container1.
struct_grid_lset-edit = 'X'. "To enable editing in ALV
call method grid1->set_table_for_first_display
exporting is_layout = struct_grid_lset
changing
it_outtab = <dyn_table>
it_fieldcatalog = it_fldcat.
endif.
set pf-status '001'.
set titlebar '000'.
endmodule.
MODULE user_command_0100 INPUT.
case sy-ucomm.
when 'BACK'.
leave program.
when 'EXIT'.
leave program.
when 'RETURN'.
leave program.
when others.
endcase.
endmodule.
I don't want to see any more of the old Dinosaur SLIS type of function module calls.
If you now ever need to take take longer than 5 mins to code simple ALV grids then please re-read this post as it is completely general for around 99.99% of SIMPLE Grids (not Trees or complicated data handling).
This should show you the principle easily enough.
Cheers
jimbo
01-08-2008 5:58 AM
Hi burc,
If you are using classes for ALV...
use method
CALL METHOD grid->set_toolbar_interactive. -- where
grid TYPE REF TO cl_gui_alv_grid, (This you should have already defined for creating grid)..
Regards,
Mohaiyuddin
01-08-2008 6:00 AM
Additionally, to copy any changes to your internal table... use method
CALL METHOD grid->check_changed_data. in your PAI.
I forgot to mention in my previous response.
Use
CALL METHOD grid->set_toolbar_interactive. -- in your PBO..