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: 

How can I make a field mandatory in selection screen when i click my check

Former Member
0 Kudos

Hi

How can I make a field mandatory in selection screen when i click my check box.

Description:

In the selection screen having one parameter and check box, By default parameter is optional.

When user click the check box parameter should be change as mandatory.

Please send me code if you know

Thanks in advance,

Satya.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

you have at least two ways:

1. do the check in the AT SELECTION-SCREEN ON OUTPUT -> E- message, if checkbox is set, but your other field not

or if the two fields are in the same selection-screen block make the check in AT SELECTION-SCREEN ON BLOCK xyz

2. Modify SCREEN-Table at event AT SELECTION-SCREEN ON OUTPUT

this requires a bit more experience, but is better from user view.

Pseudo-Code (currently no system available):

LOOP AT SCREEN.

IF checkbox is set.

if screen-fieldname (or so) eq <the field you want to set obligatory>

SCREEN-<obligatory flag> = 'X'.

endif.

ENDIF

MODIFY SCREEN.

ENDLOOP.

7 REPLIES 7

Former Member
0 Kudos

Check whether it is working for your requirement

REPORT Z_TEST message-id zz.

PARAMETERS: p1 AS CHECKBOX USER-COMMAND r MODIF ID md5.

PARAMETERS: p_matnr TYPE matnr.

IF p1 ='X' and p_matnr is initial.

MESSAGE e000 WITH text-005.

ENDIF.

end-of-selection.

write: 'Test successful'.

Edited by: mukesh kumar on Jan 17, 2008 9:05 AM

Former Member
0 Kudos

Hi,

you have at least two ways:

1. do the check in the AT SELECTION-SCREEN ON OUTPUT -> E- message, if checkbox is set, but your other field not

or if the two fields are in the same selection-screen block make the check in AT SELECTION-SCREEN ON BLOCK xyz

2. Modify SCREEN-Table at event AT SELECTION-SCREEN ON OUTPUT

this requires a bit more experience, but is better from user view.

Pseudo-Code (currently no system available):

LOOP AT SCREEN.

IF checkbox is set.

if screen-fieldname (or so) eq <the field you want to set obligatory>

SCREEN-<obligatory flag> = 'X'.

endif.

ENDIF

MODIFY SCREEN.

ENDLOOP.

Former Member
0 Kudos

Hi

Check below code:


parameters: p_ch as checkbox user-command abc,
            p_text(10) type c.

at selection-screen output.
   loop at screen.
        check screen-name cp 'P_TEXT'.
        if not p_ch is initial.
           screen-required = 1.
        else.
           screen-required = 0.
        endif.
        modify screen.
   endloop.

By the basic characteristic of Mandatory field, once it is set value has to be populated before further processing can take place.

Kind Regards

Eswar

former_member404244
Active Contributor
0 Kudos

Hi,

try like this

AT SELECTION-SCREEN OUTPUT.

if check = 'X'.

LOOP AT SCREEN.

IF SCREEN-NAME = 'P_FIELD'.

SCREEN-REQUIRED = 1.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

ENDIF.

Regards,

Nagaraj

Former Member
0 Kudos

One way is as Mukesh suggested that you check for the checkbox value and do a customized check in your code.

Other way something like this:

IF p_check = 'X'.

LOOP AT SCREEN .

IF screen-name = 'P_FIELD2' .

screen-required = '1'.

MODIFY SCREEN.

EXIT.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT SCREEN .

IF screen-name = 'P_FIELD2' .

screen-required = '0'.

MODIFY SCREEN.

EXIT.

ENDIF.

ENDLOOP.

ENDIF.

But in this way, if it is made required once, you NEED to enter something in it before you can make it non-mandatory again....

Former Member
0 Kudos

Hi,

First thanx for your rapid reply ,

Your solution is almost correct one problem is there as for your code ,if click on check box it is setting as mandatory but later if uncheck the check box that time also its shows as mandatory .

thanks in advance

Satya.

0 Kudos

As specified in the earlier post, once the field is set to Mandatory. You need to populate value before any r processing can take place.

Alternatively, you can use: AT SELECTION-SCREEN Event and populate error mesg if Check box is NOT initial.

Kind Regards

Eswar