Recordref: How to sort by FieldNo instead of FieldIndex?

mr.burnsmr.burns Member Posts: 39
Hello,

I create a function to copy the content of a table given by table ID to a textfile. What I do is:
  Table.OPEN(TableID); // Table is of type recordref
  FieldCount := Table.FieldCount;
    
  FOR FieldIndex := 1 TO FieldCount DO
  BEGIN
    // copy fieldcontent to textfile
  END;

My problem now is the order of the fields in the textfile is not same as the order of the fields in the table.
This is because the loop uses the fieldindex of the recordref and this goes from 1 to FIELDCOUNT.
What I need is a recordref sorted by FIELDNO as I see if I open a table using the designer.
Is there any way to loop through a recordref variable which is sorted by FieldNo instead of FieldIndex?

Thanks for any help!

Comments

  • AlbertvhAlbertvh Member Posts: 516
    Hi

    If you need the contents of the record set you could use this

    OBJECT Codeunit 90005 Value to Text Using Field Ref
    {
      OBJECT-PROPERTIES
      {
        Date=03/07/07;
        Time=11:20:16;
        Modified=Yes;
        Version List=Toolbox;
      }
      PROPERTIES
      {
        OnRun=BEGIN
                TextFile.TEXTMODE := TRUE;
                TextFile.CREATE('C:\Temp.txt');
                Field.SETFILTER(TableNo,'%1',3);
                IF Field.FINDSET THEN BEGIN
                  RecordReference.OPEN(Field.TableNo);
                  IF RecordReference.FINDSET THEN
                    REPEAT
                      Field.FINDFIRST;
                      TextLine := '';
                      REPEAT
                        FieldReference := RecordReference.FIELD(Field."No.");
                        TextLine := TextLine + '|' + FORMAT(FieldReference);
                      UNTIL Field.NEXT = 0;
                      TextFile.WRITE(DELCHR(TextLine,'<','|'));
                    UNTIL RecordReference.NEXT = 0;
                  RecordReference.CLOSE;
                END;
                TextFile.CLOSE;
              END;
    
      }
      CODE
      {
        VAR
          Field@1000000005 : Record 2000000041;
          TextFile@1000000006 : File;
          Char@1000000003 : Char;
          T10@1000000004 : Text[1];
          RecordReference@1000000000 : RecordRef;
          FieldReference@1000000001 : FieldRef;
          TextLine@1000000002 : Text[1024];
    
        BEGIN
        END.
      }
    }
    
    

    This is using the Payment Terms table and output looks like this
    ADVANCE|0D||0|Payable in Advance|No
    CHEQUE|0D||0|Cheque Payment|No
    COD|CD||0|Cash Payment|No
    DIRECT|0D||0|Direct Bank Transfer|No
    EOM|CM+1M||0|End of Current Month + 1 Month|No
    PRE|0D||0|Pre-Paid before delivery can commence|No
    14DAYS|14D||0|14 Days|No
    15DAYS|15D||0|15 Days|No
    30 DAYS|30D||0|30 Days from Invoice Date|No
    30DAYS|CM+1D+1M-1D||0|30 Days|No
    30DDISC|CM+1D+1M-1D||2.5|30 Days Less 2.5% Discount|No
    60DAYS|60D||0|60 Days|No
    7DAYS|7D||0|7 Days From Installation|No
    7DAYSS|CM+7D||0|7 Days from statement|No
    7DAYS1|7D||0|7 Days From Invoice|No
    7DDISC|7D||10|7 Days from Invoice less 10% Discount|No
    90DAYS|90D||0|90 Days|No
    

    or is it the field names and numbers you want if so just use the "field" table

    Albert
  • mr.burnsmr.burns Member Posts: 39
    Thanks, that helped!
  • pdjpdj Member Posts: 643
    I never noticed it was different? :?
    Well, you can use the Field table, and loop throug that, and use "FldRef := RecRef.FIELD(Field."No.")" instead of "FldRef := RecRef.FIELDINDEX(FieldIndex)"

    Seems I were to slow to press Submit...
    Regards
    Peter
Sign In or Register to comment.