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. [8-|]

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.

One Comment

  1. 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? 😎

    b rg

    Luc

Leave a Reply

Your email address will not be published. Required fields are marked *