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: 

Selecting a single checkbox

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

14 REPLIES 14

Former Member
0 Kudos

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

gopi_narendra
Active Contributor
0 Kudos

You can use radiobuttons for such requirement instead.

Regards

Gopi

Former Member
0 Kudos

Hi Mohit Goel,

Instead of using the check box u can use Radio Button for ur Requirement i hope ....

Thanks & Regards

Bhaskar Rao.M.

0 Kudos

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.

0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

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.

0 Kudos

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

0 Kudos

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

0 Kudos

Hi

Have you tried the code that i have given..?????

0 Kudos

Hi,

I got a fair amount of idea of wat exactly i hv 2 do after understanding ur code. Thanx a lot buddy...

0 Kudos

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.