/*****************************************************************************
         AUTHOR: Unknown
*****************************************************************************/

def SHARED var savefname    like _file._file-name                       no-undo.
def SHARED var show_labels  as log format "Y/N"                         no-undo.
def SHARED var sub_title    as cha format "x(70)"                       no-undo.
def SHARED var sfile        as cha format "x(15)"   label "First Table" no-undo.
def SHARED var efile        as cha format "x(15)"   label "Last Table"  no-undo.
DEF SHARED VAR from-field   AS CHA FORMAT "x(15)"   LABEL "From Field"  NO-UNDO.
DEF SHARED VAR to-field     AS cha FORMAT "x(15)"   LABEL "To Field"    NO-UNDO.
def SHARED var file_count   as int format ">>,>>9"  label "Files"       no-undo.
def SHARED var field_count  as int format ">>,>>9"  label "Fields"      no-undo.
DEF SHARED VAR i            AS INT                                      NO-UNDO.
def SHARED stream s.

form
    skip(1)   
    file_count       colon 20 label "File Count" skip(1)   
    field_count      colon 20 label "Field Count" skip(1)   
    
with 
    center 
    row 2 
    side-labels 
    title " DB Schema Listing " 
    frame fcount_fr.

for each {1}._file 
    where {1}._file._file-name >= sfile 
      and {1}._file._file-name <= efile no-lock:   

    disp 
        _file._file-name FORMAT "x(15)"
        file_count 
        field_count
    with frame fcount_fr.

    if line-counter(s) > 1 or page-number(s) > 1 then 
        put stream s skip(1).   
    savefname = "".   
    for each {1}._field of {1}._file
        WHERE _field-name GE from-field
        AND _field-name LE to-field
        no-lock      
    with frame db-fields-frame: 

        file_count = file_count + 1.
        field_count = field_count + 1.

        disp stream s skip(1) 
            
            _file._file-name + ' ; ' + _file._Desc + ' ; ' + _field-name 
            format 'x(132)'
        with no-label no-box no-attr-space WIDTH 200 frame dbFileFrame.
        if show_labels then
        do:
            down with frame db-fields-frame.
            display stream s
                '"' + _field._label + '"' @ _field._field-name
            with frame db-fields-frame.
            down with frame db-fields-frame.
        end.
        IF i = 1 THEN savefname = _file._file-name.
    end.   
end.
