calcsums

charles.rooscharles.roos Member Posts: 60
Hi, can you confirm that i understand correctly following:

1. Table1 definition:
field1
field2
field3
field4
key: (field2, field3) sumindexfield: field4

2. Code to calculate field4 total sum:
setcurrentKey( field2, field3 )
setfilter( field1, value1)
setfilter( field2, value2)
calcsums( field4 )
message( Table1.field4 )

Does this code outputs correct Table1.field4 total sum?
The key of the sumindex field didn't get filters on field3, and "field1" which is outside of the key got also a filter. Does it return correct sum for me?

Comments

  • JedrzejTJedrzejT Member Posts: 267
    Hi

    Nav return good sum, only in case when Field1 is in PrimaryKey of that table, in other case Nav give You error that You use wrong key for calcsum.

    Regards
  • krzychub83krzychub83 Member Posts: 120
    Hi charles.roos

    Yes it does. I made an simple example to check it, when I saw JedrzejT answer:
    OBJECT Table 59999 test3
    {
      OBJECT-PROPERTIES
      {
        Date=08-06-12;
        Time=16:03:21;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
      }
      FIELDS
      {
        { 1   ;   ;No1                 ;Integer        }
        { 2   ;   ;No2                 ;Integer        }
        { 3   ;   ;No3                 ;Integer        }
        { 4   ;   ;Value               ;Decimal        }
      }
      KEYS
      {
        {    ;No1                                      }
        {    ;No2,No3                                 ;SumIndexFields=Value }
      }
      CODE
      {
    
        BEGIN
        END.
      }
    }
    
    OBJECT Form 59999 TEST
    {
      OBJECT-PROPERTIES
      {
        Date=08-06-12;
        Time=16:05:11;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        Width=9790;
        Height=7480;
        TableBoxID=1000000000;
        SourceTable=Table59999;
      }
      CONTROLS
      {
        { 1000000000;TableBox;220 ;220  ;9350 ;5500 ;HorzGlue=Both;
                                                     VertGlue=Both }
        { 1000000001;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                     InColumn=Yes;
                                                     SourceExpr=No1 }
        { 1000000002;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000001;
                                                     InColumnHeading=Yes }
        { 1000000003;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                     InColumn=Yes;
                                                     SourceExpr=No2 }
        { 1000000004;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000003;
                                                     InColumnHeading=Yes }
        { 1000000005;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                     InColumn=Yes;
                                                     SourceExpr=No3 }
        { 1000000006;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000005;
                                                     InColumnHeading=Yes }
        { 1000000007;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                     InColumn=Yes;
                                                     SourceExpr=Value }
        { 1000000008;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000007;
                                                     InColumnHeading=Yes }
        { 1000000009;CommandButton;2530;6710;2200;550;
                                                     HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     Default=Yes;
                                                     PushAction=LookupOK;
                                                     InvalidActionAppearance=Hide }
        { 1000000010;CommandButton;4950;6710;2200;550;
                                                     HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     Cancel=Yes;
                                                     PushAction=LookupCancel;
                                                     InvalidActionAppearance=Hide }
        { 1000000011;CommandButton;7370;6710;2200;550;
                                                     HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     PushAction=FormHelp }
        { 1000000012;CommandButton;7370;5940;2200;550;
                                                     CaptionML=ENU=Calculate;
                                                     OnPush=BEGIN
                                                              Rec.SETCURRENTKEY(No2, No3);
                                                              Rec.SETRANGE(No1,1,10);
                                                              Rec.SETRANGE(No2,1,10);
                                                              Rec.CALCSUMS(Value);
                                                              MESSAGE('%1', Rec.Value );
                                                            END;
                                                             }
      }
      CODE
      {
    
        BEGIN
        END.
      }
    }
    

    Inserted data:
    No1 No2 No3 Value
    1 1 1 100,00
    2 12 10 100,00
    3 3 3 100,00
    100 1 1 1 000,00

    Returned Value:
    200

    Have a good day...
Sign In or Register to comment.