05-29-2007 4:24 AM
Hi,
How can i put a contraint that only a single checkbox can be selected from a no. of checkboxes from a column. In case i select more than 1 checkbox, the program should give an appropriate error message and exit.
Thanx in advance,
Mohit.
05-29-2007 4:50 AM
this is a small piece of code(just an idea not a full code)... do like this..
tables mara.
data : begin of itab occurs 0,
chk,
matnr like mara-matnr,
end of itab.
data : counter type i,
lin type i,
chk.
start-of-selection.
select matnr into corresponding fields of table itab from mara up to 20 rows.
*set pf-status 'ZSPD'.
loop at itab.
write : / itab-chk as checkbox, itab-matnr.
hide itab.
endloop.
at line-selection.
clear counter.
describe table itab lines lin.
do lin times.
read line sy-index field value itab-chk into chk.
if chk = 'X'.
counter = counter + 1.
endif.
if counter gt 1.
clear counter.
message 'Pls check only one check box' type 'I'.
leave program.
endif.
enddo.
please change the code as you need it will by default show a detail button(magnifying glass) in application tool bar just click that after clicking in two or thrre check boxes. But here you have to set your own pf-status(like zspd just uncomment that and dbl click to set your pf status) and must press some fn key for getting the desired output.
regards
shiba dutta
05-29-2007 4:25 AM
Hi,
if you want to do this in ALV, you can check this in the After input event and give warning/error message there.
Reward points if useful.
Regards,
Atish
05-29-2007 4:26 AM
You can use radiobuttons for such requirement instead.
Regards
Gopi
05-29-2007 4:26 AM
Hi Mohit Goel,
Instead of using the check box u can use Radio Button for ur Requirement i hope ....
Thanks & Regards
Bhaskar Rao.M.
05-29-2007 4:28 AM
Hi,
i have this boundation 2 do this task WITHOUT radoibuttons. i need to throw an error msg. when i select multiple checkboxes...
Thanks,
MOHIT.
05-29-2007 4:32 AM
Hello
Use the same code That i posted above and include your error message also accordingly...Insted of CASE...ENDCASE you can use IF also and in the ELSE clause you can add your error messages...Try This ,this will Work...
Reward All Helpfull Answers...........
05-29-2007 4:27 AM
Hi Mohit
Do Like this.........
parameters: p_chk1 as checkbox default 'X' user-command p_sel1.
parameters: p_chk2 as checkbox user-command p_sel2.
parameters: p_chk3 as checkbox user-command p_sel3.
parameters: p_chk4 as checkbox user-command p_sel4.
at selection-screen output.
case sy-curow.
when 1.
clear: p_chk2, p_chk3, p_chk4.
when 2.
clear: p_chk1, p_chk3, p_chk4.
when 3.
clear: p_chk1, p_chk2, p_chk4.
when 4.
clear: p_chk1, p_chk2, p_chk3.
endcase.
Change This Code According to your Requirment....
Reward All Helpfull Answers.........
05-29-2007 4:28 AM
hi
if want to do the same thing in a list, use READ LINE command
something like this
do mline times.
READ LINE SY-INDEX FIELD VALUE ITAB-FLAG.
IF ITAB-FLAG NE SPACE.
chk = chk + 1.
endif.
if chk > 1.
write 'Error'.
endif.
if helpful, reward
Sathish. R
05-29-2007 4:50 AM
this is a small piece of code(just an idea not a full code)... do like this..
tables mara.
data : begin of itab occurs 0,
chk,
matnr like mara-matnr,
end of itab.
data : counter type i,
lin type i,
chk.
start-of-selection.
select matnr into corresponding fields of table itab from mara up to 20 rows.
*set pf-status 'ZSPD'.
loop at itab.
write : / itab-chk as checkbox, itab-matnr.
hide itab.
endloop.
at line-selection.
clear counter.
describe table itab lines lin.
do lin times.
read line sy-index field value itab-chk into chk.
if chk = 'X'.
counter = counter + 1.
endif.
if counter gt 1.
clear counter.
message 'Pls check only one check box' type 'I'.
leave program.
endif.
enddo.
please change the code as you need it will by default show a detail button(magnifying glass) in application tool bar just click that after clicking in two or thrre check boxes. But here you have to set your own pf-status(like zspd just uncomment that and dbl click to set your pf status) and must press some fn key for getting the desired output.
regards
shiba dutta
05-29-2007 5:25 AM
Hi Shiba,
I applied the following code after modifying the one given by you:
tables mara.
data : begin of itab occurs 0,
chk,
matnr like mara-matnr,
end of itab.
data : counter type i,
lin type i,
chk.
start-of-selection.
select matnr into corresponding fields of table itab from mara up to 20
rows.
<b>set pf-status 'INITIAL1'.</b>
loop at itab.
write : / itab-chk as checkbox, itab-matnr.
hide itab.
endloop.
<b>AT USER-COMMAND.
CASE SY-UCOMM.
WHEN 'UPDT'.
ITAB-chk = ' '.
PERFORM UPDATE.
ENDCASE.</b>
at line-selection.
clear counter.
<b>FORM UPDATE.</b>
describe table itab lines lin.
do lin times.
read line sy-index field value itab-chk into chk.
if chk = 'X'.
counter = counter + 1.
endif.
if counter gt 1.
clear counter.
message e101." 'Pls check only one check box' type 'I'.
leave program.
endif.
enddo.
<b>ENDFORM. </b> " UPDATE
The bold parts are the one modified by me.
i have used the itb-chk = ' '. command to initialize the value of checkboxes after the 1st round of selection & execution has been made. So, every time i begin a new selection, the previous ones would be initialized. Still the problem persists that the chkbox values aer not getting initialized i.e. once i select multiple chkboxes & after that i select only a single checkbox in the next cycle, it still gives error. Can u help me out with this situation...
Thanx in advance,
Mohit.
05-29-2007 5:44 AM
Hi Mohit
make the below changes,
if counter gt 1.
clear counter.
<b><i>clear itab.
refresh itab,</i></b>
message e101." 'Pls check only one check box' type 'I'.
leave program.
endif.
Reward points if useful.
Regards,
Atish
05-29-2007 5:45 AM
that is because you are not clearing the counter
FORM UPDATE.
clear counter.
describe table itab lines lin.
do lin times.
read line sy-index field value itab-chk into chk.
if chk = 'X'.
counter = counter + 1.
endif.
if counter gt 1.
clear counter.
message e101." 'Pls check only one check box' type 'I'.
leave program.
endif.
enddo.
ENDFORM. " UPDATE
and no need of ITAB-chk = ' '. just try that and let us know whether your problem is solved or not.
regards
shiba dutta
05-29-2007 5:47 AM
05-29-2007 5:52 AM
Hi,
I got a fair amount of idea of wat exactly i hv 2 do after understanding ur code. Thanx a lot buddy...
05-29-2007 6:10 AM
Hi Shiba,
I just made one more change 2 this code. Along with clearing the counter, i also clear "chk ". Now its working fine.
Thanx a lot,
Mohit.