‎2008 Feb 12 7:28 PM
Hi,
There is report which uses ALV Grid display. In the Output i can change the value of a coloumn. now if the Output list has several pages,and if i change the value of a filed,say in page 3, and after i press enter the display goes back to page 1.This happens everytime i make a change in any page.I want the display to be in the same page where i make changes. can some one tell me how to handle this? Is there any method for this?
Thanks,
Challa.
‎2008 Feb 13 2:00 AM
Try with
CALL METHOD <ref.var. to CL_GUI_ALV_GRID > ->set_current_cell_via_id
EXPORTING
IS_ROW_ID = <structure of type LVC_S_ROW >
IS_COLUMN_ID = <structure of type LVC_S_COL >
IS_ROW_NO = <structure of type LVC_S_ROID >.
a®
‎2008 Feb 13 2:00 AM
Try with
CALL METHOD <ref.var. to CL_GUI_ALV_GRID > ->set_current_cell_via_id
EXPORTING
IS_ROW_ID = <structure of type LVC_S_ROW >
IS_COLUMN_ID = <structure of type LVC_S_COL >
IS_ROW_NO = <structure of type LVC_S_ROID >.
a®
‎2008 Feb 14 3:53 AM
Hi,
I arrived at that point. But i dont know how to proceed further. If i use CALL METHOD <ref.var. to CL_GUI_ALV_GRID > ->set_current_cell_via_id
EXPORTING
IS_ROW_ID = <structure of type LVC_S_ROW >
IS_COLUMN_ID = <structure of type LVC_S_COL >
IS_ROW_NO = <structure of type LVC_S_ROID >.
If i change the value of a field in a particular row, the display is at the same row but the updated value is not displayed(not getting updated).
Also can you help me how to Pass values to is_row_id and all those parameters. I use event double click to select the filed and change the value.
Thanks,
Challa.
‎2008 Feb 14 11:11 AM
Hi there
I'm feeling kind today so here is a complete example of an editable Grid.
It's really easy --once you've done this you should NEVER need any more info on ALV GRIDS (or at least the Non Tree variety)..
I HATE the stupid Plane seats / airline system used in SAP examples so I've got a MUCH EASIER one here.
Column 1 contains a Hotspot sales order - click it and VA03 is entered . After the display the Grid is re-entered and the last column in the table is updated with a 'V'. The cursor is also placed on the sales order selected.
Other columns can be double clicked - for example if a material is double clicked then MM03 is entered. After the exit from the transaction as before the table is updated with a V and the cursor set to the cell that was double clicked.
There's also a toolbar extra button -- the method doesn't do anything except is entered --here you can add your own code. The toolbar method adds user toolbars to the ALV Grid which are executed in the ON_USER_COMMAND method.
It's all simply commented as well.
As a bonus here I've used the new RTTI functionality (4.6C and onwards) so FOR ANY STRUCTURE we can build automatically a field catalog and a dynamic table so the code here can be used as a model whateverr your actual data structures are.
You can actually edit the data --it currently doesn't do anything however.
You will need to implement ON_DATA_CHANGED
and ON_DATA_CHAGED_FINISHED methods --
These need to be registered via
CALL METHOD grid1->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
You will need also to add the handlers and methods for these -- however like all typical textbooks : I'll leave this as an exercise for our readers.
The code here works --t o add the data changed facility is really easy but you must do something yourselves to show you've understoood the basic functionality.
NO MORE SLIS Function modules needed -- after all this IS the OO Forum.
However to use the program you DO have to do 2 little pieces of work yourselves.
1) create a screen ( SE51) with a single element on it a Custom container called CCONTAINER1. Uncomment the genereated PAI and PBO logic in the screen before you activate it..
2) Create a standard status (SE 41) 001 with a title 000. Just 3 buttons on this are needed BACK, EXIT, CANCEL.
now here's the code
PROGRAM zzz_simple_editable_grid.
INCLUDE <icon>.
DATA grid1 TYPE REF TO cl_gui_alv_grid..
DATA: es_row_no TYPE lvc_s_roid,
ls_row_id TYPE lvc_s_row,
ls_col_id TYPE lvc_s_col,
ls_row TYPE i,
ls_value TYPE c,
ls_col TYPE i,
ls_row_no TYPE lvc_s_roid.
CLASS lcl_event_handler DEFINITION .
PUBLIC SECTION .
METHODS:
**Hot spot Handler
handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id e_column_id es_row_no,
**Double Click Handler
handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column es_row_no,
** Toolbar handler.
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive,
* button press
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS. "lcl_event_handler DEFINITION
CLASS lcl_event_handler IMPLEMENTATION.
*Handle Hotspot Click
METHOD handle_hotspot_click .
PERFORM mouse_click
USING e_row_id
e_column_id.
CALL METHOD grid1->get_current_cell
IMPORTING
e_row = ls_row
e_value = ls_value
e_col = ls_col
es_row_id = ls_row_id
es_col_id = ls_col_id
es_row_no = es_row_no.
CALL METHOD grid1->refresh_table_display.
CALL METHOD grid1->set_current_cell_via_id
EXPORTING
is_column_id = e_column_id
is_row_no = es_row_no.
ENDMETHOD. "lcl_event_handler
*Handle Double Click
METHOD handle_double_click.
PERFORM double_click
USING e_row
e_column.
CALL METHOD grid1->get_current_cell
IMPORTING
e_row = ls_row
e_value = ls_value
e_col = ls_col
es_row_id = ls_row_id
es_col_id = ls_col_id
es_row_no = es_row_no.
CALL METHOD grid1->refresh_table_display.
CALL METHOD grid1->set_current_cell_via_id
EXPORTING
is_column_id = ls_col_id
is_row_no = es_row_no.
ENDMETHOD.
METHOD handle_toolbar.
DATA: ls_toolbar TYPE stb_button.
* append a separator to normal toolbar
CLEAR ls_toolbar.
MOVE 3 TO ls_toolbar-butn_type.
APPEND ls_toolbar TO e_object->mt_toolbar.
* append an icon for your function
CLEAR ls_toolbar.
MOVE 'FUNC' TO ls_toolbar-function.
MOVE icon_railway TO ls_toolbar-icon.
MOVE 'Your Function' TO ls_toolbar-quickinfo.
MOVE 'Your user function' TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD.
METHOD handle_user_command.
BREAK-POINT 1.
CASE e_ucomm.
WHEN 'FUNC'. "Your button
* Perform what you need to do.
WHEN OTHERS.
ENDCASE.
ENDMETHOD.
ENDCLASS.
* 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
DATA:wa_elements TYPE s_elements.
DATA: ord_nr TYPE vapma-vbeln,
mat_nr TYPE vapma-matnr,
cus_nr TYPE vapma-kunnr.
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: g_handler TYPE REF TO lcl_event_handler. "handler
DATA: ok_code TYPE sy-ucomm.
DATA: struct_grid_lset TYPE lvc_s_layo.
START-OF-SELECTION.
*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> ).
* Now get the structure details into a table.
* table zogt[] contains the structure details
* From which we can build the field catalog
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'.
IF wa_it_fldcat-fieldname = 'VBELN'.
wa_it_fldcat-hotspot = 'X'.
ENDIF.
APPEND wa_it_fldcat TO it_fldcat.
ENDLOOP.
*
* You can perform any modifications / additions to your field catalog
* here such as your own column names etc.
* Now using the field catalog created above we can
* build a dynamic table
* and populate it
* First build the dynamic table
* the table will contain entries for
* our structure defined at the start of the program
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>.
* Now fill our table with data
SELECT vbeln posnr matnr kunnr werks vkorg vkbur
UP TO 200 ROWS
FROM vapma
INTO CORRESPONDING FIELDS OF TABLE <dyn_table>.
* Call the screen to display the grid
CALL SCREEN 100.
FORM double_click
USING e_row TYPE lvc_s_row
e_column TYPE lvc_s_col.
READ TABLE <dyn_table> INDEX e_row INTO wa_elements.
CASE e_column-fieldname.
WHEN 'MATNR'.
mat_nr = wa_elements-matnr.
SET PARAMETER ID 'MAT' FIELD mat_nr.
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
WHEN 'KUNNR'.
cus_nr = wa_elements-kunnr.
SET PARAMETER ID 'KUN' FIELD cus_nr.
CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
WHEN OTHERS.
ENDCASE.
wa_elements-status = 'V'.
MODIFY <dyn_table> FROM wa_elements INDEX e_row.
ENDFORM.
FORM mouse_click
USING e_row TYPE lvc_s_row
e_column_id TYPE lvc_s_col.
READ TABLE <dyn_table> INDEX e_row INTO wa_elements.
ord_nr = wa_elements-vbeln.
SET PARAMETER ID 'AUN' FIELD ord_nr.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
wa_elements-status = 'V'.
MODIFY <dyn_table> FROM wa_elements INDEX e_row.
ENDFORM.
* PBO module
MODULE status_0100 OUTPUT.
DATA: off TYPE int4.
IF sy-batch = 'X'.
CALL METHOD cl_gui_alv_grid=>offline
RECEIVING
e_offline = off.
ENDIF.
IF sy-batch = 'X'.
IF ( off IS INITIAL ).
CREATE OBJECT grid_container1
EXPORTING
container_name = 'CCONTAINER1'.
CREATE OBJECT grid1
EXPORTING
i_parent = grid_container1.
ENDIF.
ENDIF.
IF sy-batch NE 'X'.
IF grid_container1 IS INITIAL.
CREATE OBJECT grid_container1
EXPORTING
container_name = 'CCONTAINER1'.
ENDIF.
CREATE OBJECT grid1
EXPORTING
i_parent = grid_container1.
IF sy-batch NE 'X'.
struct_grid_lset-edit = 'X'. "To enable editing in ALV
ENDIF.
ENDIF.
CREATE OBJECT g_handler.
SET HANDLER g_handler->handle_double_click FOR grid1.
SET HANDLER g_handler->handle_hotspot_click FOR grid1.
SET HANDLER g_handler->handle_toolbar FOR grid1.
SET HANDLER g_handler->handle_user_command FOR grid1.
CALL METHOD grid1->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
CALL METHOD grid1->set_table_for_first_display
EXPORTING is_layout = struct_grid_lset
CHANGING
it_outtab = <dyn_table>
it_fieldcatalog = it_fldcat.
SET PF-STATUS '001'.
SET TITLEBAR '000'.
ENDMODULE.
* PAI module
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
LEAVE PROGRAM.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'RETURN'.
LEAVE PROGRAM.
WHEN OTHERS.
ENDCASE.
ENDMODULE.
Cheers
and isn't it easy !!
jimbo