Showing posts with label C/AL Functions. Show all posts
Showing posts with label C/AL Functions. Show all posts
Monday, July 27, 2009
Zoom Funtion In Navision
You can use the Zoom feature in the Classic client to help you troubleshoot and debug issues. For example, if you create a new form and need to troubleshoot the data that is displayed on the form, then you can use the Zoom feature to view all fields for the current record.
Labels:
C/AL Functions,
Zoom In Navision
WITH Statements
Following is the Syntax For WITH statment.
WITH [Record] DO [Statement]
When you work with records, addressing is created as record name, dot (period),
and field name: [Record].[Field]
you work continuously with the same record, you can use WITH statements. When you use a WITH statement, you only have to specify the record name once.
Within the scope of [Statement], fields in [Record] can be addressed without having to specify the record name.
You can nest several WITH statements. In case of identical names, the inner WITH overrules the outer WITH-statements.
and field name: [Record].[Field]
you work continuously with the same record, you can use WITH statements. When you use a WITH statement, you only have to specify the record name once.
Within the scope of [Statement], fields in [Record] can be addressed without having to specify the record name.
You can nest several WITH statements. In case of identical names, the inner WITH overrules the outer WITH-statements.
For Eg:
Consider a variable-'CustRec', Data Type -'Record', Subtype-'Customer'.
CustRec."No." := '10000';
CustRec.Name := 'Creative Solutions';
CustRec."Phone No." := '555-444-333';
CustRec.Address := '1352 Avenue';
CustRec.City := 'NewYork City';
MESSAGE('A variable has been created for this customer.');
The following example shows another way to create a record variable that you can commit later.
WITH CustomerRec DO
BEGIN
"No." := '10000';
Name := 'Creative Solutions';
"Phone No." := '555-444-333';
Address := '1352 Avenue';
City := 'NewYork City';
MESSAGE('A variable has been created for this customer.');
END;
Labels:
C/AL Functions,
With Function
Saturday, July 25, 2009
FOR,WHILE,REPEAT
C/AL Repetitive Statements
A repetitive statement is also known as a loop. The Different Loop statements are Given below.
1. FOR
2. WHILE
3. REPEAT
FOR
Repeats the inner statement until a counter variable equals the maximum or minimum value specified.
A repetitive statement is also known as a loop. The Different Loop statements are Given below.
1. FOR
2. WHILE
3. REPEAT
FOR
Repeats the inner statement until a counter variable equals the maximum or minimum value specified.
The Two Control Structures In FOR Statement are FOR TO and FOR DOWNTO.
The Syntax For The above control structures are given below.
FOR [Control Variable] := [Start Number] TO [End Number] DO
[Statement]
The data type of [Control Variable], [Start Number], and [End Number] must be Boolean, number, time, or date.
Use FOR statements when you want to execute code a specific number of times.
Use a control variable to control the number of times the code is executed. The control variable can be increased or decreased by one, depending on whether TO or DOWNTO is used.
When using a FOR TO loop, the [Statement] will not be executed if the [Start Number] is greater than the end value. Likewise, when using a FOR DOWNTO loop, the [Statement] will not be executed if the [Start Number] is less than the end value.
For Eg:
1. Consider a variable 'I' for Loop.
FOR I=1 To 5 DO
Statement 1;
2. The following example shows how to nest FOR statements.
FOR I := 1 TO 5 DO
FOR J := 1 TO 7 DO
A[I,J] := 23;
The Syntax For The above control structures are given below.
FOR [Control Variable] := [Start Number] TO [End Number] DO
[Statement]
The data type of [Control Variable], [Start Number], and [End Number] must be Boolean, number, time, or date.
Use FOR statements when you want to execute code a specific number of times.
Use a control variable to control the number of times the code is executed. The control variable can be increased or decreased by one, depending on whether TO or DOWNTO is used.
When using a FOR TO loop, the [Statement] will not be executed if the [Start Number] is greater than the end value. Likewise, when using a FOR DOWNTO loop, the [Statement] will not be executed if the [Start Number] is less than the end value.
For Eg:
1. Consider a variable 'I' for Loop.
FOR I=1 To 5 DO
Statement 1;
2. The following example shows how to nest FOR statements.
FOR I := 1 TO 5 DO
FOR J := 1 TO 7 DO
A[I,J] := 23;
Thursday, July 23, 2009
IF THEN ELSE in Navision
IF THEN [ELSE]
A conditional statement is one type of control structure in C/AL.
Using Conditional Statements
By using a conditional statement, you can specify a condition and one or more commands that should be executed, according to whether the condition is evaluated as TRUE or FALSE. There are two types of conditional statements in C/AL:
1. IF THEN [ELSE], where there are two choices
2. CASE, where there are more than two choices.
By using a conditional statement, you can specify a condition and one or more commands that should be executed, according to whether the condition is evaluated as TRUE or FALSE. There are two types of conditional statements in C/AL:
1. IF THEN [ELSE], where there are two choices
2. CASE, where there are more than two choices.
IF THEN ELSE Statements
IF THEN ELSE statements have the following syntax.
IF THEN ELSE statements have the following syntax.
IF (Condition) THEN (Statement1)
[
ELSE
(Statement2)
]
This means that if (Condition) is true, then (Statement1) is executed. If (Condition) is false, then (Statement2) is executed.
The square brackets around ELSEmean that this part of the statement is optional. The ELSE statement is used when different actions are executed, depending on the evaluation of (Condition).
You can build even more complex control structures by nesting IF THEN ELSE statements. The following example is a typical IF THEN ELSE statement.
This means that if (Condition) is true, then (Statement1) is executed. If (Condition) is false, then (Statement2) is executed.
The square brackets around ELSE
You can build even more complex control structures by nesting IF THEN ELSE statements. The following example is a typical IF THEN ELSE statement.
IF (Condition1) THEN
IF (Condition2) THEN
Statement1;
ELSE
Statement2
Note: A semicolon preceding an ELSE is not allowed.
If 'Condition1' is false, then nothing is executed. If 'Condition1' and 'Condition2' are both true, then 'Statement1' is executed. If 'Condition1' is true and 'Condition2' is false, then 'Statement2' is executed.
If 'Condition1' is false, then nothing is executed. If 'Condition1' and 'Condition2' are both true, then 'Statement1' is executed. If 'Condition1' is true and 'Condition2' is false, then 'Statement2' is executed.
Reading several nested IF THEN ELSE statements can be quite confusing but a general rule is that an ELSE belongs to the last IF that lacks an ELSE.
Example 1
The following example shows an IF statement without the optional ELSE part.
The following example shows an IF statement without the optional ELSE part.
IF Amount (<) 1000 THEN Total := Total + Amount;
Example 2
The following example shows an IF statement with the optional ELSE part.
The following example shows an IF statement with the optional ELSE part.
(1)...
(2) IF Amount (<1000) align="justify">(3) THEN BEGIN(4) IF I > J THEN Max := I
(5) ELSE Max := J;
(6) Amount := Amount * Max;
(6) END
(7) ELSE
(8)...
A common error is to put an extraneous semicolon at the end of a line before an ELSE (line 4). As mentioned earlier, this is not valid according to the syntax of C/AL. The semicolon is used as a statement separator. (The end of line 4 is inside the inner IF statement.)
A common error is to put an extraneous semicolon at the end of a line before an ELSE (line 4). As mentioned earlier, this is not valid according to the syntax of C/AL. The semicolon is used as a statement separator. (The end of line 4 is inside the inner IF statement.)
CASE Statements
CASE statements have the following syntax.
CASE statements have the following syntax.
CASE (Expression) OF
(Value set 1) : (Statement 1);
(Value set 2) :(Statement 2);......
(Value set n) : (Statement n);
[ ELSE (Statement n+1) ]
CASE statements are also called multiple option statements and are typically used when you must choose between more than two different actions.
The function of the CASE statement is as follows:
1. The 'Expression' is evaluated, and the first matching value set executes the associated statement, if there is one.
2. If none of the value sets matches the value of the expression, and the optional ELSE part has been omitted, no action is taken. If the optional ELSE part is used, then the associated statement is executed.
The data type of the value sets must be the same as the data type of 'Expression' or at least be convertible to the same data type.
1. The 'Expression' is evaluated, and the first matching value set executes the associated statement, if there is one.
2. If none of the value sets matches the value of the expression, and the optional ELSE part has been omitted, no action is taken. If the optional ELSE part is used, then the associated statement is executed.
The data type of the value sets must be the same as the data type of 'Expression' or at least be convertible to the same data type.
For Eg:
The following C/AL code prints various messages depending on the value of Number. If the value of Number does not match any of the entries in the CASE structure, the ELSE entry is used as the default.
CASE Number OF
1,2,9: MESSAGE('1, 2, or 9.');
10..100: MESSAGE('In the range from 10 to 100.');
ELSE MESSAGE('Neither 1, 2, 9, nor in the range from 10 to 100.');
END
Labels:
C/AL Functions,
CASE,
IF THEN ELSE
BEGIN END Statements
A compound statement is one type of control structure in C/AL.
Using Compound Statements, In some cases, the C/AL syntax only allows you to use a single statement.
If however you have to execute more than one simple statement, the statements can be written as a compound statement by enclosing the statements between the keywords BEGIN and END.
Using Compound Statements, In some cases, the C/AL syntax only allows you to use a single statement.
If however you have to execute more than one simple statement, the statements can be written as a compound statement by enclosing the statements between the keywords BEGIN and END.
BEGIN
Statement 1;
Statement 2;
.. ;
END
END
The individual statements are separated by a semicolon. In C/AL a semicolon is used to separate statements, and not, as in other programming languages, as a terminator symbol for a statement. Nevertheless, an extra semicolon before an END does not cause an error because it is interpreted by the compiler as an empty statement.
Blocks
The BEGIN-END structure is also called a block. Blocks can be very useful in connection with the other control structures in C/AL
Labels:
BEGIN END Statements,
C/AL Functions
Saturday, July 18, 2009
TESTFIELD & VALIDATE Functions
TESTFIELD Function
TESTFIELD tests whether a field contains a specific value. It has the following syntax.
Record.TESTFIELD(Field, [Value])
If the test fails, that is, if the field does not contain the specified value, an error message is displayed and a runtime error is triggered. This means that any changes that were made to the record are discarded. If the value that you test against is an empty string, the field must have a value other than blank or 0 (zero).
One of the main feature of this function is that, if you want to check any field where value is their or not, You can Use this function, So that without giving any data to that particular field, System won't allow the user to Post the document. For this you can simply write
TestField(Fieldname);
VALIDATE Function
VALIDATE calls the OnValidate trigger of a field. It has the following syntax.
Record.VALIDATE(Field [, NewValue])
Thursday, July 16, 2009
GETRANGEMIN, GETRANGEMAX Functions
GETRANGEMIN Function
GETRANGEMIN retrieves the minimum value of the filter range that is currently applied to a field.
GETRANGEMIN has the following syntax.
Record.GETRANGEMIN(Field);
A runtime error occurs if the filter that is currently applied is not a range. For example, you can set a filter as follows.
Customer.SETFILTER("No.",'100002000030000');
With this filter, the following code fails because the filter is not a range.
GETRANGEMAX has the following syntax.
Value := Record.GETRANGEMAX(Field)
GETRANGEMIN retrieves the minimum value of the filter range that is currently applied to a field.
GETRANGEMIN has the following syntax.
Record.GETRANGEMIN(Field);
A runtime error occurs if the filter that is currently applied is not a range. For example, you can set a filter as follows.
Customer.SETFILTER("No.",'100002000030000');
With this filter, the following code fails because the filter is not a range.
BottomValue := Customer.GETRANGEMIN("No.");
GETRANGEMAX Function
GETRANGEMAX has the following syntax.
Value := Record.GETRANGEMAX(Field)
Labels:
C/AL Functions,
GETRANGEMAX,
GETRANGEMIN
Wednesday, July 15, 2009
LOCKTABLE Function
Ordinarily, when you are developing applications in C/SIDE, you do not need to take into consideration transactions and table locking. There are, however, some situations in which you must lock a table explicitly. To do this, use the LOCKTABLE function.
For example, in the beginning of a function, you inspect data in a table and then use this data to perform various checks and calculations. Finally, you want to insert a record based on the result of these calculations. To ensure that your calculations make sense, you must be certain that the values you retrieved at the beginning of the transaction are consistent with the data that is in the table now. You cannot allow other users to update the table while your function is performing its calculations.
LOCKTABLE Function
You can use the LOCKTABLE function to lock the table at the start of your function.
LOCKTABLE has the following syntax.
Record.LOCKTABLE([Wait] [, VersionCheck])
For example, in the beginning of a function, you inspect data in a table and then use this data to perform various checks and calculations. Finally, you want to insert a record based on the result of these calculations. To ensure that your calculations make sense, you must be certain that the values you retrieved at the beginning of the transaction are consistent with the data that is in the table now. You cannot allow other users to update the table while your function is performing its calculations.
LOCKTABLE Function
You can use the LOCKTABLE function to lock the table at the start of your function.
LOCKTABLE has the following syntax.
Record.LOCKTABLE([Wait] [, VersionCheck])
Labels:
C/AL Functions,
LockTable Function
Essential C/AL Functions
Although there are more than 100 functions in C/AL, there are several functions that you will use more often than the others.
1. GET, FIND, and NEXT Functions
2. SETCURRENTKEY, SETRANGE, SETFILTER, GETRANGEMIN, and GETRANGEMAX Functions
3. INSERT, MODIFY, MODIFYALL, DELETE and DELETEALL Functions
4. LOCKTABLE Function
5. CALCFIELDS, CALCSUMS,FIELDERROR, FIELDNAME, INIT, TESTFIELD, and VALIDATE Functions
6. Progress Windows, MESSAGE, ERROR and CONFIRM Functions
7. STRMENU Function
Subscribe to:
Posts (Atom)