Hi all,
Sometimes I see a line of code that seems incomplete but it's not, and I am just wondering what it means and why it's written this way. Below is an example:
IF ShipmentMethod.GET("Sales Shipment Header"."Shipment Method Code") THEN BEGIN
END;
My question is specifically related to the THEN BEGIN ?? END part.
Thanks in advance,
MisConsultng
0
Answers
Is it answer to your question? or please provide more details.
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
BEGIN and END allow to execute Multiple Statement if the IF statement Condition Met, without Begin and End only First statement executes.
Hope it answers your query.
Thanks & Regards,
Saurav Dhyani
Do you Know this About NAV?
Connect - Twitter | Facebook | Google + | YouTube
Follow - Blog | Facebook Page | Google + Page
The BEGIN END; part, without any statements in between BEGIN and END does nothing at all. BEGIN ... END is called a compound statement.
C/AL usually allows for just one statement for it's control statements like In any place where there is an ... above, exactly one statement may go. If you need to do more, you can use the compound statement, which allows for a list of statements between BEGIN and END, separated by semicolons.
Most programming languages use the concept of code blocks. C/AL does not, thus the need for a compound statement.
In your example, the IF statement around GET as a condition may well be used for it's side effect on GET. If you use GET as a statement it causes an error, if it fails; if GET is used as an expression, it instead returns FALSE.
So, your code sample tries to get the record, but does not handle the case where it can or can't be found (assuming there is indeed no code between BEGIN and END). It is unusual to use BEGIN END; in this case though. Usually just the semicolon is written (which is the empty statement, and makes the subsequent statement separator redundant):
Programming around error message is a good thing of course, but then you need to also program what the system should do if the record does not exist, like set default values.
RIS Plus, LLC
Thanks again guys.