Application Development 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: 

change in mandatory field in selection screen dynamically

naveen_yadavs
Explorer
0 Kudos

Hi Experts,

I have have these fields in selection screen, my requirement is that when i give an input in

contract number then all mandatory has been changed to non-mandatory.

Sales Org. Mandatory TVKO-VKORG Contract Type Mandatory TVAK-AUART Customer
Mandatory KNA1-KUNNR Contract Number VBAK-VBELN

Thanks in advance.

Regards,

Naveen Yadav

5 REPLIES 5

horst_keller
Product and Topic Expert
Product and Topic Expert

You can work with CALL SELECTION-SCREEN in that case.

Call your selection screen after a value is entered in contract number another time and use MODIFY SCREEN during event AT SELECTION-SCREEN OUTPUT.

Oops, have to take that back, since OBLIGATORYs can only be left empty with function codes BACK, CANCEL, EXIT. Doesn't help with Enter or F8, don't get the control in ABAP.

0 Kudos

Hi Horst,

Can you give me an example of this???

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

Now, let's try something like this

PARAMETERS p1.
PARAMETERS p2 OBLIGATORY.

AT SELECTION-SCREEN OUTPUT.
 LOOP AT SCREEN INTO DATA(wa).
   IF wa-required = '1'.
     IF p1 IS INITIAL.
       wa-required = '2'.
     ELSE.
       wa-required = '0'.
     ENDIF.
     MODIFY SCREEN FROM wa.
   ENDIF.
 ENDLOOP.

AT SELECTION-SCREEN ON p2.
 IF p1 IS INITIAL AND p2 IS INITIAL.
   MESSAGE 'Fill P2' TYPE 'E'.
 ENDIF.

START-OF-SELECTION.
 BREAK-POINT.

Jelena
Active Contributor
0 Kudos

Use Google, dynamic selection screens have been covered on SCN ad nauseum. See also this old blog.

All Horst said is valid but, as he mentioned, in ABAP there are no events triggered when you just enter a value in a field or navigate between the fields. So we can't expect exactly what you described to happen. But I believe you might be taking the requirement too literally and there might not be an actual need to manipulate the field attributes. You can simply handle this by checking values in AT SELECTION SCREEN and issuing an error message when the fields entered don't meet the conditions. It might not be as intuitive (since the users don't see mandatory marker on screen) but is usually OK, especially when the fields are pre-filled whenever possible.

Or use the approach similar to the referenced blog and have a radio button for different option. E.g. if the users want to run it by contract then it'd be one option and the rest - another.

Also make sure to test different scenarios (like exiting from the screen or going to the variant). I found that selection screen changes can sometimes lead to unwanted results because the events are triggered not always when you need/expect.

matt
Active Contributor
0 Kudos

This really is a FAQ. But as Horst Keller and Jelena Perfiljeva have given detailed answers, I'll just lock it now rather than reject it. Please SEARCH before posting.