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.
Related
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.
After selecting a value in a dropdown listbox field, there is this error message:
Entry is too long for the field
(it's the message number 00092)
I created one text field TXTOPENV as Listbox with key value, set value using VRM_SET_VALUES in PBO section.
Here is the screenshot of screen painter:
Screen flow logic:
PROCESS BEFORE OUTPUT.
MODULE status_0210.
ABAP code:
DATA txtopenv TYPE c LENGTH 1.
MODULE status_0210 OUTPUT.
SET PF-STATUS 'ST210'.
SET TITLEBAR 'T210'.
PERFORM GetVacancy.
ENDMODULE.
FORM GetVacancy.
TYPES: BEGIN OF ty_vacancy,
plans TYPE t528t-plans,
plstx TYPE t528t-plstx,
END OF ty_vacancy.
DATA: wa_vacancy TYPE ty_vacancy.
LOOP AT it_vacancyid INTO wa_vacancyid.
SELECT plans plstx
FROM t528t
INTO wa_vacancy
WHERE plans = wa_vacancyid-ty_objid.
ENDSELECT.
field_id = wa_vacancy-ty_plans.
value = wa_vacancy-ty_plstx.
APPEND value TO values.
CLEAR wa_vacancy.
ENDLOOP.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'TXTOPENV'
values = values
EXCEPTIONS
id_illegal_name = 1
OTHERS = 2.
ENDFORM.
The error "Entry is too long for the field" is not specifically related to the listbox fields, but may occur with all types of screen fields, so I will first answer the general case, and then explain why you were mistaken .
The error happens when the screen field is defined with a "definition length" which is larger than the length defined for the eponym global variable in the ABAP program (eponym: the name has to be the same so that to allow the transfer of values between screen and program, back and forth), and when the input value is larger than the length of the ABAP program.
In your case, the key of the selected value in the listbox is probably larger than 1 character which is the length of the global variable.
The solution in your case is to set the variable to 8 characters:
DATA txtopenv TYPE t528t-plstx.
NB:
In your screenshot of the listbox field with possible values, only the texts are shown, but you can also display the key value via SAP GUI settings Interaction Design > Visualization 1 > Show keys within dropdown lists.
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.
I am using the CL_GUI_ALV_GRID class to display a table. I would like to be able to edit the table (adding new rows and removing all lines), but I don't want existing rows to be editable. That means:
I've got 5 records to display, and I would like to be able to remove and add new records but I don't want the user to edit the 5 existing records (I'd like him to be able to remove them).
Is that possible?
By default when you call the 'LVC_FIELDCATALOG_MERGE' function module to generate a field catalog for the CL_GUI_ALV_GRID, the cells are not editable.
You must set which column is going to be edited setting the 'edit' attribute like this:
...
data: it_fieldcat type lvc_t_fcat,
wa_fieldcat like line of it_fieldcat.
call function 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'ZSTRUCT'
CHANGING
ct_fieldcat = it_fieldcat.
loop at it_fieldcat into wa_fieldcat.
wa_fieldcat-edit = 'X'. " ---->Here is set the editable column
modify it_fieldcat from wa_fieldcat.
endloop.
If you don't want cells to be edited do not set this attribute.
But for better reference check programs 'BCALV_EDIT_03' and 'BCALV_EDIT_04' for complete examples.
Hope it helps.
"Rinka" - field type "checkbox"
"Vadybininkas" - field type "text"
I want: if "Rinka" is selected "First" when in field vadybininkas will be "Pirmas"
I want: if "Rinka" is selected "Second" when in field vadybininkas will be "Antras"
I want: if "Rinka" is selected "Third" when in field vadybininkas will be "Trečias"
My code: #If(Rinka='First'; 'Pirmas'; Rinka='Second';'Antras'; Rinka='Third';'Trecias'; NULL)
But this if statment not work I plaece this code in "Default value", but field "Vadybininkas" is still empty, what is wrong ?
Default value is only calculated ONCE when the document is opened. You need to change your field "Vadybininkas" to "Computed" and put this formula in the "Value"- Section.
In addition you need to tick the property "Refresh fields on Keyword change" for the Rinka- Field or set the "Automatically Refresh Fields"- Property of the form.
Also NULL is not defined in Notes, it will interpret NULL as a non allocated variable name which will have the default value of "" (empty string). NULL is not a defined state in Notes. Just a point but worth knowing!