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.
Related
I have two SAP systems with the same program.
The column Nome 2 is displayed in the ALV grid of the system1 but in the ALV grid of the system2 is hidden and when select the details you could see the Nome 2 value in both sistems.
The program uses field catalog to pass a list of fields to display in ALV, and also uses the function 'REUSE_ALV_GRID_DISPLAY'.
I would be very pleased if someone have any suggestions that could solve it.
Regards,
Nataly
Check the no-out property of fieldcatalog in system 1. It seems to be enabled there:
You suppose to search lines like this:
IF T_FIELDCAT-FIELDNAME = 'NOME1'.
T_FIELDCAT-NO_OUT = 'X'.
MODIFY T_FIELDCAT INDEX sy-tabix.
ENDLOOP.
Remove NO-OUT line and voilá!
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 have a datagridview with columns added from the designer, the data for this grid will be selected from the database and will be directly bound to the grid. For this purpose I have DataPropertyName to the column names of the database table.
I am setting the datasource like this :
dgPayment.DataSource = myDatatable
Now I need to clear the rows of the datagridview without removing the headers of the datagridview. I tried using dgPayment.Rows.Clear(), but this prompted a error because the grid is bound & therefore the rows cannot be manually altered. I also tried setting the datasource to nothing like this :
dgPayment.DataSource = Nothing
But this removes the headers too, which doesn't need to happen because they are the column headers that I added using the designer. How can I clear only the data without clearing the headers.
If you create columns through designer, then in form constructor or in Load event handler put next line of code
dgPayment.AutoGenerateColumns = false
Then freely use dgPayment.DataSource = Nothing for removing all rows
Remove only rows from the datatable.
DataTable.Rows.Clear(). This will keep the columns intact.
Then to refresh the data -
CurrencyManager cm = ((CurrencyManager)) dataGridView1.BindingContext[dataGridView1.DataSource];
cm.Refresh();
Try like this
dataGridView1.DataSource.Rows.Clear()
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.
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.