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: 

mandatory to optional

Former Member
0 Kudos

Hi all ABAP Gurus,

I have a field that is declared as mandatory and I cant change it to optional.

It is mandatory for a flag.

But the field should be optional when I enter the flag as 'X'.

14 REPLIES 14

Former Member
0 Kudos

Hi,

Its a dialog programming or selection screen?

Thanks.

0 Kudos

it is a selection-screen

0 Kudos

check in the

loop at screen

u will find some there.

end loop.

0 Kudos

I guess the only way to do this is by writing a validation in the event

AT SELECTION SCREEN on Checkbox.

If checkbox = 'X'.

if Field is initial.

throw an error message.

endif.

endif.

Hope it helps.

Lokesh

0 Kudos

flag is not a checkbox, it is a field.

i tried with the

loop at screen.

but this doesnt change the field as it still is mandatory.

0 Kudos

Do not declare field as mandatory and check as I suggested before.

Former Member
0 Kudos

You cannot switch from mandatory to optional in a selection screen using AT SELECTION-SCREEN OUTPUT event. You will have to check that yourself in the AT SELECTION-SCREEN event. Check if that field is entered (or not entered) when a certain condition is met and do not allow the user to proceed any further. To achieve this you will have to declare SSCRFIELDS in your TABLES statement and then in your AT SELECTION-SCREEN event do the following.

CASE SSCRFIELDS-UCOMM.

WHEN 'ONLI' OR 'PRIN' OR 'SJOB'.

CLEAR SSCRFIELDS-UCOMM.

IF flag = 'X' AND field IS INITIAL.

MESSAGE E001(00) WITH 'Value for field is required when flag = x'.

ENDIF.

WHEN OTHERS.

ENDCASE.

0 Kudos

there is no change.

It still says "Make an entry in all required fields".

0 Kudos

I cant change it from mandatory to optional

0 Kudos

Hi Ramana,

I dont think there is a direct way of making that field not mandatory.

I have a work around for this.

In event AT SELECTION SCREEN on <Flag>

Enter some junk/default value into FieldA "which you want to not mandatory.

Also make the field disabled, by looping at screen and set invisible parameter = 1.

In Event Start of Selection.

In the very first statement check the Flag = 'X' and FieldA = default value, clear the fieldA.

Hope it helps...

Lokesh

Edited by: Lokesh Aggarwal on Dec 21, 2007 4:12 PM

0 Kudos

If it is your program, why can't you declare this parameter as optional and check for mandatory entry upon the condition being satisfied?

0 Kudos

its not my program, I cant change the existing code.

the mandatory field is in the existing code.

but I can add to it.

I have to write for the flag.

0 Kudos

I still get the same message

0 Kudos

There is no way you can do that without making it optional parameter. The runtime environment does the necessary checks for mandatory entries before even it gives control to you. So unless you remove the mandatory requirement, you will not be able to control its behaviour. Just curious, if it is a custom program, why is it that you cannot make it optional? If there is a genuine requirement to make mandatory only if the flag is 'X', then it is also implicitly understood that you will make changes that are needed.