Tables Collection?

mstallmannmstallmann Member Posts: 138
Is there a way to loop through all of the tables in the database? I am trying to search and replace on all of the tables/fields in the database. I saw a post where someone looped through:

Foreach Table do
- Foreach Record (using recref) do
- Foreach Field (using virtual Fields) do
- check recref.fieldref.value for string

But this is VB code...navision doesn't have a for each...does it?????

Confused,

Mike

Comments

  • jsoagejsoage Member Posts: 9
    Hope this helps,
    VAR
      v_AllObjects@1000000000 : Record 2000000038;
      v_RecRef@1000000001 : RecordRef;
      v_FldRef@1000000002 : FieldRef;
      v_I@1000000003 : Integer;
      v_Modify@1000000004 : Boolean
    BEGIN
      WITH v_AllObjects DO BEGIN
        SETRANGE("Object type", "Object type"::Table);
        SETFILTER("Object ID", '<%1', 2000000001); // Non-system tables
        IF FIND('-') THEN
          REPEAT
            v_RecRef.OPEN("Object ID");
            v_Modify := FALSE;
            FOR v_I := 1 TO v_RecRef.FIELDCOUNT DO BEGIN
              v_FldRef := v_RecRef.FIELDINDEX(v_I);
    // +++ << Your code here >>
              IF <Your conditions> THEN BEGIN
                v_FldRef.VALIDATE(<Your value>);
                v_Modify := TRUE;
              END;
    // ---
            END;
    // +++ << Your code here >>
              IF v_Modify THEN v_RecRef.MODIFY(<TRUE/FALSE>)
    // ---
            v_RecRef.CLOSE;
          UNTIL NEXT = 0;
      END;
    END;
    
  • mstallmannmstallmann Member Posts: 138
    Thank you for your help...You're a stud...

    Just needed to add one more loop...thought I'd put it up there for future users looking for same solution...



    VAR
    v_AllObjects@1000000000 : Record 2000000038;
    v_RecRef@1000000001 : RecordRef;
    v_FldRef@1000000002 : FieldRef;
    v_I@1000000003 : Integer;
    v_Modify@1000000004 : Boolean
    BEGIN
    WITH v_AllObjects DO BEGIN
    SETRANGE("Object type", "Object type"::Table);
    SETFILTER("Object ID", '<%1', 2000000001); // Non-system tables
    IF FIND('-') THEN
    REPEAT
    v_RecRef.OPEN("Object ID");
    v_Modify := FALSE;

    *Add* IF v_RecRef.FIND('-') THEN BEGIN
    *Add* REPEAT
    FOR v_I := 1 TO v_RecRef.FIELDCOUNT DO BEGIN
    v_FldRef := v_RecRef.FIELDINDEX(v_I);
    // +++ << Your code here >>
    IF <Your conditions> THEN BEGIN
    v_FldRef.VALIDATE(<Your value>);
    v_Modify := TRUE;
    END;
    *Add* UNTIL RecRef.NEXT=0;
    *Add* END;
    // ---
    END;
    // +++ << Your code here >>
    IF v_Modify THEN v_RecRef.MODIFY(<TRUE/FALSE>)
    // ---
    v_RecRef.CLOSE;
    UNTIL NEXT = 0;
    END;
    END;
Sign In or Register to comment.