2009 Jun 09 2:47 PM
Hi,
I have created an ALV grid which displays the data for me (see code below).
FORM create_alv .
FIELD-SYMBOLS: <outtab> TYPE STANDARD TABLE,
<fcat> TYPE lvc_s_fcat.
CHECK gv_alv_obj-defined IS INITIAL.
gv_alv_obj-selection = gv_main_selection.
CREATE OBJECT gv_alv_obj-container
EXPORTING
container_name = 'ALV_CONTAINER'.
CREATE OBJECT gv_alv_obj-grid
EXPORTING
i_parent = gv_alv_obj-container.
ASSIGN gt_outtab->* TO <outtab>.
REFRESH gv_alv_obj-fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = gv_alv_obj-structure_name
CHANGING
ct_fieldcat = gv_alv_obj-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.
READ TABLE gv_alv_obj-fcat ASSIGNING <fcat> WITH KEY fieldname = 'SPRAS'.
IF sy-subrc = 0. " found it so hide it.
<fcat>-no_out = 'X'.
ENDIF.
gv_alv_obj-layout-no_toolbar = 'X'.
gv_alv_obj-layout-zebra = 'X'.
gv_alv_obj-layout-cwidth_opt = 'X'.
gv_alv_obj-layout-no_merging = 'X'.
gv_alv_obj-layout-sgl_clk_hd = 'X'.
CALL METHOD gv_alv_obj-grid->set_table_for_first_display
EXPORTING
is_layout = gv_alv_obj-layout
CHANGING
it_outtab = <outtab>
it_fieldcatalog = gv_alv_obj-fcat
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.
* Once the ALV has been defined set the defined flag.
gv_alv_obj-defined = 'X'.
ENDFORM. " CREATE_ALV
On my main toolbar menu (not the ALV toolbar) I have a few icons.
1) Delete - think this is ok as when I delete a line the cursor moves to the 1st line of the
ALV grid; is this ok or should the cursor go somewhere else? how do I position it to particular row?
2) Copy - Details are copied to a new line I want to move to the copied line and highlight it ? how
3) Display/Modify - Goes to subscreen on exit of subscreen want to be at line where I entered
2009 Jun 09 2:53 PM
Hi,
To place your cursor on a particular field use the method 'SET_SELECTED_CELLS'
of the grid.
Regards,
Ankur Parab
Hi,
To place your cursor on a particular field use the method 'SET_SELECTED_CELLS'
of the grid.
Regards,
Ankur Parab
2009 Jun 09 2:53 PM
Hi,
To place your cursor on a particular field use the method 'SET_SELECTED_CELLS'
of the grid.
Regards,
Ankur Parab
2009 Jun 12 3:50 PM
Hi,
Managed to do it via the following:-
*&---------------------------------------------------------------------*
*& Form SET_SELECTED_ROW
*&---------------------------------------------------------------------*
FORM set_selected_row .
* This defines a section of memory.
FIELD-SYMBOLS: <outtab> TYPE STANDARD TABLE, " This is the table.
<table_line> TYPE ANY, " This is a row within the table.
<fld> TYPE ANY, " This holds the value in the field.
<key_value> TYPE ANY. " This is the value in the field.
DATA: lt_index_rows TYPE lvc_t_row, " ALV control - Table rows.
wa_index_row LIKE LINE OF lt_index_rows, " Line of ALV control - Table rows.
key_fname TYPE fieldname. " This is the name of the field.
* This statement references the same bit of memory thus both gt_outtab & outtab
* are pointing to the same thing so whatever happens to the local outtab will
* also happen to gt_outtab.
ASSIGN gt_outtab->* TO <outtab>.
CASE gv_main_selection.
WHEN co_funder.
key_fname = co_funder.
ASSIGN gv_selected_funder TO <key_value>.
WHEN co_funder_type.
key_fname = co_funder_type.
ASSIGN gv_selected_funder_type TO <key_value>.
ENDCASE.
* Loop at the table <outtab> into a work area (<table_line>).
LOOP AT <outtab> ASSIGNING <table_line>.
* The next statement processes the work_area (<table_line>)
* and assigns the key field names (key_fname) to a field variable (<fld>)
ASSIGN COMPONENT key_fname OF STRUCTURE <table_line> TO <fld>.
* Next a check is made to see if the selected value (<key_value>) is same
* as the value read in the field (<fld>) from above statement.
* If different then the next iteration of the loop occurs.
CHECK <fld> = <key_value>.
* Field read (<fld>) is the same as the selected field value (<key_value>)
* so set the row index (wa_index_row-index) to be that of loop index (sy-tabix)
wa_index_row-index = sy-tabix.
* Append the selected row to the ALV control - Table rows
APPEND wa_index_row TO lt_index_rows.
EXIT.
ENDLOOP.
* Call the set_selected_rows method on the ALV grid.
CALL METHOD gv_alv_obj-grid->set_selected_rows
EXPORTING
it_index_rows = lt_index_rows.
ENDFORM. " SET_SELECTED_ROW
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |