2022 Dec 28 8:45 AM
Hello Experts,
When calling reuse_alv_grid_display I defined field as editable and add a button to insert a new record. How can I define a field as mandatory?
In the field catalog I tried to set
key_sel = abap_true
sel = abap_true
but it did not help.
thank you in advance
Hagit
2022 Dec 28 10:32 AM
REUSE_ALV_GRID_DISPLAY was not designed to permit that easily. You can only easily control while validating the full data.
Use CL_GUI_ALV_GRID and event DATA_CHANGED to validate yourself the fields. See example code in comment in https://answers.sap.com/questions/3654347/mandatory-field-in-editable-alv.html.
If you want the field to be controlled immediately, you need to first call the method register_edit_event with parameter i_event_id = cl_gui_alv_grid=>mc_evt_modified, so that DATA_CHANGED is called each time you leave a field.
2022 Dec 28 10:32 AM
REUSE_ALV_GRID_DISPLAY was not designed to permit that easily. You can only easily control while validating the full data.
Use CL_GUI_ALV_GRID and event DATA_CHANGED to validate yourself the fields. See example code in comment in https://answers.sap.com/questions/3654347/mandatory-field-in-editable-alv.html.
If you want the field to be controlled immediately, you need to first call the method register_edit_event with parameter i_event_id = cl_gui_alv_grid=>mc_evt_modified, so that DATA_CHANGED is called each time you leave a field.
2022 Dec 28 1:42 PM
sandra.rossi thank you for your answer.
Do you mean that I can use CL_GUI_ALV_GRID and event DATA_CHANGED when using reuse_alv_grid_display?
If yes, then where should I define the event data_changed?
if I do it after the call to reuse_alv_grid_display (line 79) then a dump is raised because lo_alv is initial
class LCL_EVENT_REGISTER
thank you
Hagit
2022 Dec 28 2:58 PM
So you tried the not-easy way, by getting the underlying ALV Grid Control object behind REUSE_ALV_GRID_DISPLAY by calling GET_GLOBALS_FROM_SLVC_FULLSCR. It works only if the ALV Grid is still displayed (during execution of callback subroutines), it cannot work after it's not displayed anymore (i.e. after REUSE_ALV_GRID_DISPLAY).
If you want to continue this way, you must execute your code while REUSE_ALV_GRID_DISPLAY is running and after it has instantiated the Control, either in the callback subroutines (maybe during SET_PF_STATUS event) or via Implicit Enhancement Options.
2022 Dec 28 3:05 PM
sandra.rossi Thank you for your answer.
When is SET_PF_STATUS event triggered?
Is it like PBO ?
Tahnk you
Hagit
2022 Dec 28 3:17 PM
I don't know, "maybe" as I said. What is important is to find a place, "while REUSE_ALV_GRID_DISPLAY is running and after it has instantiated the Control", I have just given possibilities. Of course, this is not supported by SAP, i.e. it might change (although I think it won't). A GUI Status must be set during the PBO, so I guess it's true to say "it is like PBO".
2022 Dec 28 5:28 PM
sandra.rossi
What is not supported?
Is the event triggering time not supported? Or something else?
2022 Dec 28 5:33 PM
The way you do it is not supported: you are looking for a hack while using REUSE_ALV_GRID_DISPLAY, to trigger the event DATA_CHANGED after pressing TAB or ENTER, and to trigger ABAP code when the event DATA_CHANGED. You are mixing 2 technologies, this was not intended to be used like that by SAP.
2022 Dec 28 7:07 PM
sandra.rossi
I already use REUSE_ALV_GRID_DISPLAY, so it is complicated to change it to CL_GUI_ALV_GRID & DATA_CHANGED event.
According to your comment I will not mix the 2 technologies.
What do you think about the following solution:
In user_command routine – When r_ucomm = &DATA_SAVE
Loop at gt_out into data(ls_out).
if ls_out-fld1 is initial or ls_out-fld10 is initial .
message ….
endif.
endloop.
thank you