Mark checkboxes in ALV output grid as selected - abap

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
*----------------------------------------------------------------------*

Related

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

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.

Unhide a column in ALV grid

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á!

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

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.

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.