2022 Jun 14 10:34 AM
I have 2 check boxes and if it is both selected at the same time, it doesn't get executed
SELECTION-SCREEN BEGIN OF BLOCK chk1
WITH FRAME TITLE text-008.
PARAMETERS: chk_morning AS CHECKBOX DEFAULT 'X',
chk_evening AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK chk1.
IF chk_morning = abap_true.
WRITE / 'Morning'.
ELSEIF chk_evening = abap_true.
WRITE / 'Evening'.
ELSE.
WRITE / 'Morning and Evening'.
ENDIF.
When both the checkbox morning and evening is selected, the write statement 'Morning and Evening' is not being displayed. Any help is appreciated. Thank you
2022 Jun 14 10:42 AM
2022 Jun 14 11:00 AM
2022 Jun 14 11:25 AM
Hi,
SELECTION-SCREEN BEGIN OF BLOCK chk1
WITH FRAME TITLE text-008.
PARAMETERS: chk_morning AS CHECKBOX DEFAULT 'X',
chk_evening AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK chk1.
IF chk_morning = abap_true.
WRITE / 'Morning'.
ELSEIF chk_evening = abap_true.
WRITE / 'Evening'.
ELSEIF chk_morning = abap_true AND chk_evening = abap_true.
WRITE / 'Morning and Evening'.
ENDIF.
2022 Jun 14 3:13 PM
You have added a required logical expression, but you have not rearranged the order of these expressions, so no sorry.
2022 Jun 14 3:19 PM
Hi raymond.giuseppi order of written statement will change the result ?. All three conditions needs to be done. We dont know which condition has the priority so in that case how can you say that last conditions which i have added should be first or should not be the last. Or you want to say something else.
please clarify.
2022 Jun 14 3:24 PM
Hi raymond.giuseppi I am totally disagree with your statement
2022 Jun 14 3:31 PM
Hi raymond.giuseppi
If you have right answer, and as per your opinion my answer is wrong then you can put your answer so will get know it.
2022 Jun 14 5:15 PM
In online or F1 documentation you can find 'The logical expressions, beginning with the IF statement, are checked from top to bottom and the statement block after the first real logical expression is executed. If none of the logical expressions are true, the statement block after the ELSE statement is executed.' so 'order of written statement will change the result' - so start from more restrictive criteria (here both boxes are checked) to less, the ELSE will be the last one
2022 Jun 14 5:21 PM
2022 Jun 15 8:17 AM
As an exercise, run it in the debugger and see how it is executed.
2022 Jun 15 12:47 PM
2022 Jun 14 11:27 AM
Hi,
You can try this.
IF chk_mor = ABAP_TRUE and chk_eve is initial.
WRITE / 'Morning'.
ELSEIF chk_eve = ABAP_TRUE and chk_mor is initial.
WRITE / 'Evening'.
ELSE.
WRITE / 'Morning and Evening'.
ENDIF.
2022 Jun 14 3:13 PM
2022 Jun 14 3:16 PM
If you're going to use abap_true (which is a good thing), don't use IS INITIAL instead of = abap_false.
2022 Jun 15 12:21 PM
matthew.billingham
Thanks you sir for your suggestion.
Just for my knowledge I want to know why
IS INITIAL not preferable? (so in future i can improve my skill)
2022 Jun 15 1:20 PM
shital1111
A checkbox is like boolean true/false. Used more by developers worldwide. That's why.Technically speaking, it's the same (like also = ' ' or = space etc.)2022 Jun 15 3:38 PM
shital1111 It's consistency and readability. Why use two different approaches instead of a single approach? With IS INITIAL you are relying on the programmer who reads your code in knowing that IS INITIAL means "false". With abap_false it's right there in the words!
I suggest you work your way through this https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md or getting the book mentioned here https://blogs.sap.com/2022/06/14/simplified-learning-of-clean-abap-and-clean-ui5/
2022 Jun 16 6:15 AM
2022 Jun 14 11:42 AM
Hello walkerist
Look at your IF...ELSEIF...ELSE...ENDIF statement carefully and see how it's evaluated and executed if both checkboxes are set.
If none of the logical expressions are true, the statement block after the ELSE statement is executed.
In your case the first logical expression is true, hence ELSE is not executed.
Best regards
Dominik Tylczynski
2022 Jun 14 11:44 AM
Hi,
Try this one.
IF chk_morn = abap_true AND chk_even = abap_true.
WRITE / 'Morning and Evening'.
ELSEIF chk_morn = abap_true.
WRITE / 'Morning'.
ELSEIF chk_even = abap_true.
WRITE / 'Evening'.
ELSE.
WRITE / 'nothing selected'.
ENDIF.
2022 Jun 14 3:52 PM
2022 Jun 15 7:18 AM
2022 Jun 14 11:44 AM
2022 Jun 14 12:02 PM
When you evaluate condition with IF-ELSEIF you always start with the more specific case and then proceed.
Do a google search for the FizzBuzz programming problem.
2022 Jun 14 3:11 PM
In a IF control structure, only the first valid statement block will be executed. So adapt your checks and their order.