SQL$HELP72.HLB  —  REPEAT Control, Example
    Example 1: Using a REPEAT Statement to List Files in the Current
    Directory

    SQL> SET VERIFY;
    SQL> ATTACH 'FILE SCRATCH';
    SQL> CREATE DOMAIN file_name  VARCHAR(255);
    SQL>  CREATE PROCEDURE find_file
    cont>    (IN :FILESPEC file_name BY DESCRIPTOR,
    cont>     INOUT :RESULTANT_FILESPEC file_name BY DESCRIPTOR,
    cont>     INOUT :CONTEXT INTEGER BY REFERENCE);
    cont> EXTERNAL NAME LIB$FIND_FILE
    cont> LOCATION 'SYS$LIBRARY:LIBRTL.EXE'
    cont> LANGUAGE GENERAL
    cont> PARAMETER STYLE GENERAL
    cont> COMMENT IS
    cont>    'DCL HELP: LIB$FIND_FILE '
    cont>     / 'The Find File routine is called with a wildcard  file'
    cont>      / 'specification for  which   it   searches.    LIB$FIND_FILE '
    SQL> CREATE PROCEDURE Find_file_end
    cont>    (IN :CONTEXT INTEGER BY REFERENCE);
    cont> EXTERNAL
    cont>    NAME LIB$FIND_FILE_END
    cont>     LOCATION 'SYS$LIBRARY:LIBRTL.EXE'
    cont>     LANGUAGE GENERAL
    cont>    PARAMETER STYLE GENERAL
    cont> COMMENT IS
    cont>   'DCL HELP: LIB$FIND_FILE_END '
    cont>    / 'The End of Find File routine is called once'
    cont>    / 'after each  sequence  of '
    cont>    / 'calls to LIB$FIND_FILE. LIB$FIND_FILE_END deallocates'
    cont>    / 'any saved Record Management Service (RMS) context and'
    cont>    / 'deallocates the virtual memory used to hold the'
    cont>    / 'allocated context block.';
    SQL> SET FLAGS 'TRACE';
    SQL> BEGIN
    cont> -- This procedure performs a call to an external
    cont> -- routine to list files located in the current
    cont> -- default directory
    cont> DECLARE :done, :context integer = 0;
    cont> DECLARE :search_string FILE_NAME = '*.SQL';
    cont> DECLARE :file_spec FILE_NAME;
    cont> REPEAT
    cont>     -- Ask the OpenVMS routine for the next name
    cont>     CALL find_file (:search_string, :file_spec, :context);
    cont>     IF POSITION ('*' in :file_spec) = 0
    cont>        AND POSITION ('%' in :file_spec) = 0
    cont>        AND POSITION ('...' in :file_spec) = 0
    cont>     THEN
    cont>         -- Display the name (there are no wildcards)
    cont>         TRACE :file_spec;
    cont>     ELSE
    cont>        SET :done = 1;
    cont>    END IF;
    cont>   -- Exit when we have no more file names
    cont>   UNTIL :done = 1
    cont> END REPEAT;
    cont> -- Clean up search context
    cont> CALL find_file_end (:context);
    cont> END;
    ~Xt: RDBVMS:[USER.V71]CREATE_ROLES.SQL;1
    ~Xt: RDBVMS:[USER.V71]TEST.SQL;1
    SQL>
Close Help