2008 Mar 24 11:43 AM
hai all.
iam having one query in alv .
after completing our program we are executing the output.
how can we change the output feild values ?after changing output when ever i press save ,it will automatically should updates the database.how?
help me ..
tanx in advance
2008 Mar 24 12:00 PM
this is one such requirement where u got to modularize the code accordingly. u can refresh the alv list and again display it using the same alv function module. for events u got to check with event handlers in alv by first registering it. create a form routine that is to be called when the SAVE (created using pf status) icon is cliked. using modify/insert u can process the records to the DB
2008 Mar 24 12:06 PM
Go thru the program
BCALV_TEST_GRID_EDIT_01
or in se38
BCALVEDIT and F4
you can use these examples to edit and then save whenever required.
santhosh
2008 Mar 24 12:06 PM
Hi,
Think that the fields that are dispalyed in the output should be in the editable mode(i.e,ready for input that u give).
So first to make the fields to editable mode, try using the structure LVC_S_STYLE.
Declare a field of type LVC_S_STYLE in ur internal table,
Now,in ur new PERFORM chk this code:
ls_stylerow type LVC_S_STYLE.
LOOP AT it_itab INTO wa_itab.
ls_stylerow-fieldname = 'FIELD2' . "Field which you want to make it editable
ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled. "set field to enabled
APPEND ls_stylerow TO wa_itab-field_style.
MODIFY it_itab FROM wa_itab.
ENDLOOP.
Now this will set your fields to editable mode and now you can write the code for updation of database after u click save.
Hope this is helpful.
Plz reward points if helpful.
Thanks.
Edited by: Kalyan Chakravarthi on Mar 24, 2008 1:08 PM
Edited by: Kalyan Chakravarthi on Mar 24, 2008 1:09 PM
2008 Mar 24 12:10 PM
Satya vani,
Use User Command event when you press Save button.
Regards
Joseph
2008 Mar 24 12:17 PM
Hi satya,
first of all you have to make that field editable in the alv o/p
for this while creating the field cat you should do
l_fieldcat-input = 'X'. "Making the field editable
l_fieldcat-edit = 'X'.
After doing that when user change the content if that field on the o/p screen and press save in the menu then in the user_command handling read that line of your internal table from index " rs_selfield-tabindex " .
now make the required change in that line of your internal table and modify ur internal table from the same index .
now you have to call the same FM for generating alv with that modified internal table .
this will physically post that new alv over ur previous alv and you can get the modified output after pressing save.
let me knw if u need further clearification on this n reward points if helpful.
2008 Mar 24 12:24 PM
&----
*& Report ZUS_SDN_ALVGRID_EDITABLE_8
*&
*& Description: editable ALV -> ENTER jumps to next row
&----
*& Dynpro flow logic: no screen elements, ok_code = GD_OKCODE
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
***
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
**
*&
&----
REPORT zus_sdn_alvgrid_editable_8.
DATA:
gd_repid TYPE syst-repid,
gd_okcode TYPE ui_func,
*
gt_fcat TYPE lvc_t_fcat,
go_docking TYPE REF TO cl_gui_docking_container,
go_grid TYPE REF TO cl_gui_alv_grid.
DATA:
gt_knb1 TYPE STANDARD TABLE OF knb1.
CLASS lcl_eventhandler DEFINITION
*
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING
er_data_changed
e_onf4
e_onf4_before
e_onf4_after
e_ucomm
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
CLASS lcl_eventhandler IMPLEMENTATION
*
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_data_changed.
define local data
cl_gui_cfw=>set_new_ok_code( 'NEXT_ROW' ). " not possible on 4.6c
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'NEXT_ROW'
IMPORTING
RC =
.
" Triggers PAI of dynpro with ok_code = 'NEXT_ROW'
ENDMETHOD. "handle_data_changed
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
PARAMETERS:
p_bukrs TYPE bukrs DEFAULT '2000' OBLIGATORY.
START-OF-SELECTION.
SELECT * FROM knb1 INTO TABLE gt_knb1
WHERE bukrs = p_bukrs.
Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
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 ALV grid
CREATE OBJECT go_grid
EXPORTING
i_parent = go_docking
EXCEPTIONS
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.
" Triggers event DATA_CHANGED when ENTER is pushed
CALL METHOD go_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter
EXCEPTIONS
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.
SET HANDLER:
lcl_eventhandler=>handle_data_changed FOR go_grid.
Build fieldcatalog and set hotspot for field KUNNR
PERFORM build_fieldcatalog_knb1.
Display data
CALL METHOD go_grid->set_table_for_first_display
CHANGING
it_outtab = gt_knb1
it_fieldcatalog = gt_fcat
EXCEPTIONS
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.
Link the docking container to the target dynpro
gd_repid = syst-repid.
CALL METHOD go_docking->link
EXPORTING
repid = gd_repid
dynnr = '0100'
CONTAINER =
EXCEPTIONS
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.
ok-code field = GD_OKCODE
CALL SCREEN '0100'.
END-OF-SELECTION.
&----
*& Module STATUS_0100 OUTPUT
&----
text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
SET TITLEBAR 'xxx'.
CALL METHOD go_grid1->refresh_table_display
EXPORTING
IS_STABLE =
I_SOFT_REFRESH =
EXCEPTIONS
FINISHED = 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.
ENDMODULE. " STATUS_0100 OUTPUT
&----
*& Module USER_COMMAND_0100 INPUT
&----
text
MODULE user_command_0100 INPUT.
go_grid->check_changed_data( ).
CASE gd_okcode.
WHEN 'BACK' OR
'END' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
" NOTE: ENTER button alone works apparently only if the cursor
" is placed within the command window (left-upper corner)
WHEN 'ENTER' OR
'NEXT_ROW'.
PERFORM set_cursor_next_row.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
&----
*& Form BUILD_FIELDCATALOG_KNB1
&----
text
--> p1 text
<-- p2 text FORM build_fieldcatalog_knb1 .
define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_BUFFER_ACTIVE =
i_structure_name = 'KNB1'
I_CLIENT_NEVER_DISPLAY = 'X'
I_BYPASSING_BUFFER =
I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT gt_fcat INTO ls_fcat
WHERE ( fieldname = 'ZUAWA' ).
ls_fcat-edit = abap_true.
ls_fcat-col_opt = abap_true.
MODIFY gt_fcat FROM ls_fcat.
ENDLOOP.
ENDFORM. " BUILD_FIELDCATALOG_KNB1
&----
*& Form SET_CURSOR_NEXT_ROW
&----
text
--> p1 text
<-- p2 text FORM set_cursor_next_row .
define local data
DATA:
ls_row TYPE lvc_s_row,
ls_col TYPE lvc_s_col.
CALL METHOD go_grid->get_current_cell
IMPORTING
E_ROW =
E_VALUE =
E_COL =
es_row_id = ls_row
es_col_id = ls_col
ES_ROW_NO =
.
ADD 1 TO ls_row-index. " next row
CALL METHOD go_grid->set_current_cell_via_id
EXPORTING
is_row_id = ls_row
is_column_id = ls_col
IS_ROW_NO =
.
ENDFORM. " SET_CURSOR_NEXT_ROW[/code]
and demo programs
bcalv_edit_01 to 08
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |