Skip to main content

Hi, i have a doubt.

When we invoke the CBL_CHECK_FILE_EXIST routine ,the second parameter "file-details" is obligatory?

    call "CBL_CHECK_FILE_EXIST" using file-name-1
                                                                   file-details
    returning status-code

 I´ve found a program in my company that make the call whithout  the second parameter .

If we run the program only once everithing is all right but if we run it twice it hangs.

Hi, i have a doubt.

When we invoke the CBL_CHECK_FILE_EXIST routine ,the second parameter "file-details" is obligatory?

    call "CBL_CHECK_FILE_EXIST" using file-name-1
                                                                   file-details
    returning status-code

 I´ve found a program in my company that make the call whithout  the second parameter .

If we run the program only once everithing is all right but if we run it twice it hangs.

from the mf help

On Entry:
filename The file to look for. The name can contain a path, and is terminated by a space. If no path is given, the current directory is assumed.

This routine does not work with filenames containing wildcard characters.

On Exit:
cblte-fe-filesize The size of the file in bytes.
cblte-fe-filedate The date the file was created.
cblte-fe-filetime The time the file was created.

when you don't need the file-details, only one parameter is ok

you can call also a winapi for checking if the file exist


from the mf help

On Entry:
filename The file to look for. The name can contain a path, and is terminated by a space. If no path is given, the current directory is assumed.

This routine does not work with filenames containing wildcard characters.

On Exit:
cblte-fe-filesize The size of the file in bytes.
cblte-fe-filedate The date the file was created.
cblte-fe-filetime The time the file was created.

when you don't need the file-details, only one parameter is ok

you can call also a winapi for checking if the file exist

>> when you don't need the file-details, only one parameter is ok


 
M carmen De paz please ignore this comment, the second parameter is important to pass otherwise you will get stack corruption and your application may appear to work but something somewhere is being corrupted.  

You can get the compiler to give a error message on the wrong number of parameters by including the cblproto.cpy copybook, for example:

copy "cblproto.cpy".
program-id. bad_cbl.
procedure division.

call "CBL_CHECK_FILE_EXIST" using by reference "wibble ".

Then when you compile you get the message:

# cob -ia fred.cbl
2716 call "CBL_CHECK_FILE_EXIST" using by reference "wibble ".
*1061-E************************************************************ **
** Number of parameters is less than in prototype


Hi, i have a doubt.

When we invoke the CBL_CHECK_FILE_EXIST routine ,the second parameter "file-details" is obligatory?

    call "CBL_CHECK_FILE_EXIST" using file-name-1
                                                                   file-details
    returning status-code

 I´ve found a program in my company that make the call whithout  the second parameter .

If we run the program only once everithing is all right but if we run it twice it hangs.

With Windows and Netexpress 5.x there is no compile error when not use file-details, but later by runtime.

This will be different with linux, may be.

Here the running code:

       program-id. test1.
       working-storage section.
       77  dateiname                     pic x(40) value 'c:\\upd\\test.cbl'.
       77  status-code                   pic xx comp-x.
       01  file-details.
           03  cblte-fe-filesize         pic x(8) comp-x.
           03  cblte-fe-filedate.
               05  cblte-fe-day           pic x comp-x.
               05  cblte-fe-month      pic x comp-x.
               05  cblte-fe-year         pic x(2) comp-x.
           03  cblte-fe-filetime.
               05  cblte-fe-hours      pic x comp-x.
               05  cblte-fe-minutes  pic x comp-x.
               05  cblte-fe-seconds pic x comp-x.
               05  cblte-fe-hundredths pic x comp-x.
       01  ws-fields.
           03  ws-filesize             pic zzz,zzz,zz9.
           03  ws-date.
               05  dd                     pic 9(02).
               05                          pic x(01) value '.'.
               05  mm                 pic 9(02).
               05                        pic x(01) value '.'.
               05  yyyy               pic 9(04).
           03  ws-time.
               05  hh                 pic 9(02).
               05                       pic x(01) value ':'.
               05  mn                pic 9(02).
               05                       pic x(01) value ':'.
               05  ss                 pic 9(02).
               05                       pic x(01) value ':'.
               05  ms                pic 9(03).
       procedure division.
             *> no compile error on windows os with netexpress5.x,
             *> but runtime error 114=attempt to access item beyond
             *> of memory (signal 11)
             call 'CBL_CHECK_FILE_EXIST' using dateiname
                                         returning status-code
             end-call
             *> This call is correct and work fine
             call 'CBL_CHECK_FILE_EXIST' using dateiname
                                               file-details
                                         returning status-code
             end-call
             if status-code not = 0
                display 'Error ' at 0101
             else
                move cblte-fe-filesize to ws-filesize
                move cblte-fe-day to dd in ws-date
                move cblte-fe-month to mm in ws-date
                move cblte-fe-year to yyyy in ws-date
                move cblte-fe-hours to hh in ws-time
                move cblte-fe-minutes to mn in ws-time
                move cblte-fe-seconds to ss in ws-time
                move cblte-fe-hundredths to ms in ws-time
                display 'Filesize is: ' ws-filesize
                display 'Date is    : ' ws-date
                display 'Time is    : ' ws-time
             end-if
             stop run
             .

Here the winapi command to do the same, verify a path, or path and file (here only the entry point)

       Entry "Dir-File-exist" using ws-verzeichnis.
           set pathfileptr to address of ws-verzeichnis
           call winapi 'PathFileExistsA' using by reference
                                                          ws-verzeichnis
                                       returning status-code
           end-call
           if status-code = 1
              move ' ' to error-msg
              string ws-verzeichnis delimited by x'00'
                     ' ' delimited by ' '
                     'exist' delimited by size
                     into fehlermeldung
           else
              move ' ' to error-msg
              string ws-verzeichnis delimited by x'00'
                     ' ' delimited by ' '
                     'not exist' delimited by size
                     into error-msg
           end-if
           exit program
           .


With Windows and Netexpress 5.x there is no compile error when not use file-details, but later by runtime.

This will be different with linux, may be.

Here the running code:

       program-id. test1.
       working-storage section.
       77  dateiname                     pic x(40) value 'c:\\upd\\test.cbl'.
       77  status-code                   pic xx comp-x.
       01  file-details.
           03  cblte-fe-filesize         pic x(8) comp-x.
           03  cblte-fe-filedate.
               05  cblte-fe-day           pic x comp-x.
               05  cblte-fe-month      pic x comp-x.
               05  cblte-fe-year         pic x(2) comp-x.
           03  cblte-fe-filetime.
               05  cblte-fe-hours      pic x comp-x.
               05  cblte-fe-minutes  pic x comp-x.
               05  cblte-fe-seconds pic x comp-x.
               05  cblte-fe-hundredths pic x comp-x.
       01  ws-fields.
           03  ws-filesize             pic zzz,zzz,zz9.
           03  ws-date.
               05  dd                     pic 9(02).
               05                          pic x(01) value '.'.
               05  mm                 pic 9(02).
               05                        pic x(01) value '.'.
               05  yyyy               pic 9(04).
           03  ws-time.
               05  hh                 pic 9(02).
               05                       pic x(01) value ':'.
               05  mn                pic 9(02).
               05                       pic x(01) value ':'.
               05  ss                 pic 9(02).
               05                       pic x(01) value ':'.
               05  ms                pic 9(03).
       procedure division.
             *> no compile error on windows os with netexpress5.x,
             *> but runtime error 114=attempt to access item beyond
             *> of memory (signal 11)
             call 'CBL_CHECK_FILE_EXIST' using dateiname
                                         returning status-code
             end-call
             *> This call is correct and work fine
             call 'CBL_CHECK_FILE_EXIST' using dateiname
                                               file-details
                                         returning status-code
             end-call
             if status-code not = 0
                display 'Error ' at 0101
             else
                move cblte-fe-filesize to ws-filesize
                move cblte-fe-day to dd in ws-date
                move cblte-fe-month to mm in ws-date
                move cblte-fe-year to yyyy in ws-date
                move cblte-fe-hours to hh in ws-time
                move cblte-fe-minutes to mn in ws-time
                move cblte-fe-seconds to ss in ws-time
                move cblte-fe-hundredths to ms in ws-time
                display 'Filesize is: ' ws-filesize
                display 'Date is    : ' ws-date
                display 'Time is    : ' ws-time
             end-if
             stop run
             .

Here the winapi command to do the same, verify a path, or path and file (here only the entry point)

       Entry "Dir-File-exist" using ws-verzeichnis.
           set pathfileptr to address of ws-verzeichnis
           call winapi 'PathFileExistsA' using by reference
                                                          ws-verzeichnis
                                       returning status-code
           end-call
           if status-code = 1
              move ' ' to error-msg
              string ws-verzeichnis delimited by x'00'
                     ' ' delimited by ' '
                     'exist' delimited by size
                     into fehlermeldung
           else
              move ' ' to error-msg
              string ws-verzeichnis delimited by x'00'
                     ' ' delimited by ' '
                     'not exist' delimited by size
                     into error-msg
           end-if
           exit program
           .

  you did not include the CALL prototype header file cblproto.cpy, therefore the compiler must trusts that you know what you are doing.   


For example, if the program or API you are calling has variadic parameters, the compiler needs to do what you say.   For example; if you call printf or sprintf it does not have a fixed number of parameters.