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: 
Read only

mandatory to optional

Former Member
0 Likes
1,795

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

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
Read only

Former Member
0 Likes
1,739

Hi,

Its a dialog programming or selection screen?

Thanks.

Read only

0 Likes
1,739

it is a selection-screen

Read only

0 Likes
1,739

check in the

loop at screen

u will find some there.

end loop.

Read only

0 Likes
1,739

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

Read only

0 Likes
1,739

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.

Read only

0 Likes
1,739

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

Read only

Former Member
0 Likes
1,739

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.

Read only

0 Likes
1,739

there is no change.

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

Read only

0 Likes
1,739

I cant change it from mandatory to optional

Read only

0 Likes
1,739

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

Read only

0 Likes
1,739

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

Read only

0 Likes
1,739

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.

Read only

0 Likes
1,739

I still get the same message

Read only

0 Likes
1,739

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.