0
I use Netexpress in my work and I’m looking to develop some programs at home to practice, as the Netexpress license is paid for, I opted for GNU/Open Cobol.
The problem I am having is that after using an "Exit" in Section it is closing my file, by what I read, this occurs because the compiler identifies that there is a "stop run" in my code, and closes the file to not finish the program without closing.
I know that there are some differences between the compilers, in the case of Netexpress, using "Exit" it just exits from Section and returns to the line where perform occurred.
The problem happens after the perform 1110-pd0001-acha-id-dispnivel
in Section 1100-processamento
, it reads and finds the last record, but when it comes back to record the file is closed.
I am using Opencobolide.
My code:
IDENTIFICATION DIVISION.
PROGRAM-ID. teste.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT PD0001 ASSIGN TO DISK wid-pd0001
ORGANIZATION IS INDEXED
ACCESS IS sequential
RECORD KEY IS pd0001-mestre-chave
FILE STATUS IS ws-status-acesso.
DATA DIVISION.
FILE SECTION.
FD PD0001.
01 pd0001-mestre.
03 pd0001-mestre-chave.
05 pd0001-mestre-id PIC 9(10) VALUE ZERO.
05 pd0001-tp-reg-mestre PIC 9(01) VALUE ZERO. *> 1
03 pd0001-mestre-data PIC x(200) VALUE SPACE.
01 pd0001-entry-1.
03 pd0001-r1-chave.
05 tp-reg-r1 PIC 9(01) VALUE ZERO. *> 2
05 pd0001-r1-id PIC 9(10) VALUE ZERO.
05 pd0001-r1-seq PIC 9(01) VALUE ZERO.
03 pd0001-r1-data PIC x(200) VALUE SPACE.
WORKING-STORAGE SECTION.
01 ws-status-acesso PIC x(02) VALUE ZERO.
88 ws-acesso-ok VALUE "00".
01 ws-working-vars.
03 ws-prox-id PIC 9(10) VALUE ZERO.
PROCEDURE DIVISION.
1000-controle section.
1000.
perform 1100-inicializacao
perform 1100-processamento
.
1000-exit.
stop run.
1100-inicializacao section.
1100.
move ".\test.dat" to wid-pd0001
perform 1110-criar-pd0001
.
1100-exit.
exit.
1100-processamento section.
1100.
open i-o PD0001
if not ws-acesso-ok
display "Erro ao abrir arquivo PD0001. Status: " ws-status-acesso
exit section
end-if
perform 1110-pd0001-acha-id-dispnivel
initialize pd0001-mestre
move ws-prox-id to pd0001-mestre-id
move "test" to pd0001-mestre-data
write pd0001-mestre
if not ws-acesso-ok
display "Erro ao gravar pd0001-mestre. Status: " ws-status-acesso
exit section
end-if
initialize pd0001-mestre
perform until not ws-acesso-ok
read pd0001 next
display pd0001-mestre
display pd0001-entry-1
end-perform
close PD0001
.
1100-exit.
exit.
1110-pd0001-acha-id-dispnivel section.
1110.
initialize pd0001-mestre
move zeros to ws-prox-id
move 1 to pd0001-tp-reg-mestre
move 9999999999 to pd0001-mestre-id
start pd0001 key is not greater pd0001-mestre-chave
read PD0001 previous
if ws-acesso-ok
if ws-status-acesso = "23"
exit section
end-if
end-if
compute ws-prox-id = pd0001-mestre-id + 1
.
1110-exit.
exit.
1110-criar-pd0001 section.
1111.
open output PD0001
close PD0001
.
1111-exit.
exit.