sort order in a table.

karuchuakaruchua Member Posts: 151
edited 2012-10-24 in NAV Three Tier
how can get the first record in a table or the last for a set of records.

for example in the purchase line table,i want for every document number,just get the first line.

the code below only gives the first record for all the records in the table.




setcurrentkey(Document Type,Document No.,Line No.);
setrange(document type,document type::order);
setrange(document no,document no);

if "purchase line" .findfirst then begin
GitemNo=purchase line.No.

end

Comments

  • SavatageSavatage Member Posts: 7,142
    So your code uses FINDFIRST. There is also FIND, FINDLAST & FINDSET:
    details here:

    FINDFIRST: http://msdn.microsoft.com/en-us/library/dd338835.aspx
    FINDLAST: http://msdn.microsoft.com/en-us/library/dd338877.aspx
    FINDSET: http://msdn.microsoft.com/en-us/library/dd301434.aspx
    FIND: http://msdn.microsoft.com/en-us/library/dd301096.aspx

    Are you saying the code is working for you but it's not doing it for each new doc number?
    what exactly is the issue?
  • SavatageSavatage Member Posts: 7,142
    Now, if you want find the first item number of each PO then I would use the Purchase Header Table as your dataitem. That way on each OnAfterGetRecord it gives you a new PO. Then you can use that data to filter your purchase Line table. Here's a sample report....
    OBJECT Report 50023 Test Report
    {
      OBJECT-PROPERTIES
      {
        Date=10/24/12;
        Time=12:16:03 PM;
        Modified=Yes;
        Version List=MIBUSO Sample;
      }
      PROPERTIES
      {
      }
      DATAITEMS
      {
        { PROPERTIES
          {
            DataItemTable=Table38;
            OnAfterGetRecord=BEGIN
                               PurchLine.SETRANGE("Document Type","Document Type");
                               PurchLine.SETRANGE("Document No.","No.");
                               PurchLine.SETRANGE(Type,PurchLine.Type::Item);
    
                               IF PurchLine.FIND('-') THEN BEGIN
                                 PL_DocNo := PurchLine."Document No.";
                                 PL_ItemNo := PurchLine."No.";
                                END ELSE BEGIN
                                 CurrReport.SKIP;
                               END;
                             END;
    
          }
          SECTIONS
          {
            { PROPERTIES
              {
                SectionType=Header;
                PrintOnEveryPage=Yes;
                SectionWidth=18150;
                SectionHeight=1269;
              }
              CONTROLS
              {
                { 1000000002;TextBox;15000;0    ;3150 ;423  ;HorzAlign=Right;
                                                             SourceExpr=FORMAT(TODAY,0,4) }
                { 1000000003;TextBox;0    ;0    ;7500 ;423  ;SourceExpr=COMPANYNAME }
                { 1000000004;TextBox;17700;423  ;450  ;423  ;CaptionML=ENU=Page;
                                                             SourceExpr=CurrReport.PAGENO }
                { 1000000005;Label  ;16950;423  ;750  ;423  ;ParentControl=1000000004 }
                { 1000000006;TextBox;15900;846  ;2250 ;423  ;HorzAlign=Right;
                                                             SourceExpr=USERID }
              }
               }
            { PROPERTIES
              {
                SectionType=Body;
                SectionWidth=18150;
                SectionHeight=423;
              }
              CONTROLS
              {
                { 1000000000;TextBox;150  ;0    ;3600 ;423  ;SourceExpr=PL_DocNo }
                { 1000000001;TextBox;4350 ;0    ;3450 ;423  ;SourceExpr=PL_ItemNo }
              }
               }
          }
           }
      }
      REQUESTFORM
      {
        PROPERTIES
        {
          Width=9020;
          Height=3410;
        }
        CONTROLS
        {
        }
      }
      CODE
      {
        VAR
          PurchLine@1000000000 : Record 39;
          PL_DocNo@1000000001 : Code[20];
          PL_ItemNo@1000000002 : Code[20];
    
        BEGIN
        END.
      }
    }
    

    It finds the first line and the report shows the doc no & item no.
    Adjust it to show whatever fields you need.
Sign In or Register to comment.