05-11-2017 11:15 AM
I have a requirement in module pool programming. I have to modify an existing custom screen. Requirement is to display a new input field if a existing check box is checked and make it mandatory. if again the check box is unchecked, new field should not be displayed on screen. Please suggest a solution. Thanks a lot.
05-12-2017 1:03 PM
Hello,
In PBO:
Loop at screen.
if screen-name = '<Fieldname>'.
if checkbox = 'X'.
screen-active = 1.
Flag = 'X'. <<<< to make field to act like mandatory field
else.
screen-active = 0.
Flag = ' '
endif.
MODIFY SCREEN
endif.
ENDLOOP.
and in PAI to make the field mandatory..
CHAIN.
FIELD <FIELDNAME> MODULE <MODULENAME>
ENDCHAIN.
MODULE <MODULENAME>.
IF checkbox = 'X' and Flag = 'X' and <fieldname> IS INITIAL.
message 'Field is mandatory' TYPE 'E'.
endif.
ENDMODULE.
thank you!!
05-11-2017 11:43 AM
Hi!
You should set FCODE for your checkbox, and perform PBO processing depending on the checkbox like this:
LOOP AT SCREEN INTO ls_screen
IF ls_screen-name = 'GV_FIELD'
AND p_cbox = abap_true.
ls_screen-active = '1'.
ls_screen-required = '1'.
MODIFY SCREEN FROM ls_screen.
ENDIF.
ENDLOOP.
Hope it's helpful
Evgeny
05-11-2017 11:58 AM
Thank you Evgeny.
But with this solution, new screen field is available with initial execution of program.
My requirement is that new field should be displayed only when check box is ticked.
Regards,
Rahul
05-11-2017 12:02 PM
You can add one more branch in the screen processing for empty checkbox, where you will hide this field via setting parameters I pointed in the answer to '0'.
05-11-2017 11:54 AM
Rather than use SCREEN-NAME I would use a modification group such as SCREEN-GROUP1. Whilst this may not matter in this development, using screen-groups is a better idea since you can then modify multiple fields without having to check each field name. So, in this case I would assign a group to the text field and the input field for the field to be displayed and check the screen group.
Rich
05-11-2017 12:04 PM
Thanks for your notice, I've written this code just for example, how it can be set as required field.
Evgeny
05-12-2017 1:03 PM
Hello,
In PBO:
Loop at screen.
if screen-name = '<Fieldname>'.
if checkbox = 'X'.
screen-active = 1.
Flag = 'X'. <<<< to make field to act like mandatory field
else.
screen-active = 0.
Flag = ' '
endif.
MODIFY SCREEN
endif.
ENDLOOP.
and in PAI to make the field mandatory..
CHAIN.
FIELD <FIELDNAME> MODULE <MODULENAME>
ENDCHAIN.
MODULE <MODULENAME>.
IF checkbox = 'X' and Flag = 'X' and <fieldname> IS INITIAL.
message 'Field is mandatory' TYPE 'E'.
endif.
ENDMODULE.
thank you!!
05-12-2017 1:10 PM
05-12-2017 1:12 PM
Field property will give error message of required field when you will uncheck the checkbox.