HP OpenVMS Systems

ask the wizard
Content starts here

Calling RTL LIB$ routines in COBOL?

» close window

The Question is:

I am trying to obtain information about files in a directory with a view to
 deleting them, but need to do this within a COBOL program. Are there any
 examples on equivalent COBOL calls to f$search and delete in DCL?

The Answer is :

  lib$find_file and lib$delete_file would be the calls involved.
  Attached is an example of these calls from within a COBOL program.
Identification Division.
Program-ID. filefind.
Environment Division.
Configuration Section.
Data Division.
file section.
working-storage section.
01  answer  pic x.
01  file-spec  pic x(7)  value '*.tmp;*'.
01  result-spec   pic x(255)  value spaces.
01  context  pic 9(5) comp value zero.
01  stat pic s9(9) comp value zero.
01  counter  pic s9(9) comp value zero.
01  rms$_nmf pic s9(9) comp value external rms$_nmf.
01  rms$_normal pic s9(9) comp value external rms$_normal.
procedure division.
        move "N" to answer.
        call 'lib$find_file' using by descriptor file-spec
                                by descriptor  result-spec
                                by reference context
                                 omitted omitted omitted
                        giving stat.
        if stat = rms$_nmf then go to fini.
        display result-spec.
        display "Delete? " with no advancing.
        accept answer.
        if answer = "y" then move "Y" to answer.
        if answer not equal "Y" then go to loop.
        call 'lib$delete_file' using by descriptor file-spec giving stat.
        if stat = rms$_normal then go to loop.
        display "Delete status = ", stat with conversion.
        go to loop.
        call 'lib$find_file_end' using by reference context.
        stop run.

answer written or last revised on ( 16-NOV-2000 )

» close window