Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Define mandatory field in reuse_alv_grid_display

hagit
Active Participant
1,203

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

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
1,125

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.

8 REPLIES 8

Sandra_Rossi
Active Contributor
1,126

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.

hagit
Active Participant
1,125

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

0 Kudos
1,125

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.

hagit
Active Participant
0 Kudos
1,125

sandra.rossi Thank you for your answer.

When is SET_PF_STATUS event triggered?

Is it like PBO ?

Tahnk you

Hagit

0 Kudos
1,125

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".

hagit
Active Participant
0 Kudos
1,125

sandra.rossi

What is not supported?

Is the event triggering time not supported? Or something else?

0 Kudos
1,125

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.

hagit
Active Participant
0 Kudos
1,125

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