I'm trying to write a subprogram in COBOL to make a logfile called from my main program. I don't want the logfile is cleared every time I call the subprogram so I use 'open extend'. The problem is because of an unknown reason it won't work, the program does nothing. When i change 'open extend' into 'open output' it works but I don't want the file is overwritten every time.
IDENTIFICATION DIVISION.
PROGRAM-ID. LOGGER.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT LOGFILE ASSIGN TO "LOGFILE.txt"
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD LOGFILE.
copy "FDLOGGER.cpy".
WORKING-STORAGE SECTION.
LINKAGE SECTION.
01 LOGFILEBOODSCHAP PIC X(150) value spaces.
Procedure division USING LOGFILEBOODSCHAP.
pgm.
open EXTEND LOGFILE
Move Current-time to TIJD
Move Current-date to DATUM
Move LOGFILEBOODSCHAP to BOODSCHAP
write logrecord
close LOGFILE
exit program
.
Well, it's a guess, as you have not provided much, but if "LOGFILE.txt" does not exist, you will need OPTIONAL on your SELECT.
Suggest you put FILE STATUS checking in your code.