Today, we will how we can use the CASE .. ENDCASE statment to check the values of the Radiobutton.
CASE.. ENDCASE has better performance compared to the IF.. ENDIF statement.
So, here is the Code which will show how to use th CASE .. ENDCASE to access the values of the Radiobuttons.
Code Snippet
*&---------------------------------------------------------------------*
*& This code snippet will show how to use the CASE .. ENDCASE statement
*& to check which radiobutton has been selected
*&---------------------------------------------------------------------*
* Selection screen with 3 radiobuttons.
SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME TITLE aaa.
PARAMETERS: p_r1 RADIOBUTTON GROUP rd1,
p_r2 RADIOBUTTON GROUP rd1,
p_r3 RADIOBUTTON GROUP rd1.
SELECTION-SCREEN: END OF BLOCK blk1.
*
INITIALIZATION.
aaa = 'Select your option'.
*
START-OF-SELECTION.
* Case statements to check which radiobutton was selected.
CASE 'X'.
WHEN p_r1.
WRITE: / 'P_R1 has been selected..!'.
WHEN p_r2.
WRITE: / 'P_R2 has been selected..!'.
WHEN p_r3.
WRITE: / 'P_R3 has been selected..!'.
ENDCASE.
thanks for ur post. but why u have used ‘X’ in CASE ‘X’ statement, what does it imply.
Hi Charu,
CASE has always a good performance over the IF statement. This type of CASE is very helpful when you have to handle more radiobuttons.
Regards,
Naimesh Patel
yeah thanks for the reply. but can we use any other variable in place of X. Like for example the case here is to check the option in the radio button and the output should be displayed corresponding to the option that we select. but when i give as CASE ‘rd1’ i dont get the output..so this is my question. Is ‘X’ a default value in CASE statement while using optional buttons??
We are using ‘X’ because when we select any radiobutton, the radiobutton variable will be set to ‘X’. If you want to use the CASE RD1, than you have to write so many cases.
Like:
PARAMETERS: p_r1 RADIOBUTTON GROUP rd1, p_r2 RADIOBUTTON GROUP rd1, p_r3 RADIOBUTTON GROUP rd1.
case p_r1.
when ‘X’.
write: ‘R1 Selected’.
endcase.
case p_r2.
when ‘X’.
write: ‘R2 Selected’.
endcase.
case p_r3.
when ‘X’.
write: ‘R3 Selected’.
endcase.
Regards,
Naimesh Patel
o ok.. thank you for the explanation…
Hi Naimesh,
i was wondering why you claim that “CASE.. ENDCASE has better performance compared to the IF.. ENDIF statement.” is based on. I wrote a little test program and couldn’t verify this claim. I only saw minor improvements of CASE over IF. In fact I would have been very surprised if there had been an significant difference….
Nevertheless I think that the CASE statement is much more readable an should therefore be preferred (independent of performance).
Christian
Hello Christian,
I only saw minor improvements of CASE over IF
This minor improvement also counts 🙂
It would be very performance effective when you have nested IF.. ENDIF. Because we are getting rid of one of the IF.. ENDIF by using the CASE.. ENDCASE.
Regards,
Naimesh Patel