Skip to main content

Problem:

File and Filename Routines: CBL_CHANGE_DIR, CBL_CHECK_FILE_EXIST, CBL_COPY_FILE, CBL_CREATE_DIR, CBL_DELETE_DIR, CBL_DELETE_FILE, CBL_DIR_SCAN_BEGIN, CBL_DIR_SCAN_END, CBL_DIR_SCAN_READ,  CBL_GET_CURRENT_DIR, CBL_JOIN_FILENAME, CBL_RENAME_FILE, CBL_SPLIT_FILENAME, PC_FIND_DRIVES,  PC_PRINT_FILE

PC_PRINTER_CLOSE, PC_PRINTER_CONTROL, PC_LOAD_BMP, PC_PRINTER_OPEN,

PC_PRINTER_WRITE, PC_PRINTER_WRITE_BMP, PC_READ_DRIVE, PC_SET_DRIVE

Example:

    01  infile-name  pic x(20) value '%TMP%/infile'.

    01 outfile-name pic x(20) value '%TMP%/outfile'.

    call 'CBL_COPY_FILE' using infile-name outfile-name.

Will fail unless a file with the literal name "%TMP%/infile" exists. Likewise for the outfile name.

The CBL_ routines use system API calls, not the command shell, to do their work. Only the command shell "knows" how to expand environment variables and passes the expanded string(s) to the specified command.

Resolution:

There are two possible solutions:

1. Expand the variable names in the COBOL program and build file name strings.

2. Pass a command string to the shell rather than use the functionally similar CBL_ routine.

The following examples use the values shown in the problem code fragment above.

Example of solution 1:

     01 infile-string  pic x(1024).

     01 outfile-string pic x(1024).

     01 tmp-value pic x(1024).

      display 'TMP' upon environment-name.

      accept tmp-value from environment-value.

      move spaces to infile-string outfile-string.

      string tmp-value '\\infile'

                delimited by spaces

                into infile-string.

      string tmp-value '\\outfile'

                delimited by spaces

                into outfile-string.

     call 'CBL_COPY_FILE' using infile-string outfile-string.

Example of solution 2:

    01 command-string.

          10 command-name pic x(20).

          10 filler pic x value space.

          10 command-arg-1  pic x(256).

          10 filler pic x value space.

          10 command-arg-2 pic x(256).

          10 command-terminator pic x value low-values.

    move 'copy' to command-name.

    move '%TMP%\\infile' to command-arg-1.

    move '%TMP%\\outfile' to command-arg-2.

    call 'SYSTEM' using command-string.

Old KB# 1220