Van Vugt's dynamiXs

All around NAV dev and test

Some Compounds Statements

Have a look at these code samples and tell me where a compound statement, i.e. BEGIN-END, should be constructed to get the code work right.

Just dare without going into NAV and verify. Geeked

Sample 1

1. SalesCommentLine.SETRANGE("Document Type",SalesQHeader."Document Type");
2. SalesCommentLine.SETRANGE("No.",SalesQHeader."No.");
3. WHILE SalesCommentLine.FIND('-') DO
4.   SalesCommentLine.DELETE;
5.   SalesCommentLine."Document Type" := SalesOrderHeader."Document Type";
6.   SalesCommentLine."No." := SalesOrderHeader."No.";
7.   SalesCommentLine.INSERT;

Sample 2

1. IF AccountingPer2.FIND('>') THEN
2.   FiscalYearEndDate := CALCDATE('<-1D>',AccountingPer2."Starting Date");
3.   AccountingPer3 := AccountingPer2;
4.   AccountingPer2.SETRANGE("New Fiscal Year");
5.   AccountingPer2.FIND('<')
6. ELSE
7.   ERROR(Text001);

Sample 3

1.  CASE "Action Taken" OF
2.    "Action Taken"::Won:
3.      IF Opp.GET("Opportunity No.") THEN
4.        SalesQuoteEnable := Opp."Sales Document No." <> '';
5.    "Action Taken"::Lost:
6.      CalcdCurrentValueLCYEnable := FALSE;
7.      SalesQuoteEnable := FALSE;
8.  END;

Sample 4

1.  CASE LOWERCASE("XBRL Item Type") OF
2.   'stringitemtype','string':
3.     "Source Type" := "Source Type"::Description;
4.   'monetaryitemtype':
5.     "Source Type" := "Source Type"::"General Ledger";
6.   'decimalitemtype':
7.     "Source Type" := "Source Type"::Constant;
8.  'sharesitemtype' :
9.     "Source Type" := "Source Type"::Constant;
10.  'uriitemtype':
11.     "Source Type" := "Source Type"::Description;
12.   'tupletype':
13.     "Source Type" := "Source Type"::Tuple;
14.   ELSE
15.     "Source Type" := "Source Type"::"Not Applicable";
16.     IF "XBRL Item Type" <> '' THEN
17.       Description := STRSUBSTNO(Text007,"XBRL Item Type");
18. END;

Sample 5

1.  WITH ResJnlLine2 DO
2.    IF "Resource No." <> '' THEN
3.      IF ResJnlTemplate.Recurring THEN BEGIN
4.        TESTFIELD("Recurring Method");
5.        TESTFIELD("Recurring Frequency");
6.        IF "Recurring Method" = "Recurring Method"::Variable THEN
7.          TESTFIELD(Quantity);
8.      END ELSE BEGIN
9.        TESTFIELD("Recurring Method",0);
10.       TESTFIELD("Recurring Frequency","0DF");
11.     END;

For reference I have added numbers to each code line. Please use it as follows: if in case in Sample 2 the BEGIN should be added to line 2 and it's balancing END to line 4, you could suffice with writing Sample 2 - line2/line4.

  • Writing without looking into NAV Dev Env :)

    Sample 1 (will compile):

    ...

    3. ... BEGIN

    ...

    8. END;

    Sample 2 (will not compile):

    1. ... BEGIN

    ...

    6. END ...

    Sample 3 (not sure about compiling):

    ...

    5. ... BEGIN

    ...

    7.5. END;

    ...

    Sample 4 (not sure about compiling):

    ...

    15.5. END;

    16. ... BEGIN

    ...

    Sample 5 (will compile):

    no changes needed?

  • Hi,

    let's try:

    Sample 1: 3a. BEGIN, 8. END;

    Sample 2: 1a. BEGIN, 5. ;, 5a. END;

    Sample 3: 5a. BEGIN, 7a. END;

    Sample 4: no change - indentation on 16 and 17 could be better

    Sample 5: no change

    slightly different than AntidotE's...

    with best regards

    Jens

  • Hi Luc, this blog is the best argument to always and ever using BEGIN/END. Thank you very much!

    Bodo

  • Hi Bodo,

    Have to admit you're right, even though I am not found of "ever using BEGIN/END". ;-)

    I guess you are not going to try to answer? 8-)

    b rg

    Luc