I have a big problem in Fujitsu COBOL V7. When using the CBL_CHECK_FILE_EXIST routine to see if a file exists I always gets return-code 0.
How can I see if a file exists or not?
You can use "GetFileAttributesA" (attributes of a file it's better than check_file_exist because is very short) if the file exist return-value is 0 else -1 you need use kernel32.lib.
On cbl routines routine check_file_exist is wrong, you can retrieve the correct file on support fujitsu.
************
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 COMODI.
03 W-CHAR PIC X VALUE X"00".
03 FILENAME PIC X(256).
03 RETURN-VALUE PIC S9(9) COMP-5.
PROCEDURE DIVISION.
CHECK-FILE-EXIST.
MOVE SPACE TO FILENAME
STRING
"\daca\ark\ARKDIT" DELIMITED BY SIZE
W-CHAR DELIMITED BY SIZE
INTO FILENAME
***************************
CALL "GetFileAttributesA" WITH STDCALL USING
BY REFERENCE FILENAME
RETURNING RETURN-VALUE
END-CALL.
********************
ERRORI.
IF RETURN-VALUE NOT = -1
GO TO CHECK1
ELSE
OPEN OUTPUT ARKDIT
MOVE SPACE TO RECD
WRITE RECD
CLOSE ARKDIT
GO TO CHECK1
You are correct that the CBL_CHECK_FILE_EXIST always returns a zero. It was that way in previous releases as well. You can check the File-Size return by this call for less than one. If the file size is less than 1 you can assume the file does not exist. The previous responce is also a good work around.
There was also an "undocumented feature" in the CBL_ routines. Fujitsu released a new DLL which is available to on their Support Web Site for clients with maintenance.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.