Grouping in reports in OnPreDataItem - is it possible?

DinDin Member Posts: 6
edited 2006-02-06 in Navision Attain
Hi to all :D

I have got a question, is there any possibility of grouping information in the report, without using GroupTotalfields property of the item. The case is, i have to get the report, which runs on the table Item, but with two different groupings. As i understand i can get them sorted as i wish with SETCURRENTKEY, but what then - searched for anything that could group them in the process - but nothing :cry:

Does anyon know, whether there is any function capable of that?

If not, then i most probably redesign the thing to work on two different Item's so that it chooses one with the suitable grouping, but still, it would be nice to know, whether there is a possibility.

Would be very glad to here from anyone knowing anything about the matter O:)

Comments

  • krikikriki Member, Moderator Posts: 9,112
    I didn't exactly understand what you want to reach.
    But instead of using "GroupTotalfields", you can write your own coding to do the grouping.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • DinDin Member Posts: 6
    That's exactly the thing i would like to do - but don't know how. i am just a begginer, that's why the question. I know how can i sort, but have no idea how can i write the expression to group them. Do you know?? If you do i would be very glad \:D/ to hear.
  • DinDin Member Posts: 6
    Well in order to be more precise, here is the part, that has been done so far :
    grupperimine - option type

    CASE grupperimine OF
    grupperimine::PMAd:
    item.SETCURRENTKEY("PMA1","PMA2");
    HERE I NEED SOME CODE TO GROUP BY
    grupperimine::"Tootja ja hankija":
    item.SETCURRENTKEY("Vendor No.","Manufacturer Code","PMA1","PMA3","PMA2","Alkoholi %","Unit Volume")
    END;
    HERE I NEED SOME CODE TO GROUP BY

    Is there any function to tell the navi to group by the fields of the currentkey?? I couldnot find any so far :oops:
  • roshandilrukroshandilruk Member Posts: 51
    There's no any specific function as far as I know, u will have to do your own coding for that, I even have seen this thing in some reports, but unfortunately I cannot remember what exactly are those reports. Whenever I ll find it, I ll let you know 4 sure.

    Roshan
  • DinDin Member Posts: 6
    Many thanks, I ll be waiting pationately :P
  • krikikriki Member, Moderator Posts: 9,112
    If I understand correctly what you want to do:
    Start reading your records in a way that goes fast (correct SETCURRENTKEY and SETRANGE), and save the totals in a temptable (grouping by the fields of the SETCURRENTKEY or even grouping by other fields) . Then run your report on the temptable.
    //clean the temptables (property TempTable=Yes on the variable)
    tmpRecord1.RESET;
    tmpRecord1.DELETEALL(FALSE);
    tmpRecord2.RESET;
    tmpRecord2.DELETEALL(FALSE);
    tmpRecord3.RESET;
    tmpRecord3.DELETEALL(FALSE);
    
    //creating the temptable:
    recRecord.RESET;
    recRecord.SETCURRENTKEY(A,B,C);
    recRecord.SETRANGE(A,from,to);
    recRecord.SETRANGE(B,from,to);
    IF recRecord.FIND('-') THEN
      REPEAT
        // maintain a total per field X,Y,Z
        IF (tmpRecord3.X <> recRecord3.X) OR
            (tmpRecord3.Y <> recRecord3.Y) OR
            (tmpRecord3.Z <> recRecord3.Z) THEN BEGIN
          tmpRecord3.RESET;
          tmpRecord3.SETCURRENTKEY(X,Y,Z);
          tmpRecord3.SETRANGE(X,recRecord.X);
          tmpRecord3.SETRANGE(Y,recRecord.Y);
          tmpRecord3.SETRANGE(Z,recRecord.Z);
          IF NOT tmpRecord3.FIND('-') THEN BEGIN
            tmpRecord3 := recRecord; // with this, you have also a valid primary key for the temptable
            tmpRecord3.TotalField1 := 0;
            tmpRecord3.TotalField2 := 0;
            tmpRecord3.TotalField3 := 0;
            tmpRecord3.INSERT(FALSE);
          END;
        END;
    
        tmpRecord3.TotalField1 += recRecord.TotalField1;
        tmpRecord3.TotalField2 += recRecord.TotalField2;
        tmpRecord3.TotalField3 += recRecord.TotalField3;
        tmpRecord3.MODIFY(FALSE);
    
        // maintain a total per field X,Y
        IF (tmpRecord2.X <> recRecord2.X) OR
            (tmpRecord2.Y <> recRecord2.Y) THEN BEGIN
          tmpRecord2.RESET;
          tmpRecord2.SETCURRENTKEY(X,Y,Z);
          tmpRecord2.SETRANGE(X,recRecord.X);
          tmpRecord2.SETRANGE(Y,recRecord.Y);
          IF NOT tmpRecord2.FIND('-') THEN BEGIN
            tmpRecord2 := recRecord; // with this, you have also a valid primary key for the temptable
            tmpRecord2.TotalField1 := 0;
            tmpRecord2.TotalField2 := 0;
            tmpRecord2.TotalField3 := 0;
            tmpRecord2.INSERT(FALSE);
          END;
        END;
    
        tmpRecord2.TotalField1 += recRecord.TotalField1;
        tmpRecord2.TotalField2 += recRecord.TotalField2;
        tmpRecord2.TotalField3 += recRecord.TotalField3;
        tmpRecord2.MODIFY(FALSE);
    
        // maintain a total per field X
        IF (tmpRecord1.X <> recRecord2.X) THEN BEGIN
          tmpRecord1.RESET;
          tmpRecord1.SETCURRENTKEY(X,Y,Z);
          tmpRecord1.SETRANGE(X,recRecord.X);
          IF NOT tmpRecord1.FIND('-') THEN BEGIN
            tmpRecord1 := recRecord; // with this, you have also a valid primary key for the temptable
            tmpRecord1.TotalField1 := 0;
            tmpRecord1.TotalField2 := 0;
            tmpRecord1.TotalField3 := 0;
            tmpRecord1.INSERT(FALSE);
          END;
        END;
    
        tmpRecord1.TotalField1 += recRecord.TotalField1;
        tmpRecord1.TotalField2 += recRecord.TotalField2;
        tmpRecord1.TotalField3 += recRecord.TotalField3;
        tmpRecord1.MODIFY(FALSE);
    UNTIL recRecord.next = 0;
    

    Now that you have a temptable with the totals, you can start your report on those temptables.
    You need a dataitem on an integer per total-level (so 3 : X,Y,Z). Y must have property "DataItemIndent"=1 and Z property "DataItemIndent"=2
    X - OnPreDataItem()
    tmpRecord1.RESET;
    tmpRecord1.SETCURRENTKEY(X,Y,Z);
    
    RESET;
    SETRANGE(Number,tmpRecord1.COUNT);
    

    X - OnAfterGetRecord()
    IF Number = 1 THEN
      tmpRecord1.FIND('-')
    ELSE
      tmpRecord1.NEXT = 0;
    


    Y - OnPreDataItem()
    tmpRecord2.RESET;
    tmpRecord2.SETCURRENTKEY(X,Y,Z);
    tmpRecord2.SETRANGE(X,tmpRecord1.X);
    
    RESET;
    SETRANGE(Number,tmpRecord2.COUNT);
    

    Y - OnAfterGetRecord()
    IF Number = 1 THEN
      tmpRecord2.FIND('-')
    ELSE
      tmpRecord2.NEXT = 0;
    


    Z - OnPreDataItem()
    tmpRecord3.RESET;
    tmpRecord3.SETCURRENTKEY(X,Y,Z);
    tmpRecord3.SETRANGE(X,tmpRecord2.X);
    tmpRecord3.SETRANGE(Y,tmpRecord2.Y);
    
    RESET;
    SETRANGE(Number,tmpRecord3.COUNT);
    

    Z - OnAfterGetRecord()
    IF Number = 1 THEN
      tmpRecord3.FIND('-')
    ELSE
      tmpRecord3.NEXT = 0;
    

    In the sections, you can use the values of the temptables in the sourceexpresion. Eg. tmpRecord3.Y or tmpRecord3.TotalField1.
    And if you want the total TotalField1 for X or Y or Z, use tmpRecord1.TotalField1 or tmpRecord2.TotalField1 or tmpRecord3.TotalField1.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • DinDin Member Posts: 6
    sorry, for the delay. Thanks i will try it out :D Seems like somthing, that would work ok under the circumstances.
Sign In or Register to comment.