How to get SALV ALV field value in a double-click event? - abap

I'm using cl_salv_table ALV for sflight table data. I want to get the value of the field thats double-clicked and then display it in pop up window. I defined lcl_handle_events class with appropriate method. Double click works, for example when I double clicked on any row I can display message, but I don't know how to display the double clicked value. How to display double clicked cell in pop up window?
DATA schedule TYPE STANDARD TABLE OF sflight.
CLASS lcl_handle_events DEFINITION.
PUBLIC SECTION.
METHODS:
on_double_click FOR EVENT double_click OF cl_salv_events_table
IMPORTING row column.
ENDCLASS.
CLASS lcl_handle_events IMPLEMENTATION.
METHOD on_double_click.
DATA value TYPE sflight.
READ TABLE schedule INTO value INDEX row.
* MESSAGE 'Row clicked.' TYPE 'I'.
ENDMETHOD.
ENDCLASS.

you can use with this function:
'POPUP_TO_INFORM'
for example:
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = 'XXXXX '
txt1 = Row clicked
txt2 = 'XXXXXXXX'.

You have the "column" parameter for the double_click event. It contains the field name, so you can access the value with a field symbol:
FIELD-SYMBOLS: <clicked_field> TYPE any.
READ TABLE schedule INTO value INDEX row.
IF sy-subrc = 0.
ASSIGN COMPONENT lv_column of STRUCTURE value to <clicked_field>.
MESSAGE |Value of clicked field { <clicked_field> }| TYPE 'I'.
ENDIF.

Related

Get row ID when user double clicks the row in ALV report

I have a scenario which displays a list of purchase documents as ALV (function module REUSE_ALV_LIST_DISPLAY). By clicking on a purchase doc no, its specific details (e.g. NETPR) should show in a pop up. How should I do it?
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE r_ucomm.
WHEN '&IC1'.
READ TABLE ITAB INTO WA WITH KEY EBELN = WA-EBELN.
PERFORM popup_display.
ENDCASE.
ENDFORM. "user_command
Inside the subroutine in structure RS_SELFIELD is what you need:
field TABINDEX contains the line, which was double clicked (you can READ TABLE the internal table which holds the data with INDEX rs_selfield-tabindex) and field FIELDNAME contains the field, which was clicked (if that is relevant in your case).
Also check the documentation of the function module SE37 => Function Module Documentation, lots of useful information there see I_CALLBACK_USER_PROGRAM

Mark checkboxes in ALV output grid as selected

I am creating an ALV output grid using class cl_gui_alv_grid. One of the columns of the output table is defined as a checkbox by using the corresponding record of the fieldcatalog:
ls_fcat-checkbox = 'X'.
ls_fcat-edit = 'X'.
For all the records of the column that contains the checkboxes, they are all set as unselected. My question is what logic can I implement in order that for some of the rows, the checkboxes to be set as selected when I display the ALV.
If you want to set the checkbox according to initially shown data in the alv grid, just fill your outtab checkbox field with abap_true (='X') if condition is matched. If you would not use the checkbox parameter of the fieldcatalog you would just see 'X' for checked and ' ' for not checked.
If you want to set the checkbox according to user input, after they edited some fields in the alv grid, use the following alv grid events to change outtab:
METHODS:
handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed,
handle_data_changed_finished FOR EVENT data_changed_finished OF cl_gui_alv_grid, "executed only if no errors, outtab holds changed data
I also found some comments I made, when I had to deal with these events
*&---------------------------------------------------------------------*
*& Method handle_data_changed
*&---------------------------------------------------------------------*
* raised when at least one cell is modified in the ALV
* - modified entries are not stored in gt_outtab yet, but er_data_changed object
* - mt_good_cells holds every changed field thats valid according to type declaration
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Method handle_data_changed_finished
*&---------------------------------------------------------------------*
* - raised when data validation is valid
* - NOW outtab holds valid changed data
*----------------------------------------------------------------------*

How to set the default value and read the selected value of a Dropdown Listbox

So I've added a field with the Dropdown type as Listbox via Screen Painter (SE51).
I've binded the data to the dropdown using the PBO and the VRM_SET_VALUES function.
I have 2 problems with this;
How do you set a selected value to the binded data?
How do you get the value selected by the user.
Data is bound to the dropdown using the following code;
LOOP AT it_zzdelay_text INTO wa_zzdelay_text.
wa_listbox-key = wa_zzdelay_text-zz_delay_reason.
wa_listbox-text = wa_zzdelay_text-zz_delay_reason_text.
APPEND wa_listbox TO it_listbox.
ENDLOOP.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'ZZ_DELAY_REASON'
values = it_listbox.
The zz_delay_reason is the unique key and the zz_delay_reason_text is the accompanying text.
Update:
According to your code, the field on the screen should be: ZZ_DELAY_REASON
And you also need a global variant with the name.
Then you can Set/Get key value in PBO/PAI:
Set value:
ZZ_DELAY_REASON = 'KEY'.
Get Selected Value(key):
lv_key = ZZ_DELAY_REASON
======================================================
When select list is set by VRM_SET_VALUES, you may notice it is a "Key-Value" pair. The field "KEY" is filled into the screen field value when the user selects drop box.
I could provide detailed information if you attach your code in this question.
Firstly, several prerequisites are to be met to make a functional drop-down:
You item table should have type vrm_values
Values that are showed in the list should be in field text of the item line. Key should be in field key.
PARAMETER should have type LISTBOX.
After all that is done, answers for your questions would be:
Relation of KEY-VALUE is done via vrm_values type. Each line of this type is an drop-down item, where text is a visible text, and key is key.
Parameter automatically gets the key value after user selects the item in the listbox.
Here is the sample code:
REPORT drop-down.
TYPE-POOLS: vrm.
PARAMETERS p_werks LIKE t001w-werks VISIBLE LENGTH 20 AS LISTBOX OBLIGATORY.
DATA: t_werks TYPE vrm_values,
w_line LIKE LINE OF t_werks.
INITIALIZATION.
SELECT werks name1
FROM t001w INTO (w_line-key, w_line-text).
APPEND w_line TO t_werks.
ENDSELECT.
AT SELECTION-SCREEN OUTPUT.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'P_WERKS'
values = t_werks.
END-OF-SELECTION.
WRITE: / 'Selected factory:', p_werks.

Web Dynpro ALV conditionally editable cells

The problem is I want that some cell of checkbox column in my WD ALV will be editable some cell will be non editable depending on some property.
I make next steps to achieve the required result:
1) Add attribute READONLY type WDY-BOOLEAN to the corresponding node ( attribute CHECK type WDY-BOOLEAN has already added ) .
2) Then in my code I Check some conditions in row of my table and assign attribute READONLY value abap_true or abap_false.
3) Then I bind my node with table. Table is filled correctly, I checked in debugger.
4) Configure my alv:
DATA: lo_table_settings TYPE REF TO if_salv_wd_table_settings,
lo_column_settings TYPE REF TO if_salv_wd_column_settings,
lo_column TYPE REF TO cl_salv_wd_column.
lo_column_settings ?= lv_value.
lo_table_settings ?= lv_value.
lo_column = lv_value->if_salv_wd_column_settings~get_column( 'CHECK' ).
DATA lr_checkbox TYPE REF TO cl_salv_wd_uie_checkbox.
" create checkbox
CREATE OBJECT lr_checkbox
EXPORTING checked_fieldname = 'CHECK'.
" make our table is editable
lo_table_settings->set_read_only( abap_false ).
lo_column = lo_column_settings->get_column( 'CHECK' ).
" Creating UI Elmenent 'INPUT FIELD' to make the column editable
DATA: lr_input_field TYPE REF TO cl_salv_wd_uie_input_field.
CREATE OBJECT lr_input_field EXPORTING value_fieldname = 'CHECK'.
lr_checkbox->set_read_only_fieldname( value = 'READONLY' ).
lv_value->if_salv_wd_column_settings~delete_column( ID = 'READONLY' ).
But it doesn't work, all of cells of checkbox column is editable and I don't get non editable cells of checkbox column.
To make a field A editable or readonly, it's only a matter of "using a field B's value to the A's readonly property".
So, as I understand , you have a column which is checkbox, and you want some rows to be editable ,and others to be readonly.
To do so, you won't need to create input field, the only thing you need to do is get the checkbox column reference and set its readonly property bind to the field in your data structure.
if that still doesn't work, check your data, whether the readonly field's value of each record is '', if yes, then of course, every cell of the check will be editable.
Your first step is correct. You added attribute READONLY of type WDY-BOOLEAN to your node and assigned it abap_true value before calling the grid.
The next step is to create input field reference for each field/row which you wanna make editable and assign this reference to the field attribute READONLY and change this attribute only for the lines that fit the condition.
Here is the sample code:
Initial assignment
loop at lt_table assigning field-symbol(<fs_table>).
<fs_table>-read_only = abap_true. " non editable
endloop.
Setting column editibility
* input type reference
data lr_input type ref to cl_salv_wd_uie_input_field.
* Retrieving all column id and reference
call method lv_value->if_salv_wd_column_settings~get_columns
receiving
value = data(lt_columns).
loop at lt_columns into ls_columns.
* Assigning column reference
data(lr_column) = ls_columns-r_column.
* Creating input field UI Element
create object lr_input
exporting
value_fieldname = ls_columns-id.
*Assigning input field to column to make it as editable
call method lr_column->set_cell_editor
exporting
value = lr_input.
* binding input field ref to READONLY field
lr_input->set_read_only_fieldname( value = "READONLY" ).
endloop.
Making single lines editable based on condition
loop at lt_table assigning field-symbol(<fs_table>).
if smth = abap_true
<fs_table>-read_only = abap_false. " non editable
endif.
endloop.
Check this guide for reference.

Double clicking a row and column in ALV Grids

Currently I have an ALV grid and I can double click to call transaction IE03 and pass the information in the first column (which is eqkt-equnr). However, this transaction is called regardless of what column you click on. This wouldn't be so bad, but I need to be able to call IW33 if you click on the 3rd column and pass along the equz-J_3GEIGNER value there.
My current double click code is as follows. t_report is my struct and matnr is the equnr part of it. maktx is the J_3GEIGNER part of it.
FORM user_command USING r_ucomm
wa_selrow TYPE slis_selfield.
IF r_ucomm = '&IC1'.
READ TABLE t_report INDEX wa_selrow-tabindex.
IF sy-subrc = 0.
SET PARAMETER ID 'EQN' FIELD t_report-matnr.
CALL TRANSACTION 'IE03' AND SKIP FIRST SCREEN.
ENDIF.
ENDIF.
ENDFORM.
Use the field wa_selrow-fieldname to determine which column was clicked. Be aware that you may have to switch the grid from row selection mode to cell selection mode - since you didn't show us how you created the grid in the first place, I can't tell you how to do this in your case. Take a look at the SEL_MODE property, it might help.