06-15-2022 7:15 AM
Hello, I'm trying to display a MESSAGE 'Please enter a valid number' at the bottom of the screen when the Integer 2 field has a value of 0 and when the mathematical operators divide and modulo is selected.
I was able to display it but the selection screen is gone. Is it possible to have the message appear while the selection screen is being displayed?
*Parameter declaration - Display fields
PARAMETERS: p_no1 TYPE i DEFAULT 5,
p_no2 TYPE i DEFAULT 3,
rb_add RADIOBUTTON GROUP RD1,
rb_sub RADIOBUTTON GROUP RD1,
rb_mul RADIOBUTTON GROUP RD1,
rb_div RADIOBUTTON GROUP RD1 DEFAULT 'X',
rb_mod RADIOBUTTON GROUP RD1.
IF p_no2 = 0
AND rb_div = abap_true
OR rb_mod = abap_true.
MESSAGE e088.
ENDIF.
*Data Declaration
DATA(lv_sum) = ( p_no1 + p_no2 ).
DATA(lv_diff) = ( p_no1 - p_no2 ).
DATA(lv_prod) = ( p_no1 * p_no2 ).
DATA: lv_quo TYPE p DECIMALS 2,
lv_mod TYPE p DECIMALS 2.
lv_quo = ( p_no1 / p_no2 ).
lv_mod = ( p_no1 MOD p_no2 ).
*Output
IF rb_add = abap_true
WRITE: { lv_sum }
ELSEIF rb_sub = abap_true
WRITE: { lv_diff }
ELSEIF rb_prod = abap_true
WRITE: { lv_prod }
ELSEIF rb_quo = abap_true
WRITE: { lv_quo }
ELSEIF rb_mod = abap_true
WRITE: { lv_mod }
06-15-2022 10:02 AM
Hi walkerist
Please use try-catch as below: This will avoid dump.
try.
lv_quo = ( p_no1 / p_no2 ).
lv_mod = ( p_no1 MOD p_no2 ).
catch cx_sy_zerodivide.
* RAISE EXCEPTION TYPE cx_sy_zerodivide.
MESSAGE 'Trying to Divide by Zero.. Not allowed' TYPE 'S' DISPLAY LIKE 'S'.
ENDTRY.
06-15-2022 7:24 AM
if p_no2 = 0.
MESSAGE 'Please enter a valid number' type 'E'.
endif.
06-15-2022 7:32 AM
06-15-2022 7:44 AM
Or you could simply stop your report
START-OF-SELECTION.
IF p_no2 = 0
AND rb_div = abap_true
OR rb_mod = abap_true.
MESSAGE ID 'O47'
TYPE 'I'
NUMBER '088'.
STOP.
ENDIF.
*Data Declaration
DATA(lv_sum) = ( p_no1 + p_no2 ).
DATA(lv_diff) = ( p_no1 - p_no2 ).
DATA(lv_prod) = ( p_no1 * p_no2 ).
DATA: lv_quo TYPE p DECIMALS 2,
lv_mod TYPE p DECIMALS 2.
lv_quo = ( p_no1 / p_no2 ).
lv_mod = ( p_no1 MOD p_no2 ).
06-15-2022 8:26 AM
Hi,
Please try below code. In below code error message is display on same screen. I have added events. If you write the message on at selection screen event it works as expected.
*Parameter declaration - Display fields<br>PARAMETERS: p_no1 TYPE i DEFAULT 5,<br> p_no2 TYPE i DEFAULT 3,<br> rb_add RADIOBUTTON GROUP rd1,<br> rb_sub RADIOBUTTON GROUP rd1,<br> rb_mul RADIOBUTTON GROUP rd1,<br> rb_div RADIOBUTTON GROUP rd1 DEFAULT 'X',<br> rb_mod RADIOBUTTON GROUP rd1.
AT SELECTION-SCREEN.<br> IF p_no2 = 0<br> AND rb_div = abap_true<br> OR rb_mod = abap_true.<br> MESSAGE 'Invalid divisor Value' TYPE 'E'.<br> ENDIF.<br>START-OF-SELECTION.<br>*Data Declaration<br> DATA(lv_sum) = ( p_no1 + p_no2 ).<br> DATA(lv_diff) = ( p_no1 - p_no2 ).<br> DATA(lv_prod) = ( p_no1 * p_no2 ).<br> DATA: lv_quo TYPE p DECIMALS 2,<br> lv_mod TYPE p DECIMALS 2.<br> lv_quo = ( p_no1 / p_no2 ).<br> lv_mod = ( p_no1 MOD p_no2 ).<br>*Output<br> IF rb_add = abap_true.<br> WRITE: lv_sum.<br> ELSEIF rb_sub = abap_true.<br> WRITE:lv_diff.<br> ELSEIF rb_mul = abap_true.<br> WRITE:lv_prod.<br> ELSEIF rb_div = abap_true.<br> WRITE: lv_quo.<br> ELSEIF rb_mod = abap_true.<br> WRITE: lv_mod.<br> ENDIF.
06-15-2022 8:40 AM
Tried this but encountering dump when the second number is 0 and the option selected is addition, subtraction, multiplication.
06-15-2022 9:25 AM
Be careful to the format of your code, there are lots of invalid <BR> inside it.
06-15-2022 9:27 AM
Actually when i click on edit then this <br> gets added automatically.
06-15-2022 8:59 AM
Hi,
Below code is working i just change position of two statement. one is calculating division and one is for mod.
*Parameter declaration - Display fields
PARAMETERS: p_no1 TYPE i DEFAULT 5,
p_no2 TYPE i DEFAULT 3,
rb_add RADIOBUTTON GROUP rd1,
rb_sub RADIOBUTTON GROUP rd1,
rb_mul RADIOBUTTON GROUP rd1,
rb_div RADIOBUTTON GROUP rd1 DEFAULT 'X',
rb_mod RADIOBUTTON GROUP rd1.
AT SELECTION-SCREEN.
IF p_no2 = 0
AND rb_div = abap_true
OR rb_mod = abap_true.
MESSAGE 'Invalid divisor Value' TYPE 'E'.
ENDIF.
START-OF-SELECTION.
*Data Declaration
DATA(lv_sum) = ( p_no1 + p_no2 ).
DATA(lv_diff) = ( p_no1 - p_no2 ).
DATA(lv_prod) = ( p_no1 * p_no2 ).
DATA: lv_quo TYPE p DECIMALS 2,
lv_mod TYPE p DECIMALS 2.
*Output
IF rb_add = abap_true.
WRITE: lv_sum.
ELSEIF rb_sub = abap_true.
WRITE:lv_diff.
ELSEIF rb_mul = abap_true.
WRITE:lv_prod.
ELSEIF rb_div = abap_true.
lv_quo = ( p_no1 / p_no2 ).
WRITE: lv_quo.
ELSEIF rb_mod = abap_true.
lv_mod = ( p_no1 MOD p_no2 ).
WRITE: lv_mod.
ENDIF.
img1.png
06-15-2022 9:44 AM
I'm encountering dump error when using addition, subtraction, and multiplication.
06-15-2022 9:50 AM
Hi Wane,
Please share your code after changes. Now the code which i have shared did you try it. Because i have done changes and now i am not getting dump.
06-15-2022 9:28 AM
It's what happens when you send a message of type ERROR during START-OF-SELECTION event. Message processing is well documented in the ABAP documentation.
Better do your validations during the Process After Input (i.e. the AT SELECTION-SCREEN event), you can send error messages, as you can see in the ABAP documentation.
NB: any code without mention of event is implicitly executed during START-OF-SELECTION event. It's better to indicate explicitly START-OF-SELECTION (and this is required when you use ABAP Objects).
06-15-2022 10:02 AM
Hi walkerist
Please use try-catch as below: This will avoid dump.
try.
lv_quo = ( p_no1 / p_no2 ).
lv_mod = ( p_no1 MOD p_no2 ).
catch cx_sy_zerodivide.
* RAISE EXCEPTION TYPE cx_sy_zerodivide.
MESSAGE 'Trying to Divide by Zero.. Not allowed' TYPE 'S' DISPLAY LIKE 'S'.
ENDTRY.
06-15-2022 11:05 AM
You could define your parameters and select-options in a dummy block (no text, no frame)
SELECTION-SCREEN BEGIN OF BLOCK criteria.
PARAMETER x...
SELECT-OPTIONS y...
SELECTION-SCREEN END OF BLOCK criteria.
Then raise those messages in AT SELECTION-SCREEN on this block (like in a CHAIN/ENDCHAIN of classic PAI)
AT SELECTION-SCREEN ON BLOCK criteria.
IF ... MESSAGE ... ENDIF
So the fields defined in the block would be available for correction in case or error message.