All around NAV dev and test
So where should compound statement be inserted in the samples I posted this week to get the code work right? Have a look below.
... code can work technically right when it compiles and doesn't throw any run-time error, which is a minimum of any code IMHO. For sure it's not the full monty as it also should work right from a functional perspective. Of course the code samples are only snippets without the broader picture, but it wasn't that difficult to the at least have deducted some context. As you might have guessed the snippets hadn't been made up and were taken from standard NAV 2013 from which I removed the BEGIN's and END's. And ... for lay-out purposes I renamed some variables.
Technically this snippet can do without. However, for functional purposes we do need BEGIN-END.
Hooray for both respondents!
Just a nitty gritty comment: jglathe's suggestion does not (fully) comply to the C/AL coding standards: When BEGIN follows THEN, ELSE, or DO, it should be on the same line and preceded by one space character.
To get this code compiled BEGIN-END is mandatory as it will throw the well known compile error, because of an incorrect (or incomplete) IF-THEN-ELSE construction:
And for the same reason as above jglathe's suggestion does not (fully) comply to the C/AL coding standards.
In codeunit 6 there is purposeless empty line between line 2 and 3.
To get this code compiled BEGIN-END is mandatory as it will throw a compile error, because of an seemingly incorrect option SalesQuoteEnable := FALSE:
However, now AntidotE's suggestion does not (fully) comply to the C/AL coding standards for CASE Statament: If there is a BEGIN, then it should be put on a separate line unless it follows ELSE.
Both technically and functionally this snippet can do without! But C/AL coding standards prescribe the use of BEGIN-END as per below.
Hooray for jglathe!
For clarity purpose I had removed the last case option as I wanted to have focus on the ELSE part.
This snippet is taken form the local function CheckRecurringLine. Actually this is all the code this function is holding so both technically and functionally no need for BEGIN-END.
However standard NAV 2013 holds BEGIN-END as per the below, which, IMHO, is not in accordance with C/AL coding standards as it is redundant (see also Redundant BEGIN ... END).
whoops, had a look into the NAV source code. Its indeed the other way round... Text007 is only for unexpected types. :)
with best regards
regarding sample 4: when coded with begin - end as shown here, it will do something else as was intended. It will only fill the description with "Not Applicable" when it's none of the types in the case statements. Without, it will always fill the description with the assigned source type. I think that's the intention, only the indentation is off.