So I'm trying to make a program in OpenCobolIDE that uses the SCREEN SECTION
feature in COBOL to create a menu where the user chooses whether he wants to input data or display it.
This data is being recorded in a sequential .txt file. The writing process works fine so I don't add the code of this part here. The problem is in the reading process. I wanted the program to display multiple times the DISPLAY-SCREEN
in a PERFORM
loop showing all the records in my file but this is not working. I thought that by removing the BLANK SCREEN
from my DISPLAY-SCREEN
it would work the way I wanted but all that happens is that the program shows the DISPLAY-SCREEN
a single time and it doesn't even display any records. What could be the problem? Here is the code:
IDENTIFICATION DIVISION.
PROGRAM-ID.PGM001.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT MYFILE ASSIGN TO "DATA.TXT"
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD MYFILE.
01 FS-TB.
02 FS-ID PIC X(03).
02 FS-NAME PIC A(15).
02 FS-PHONE PIC X(09).
WORKING-STORAGE SECTION.
01 WS-TB.
02 WS-ID PIC X(03).
02 WS-NAME PIC A(15).
02 WS-PHONE PIC X(09).
01 WS-EOF PIC A(01) VALUE "N".
01 WS-COUNT PIC 9(01) VALUE ZERO.
01 WS-OP PIC 9(01).
SCREEN SECTION.
01 MENU-SCREEN.
02 BLANK SCREEN.
02 LINE 1 COL 1 VALUE "------------------------------------".
02 LINE 2 COL 1 VALUE "- MENU -".
02 LINE 3 COL 1 VALUE "------------------------------------".
02 LINE 4 COL 1 VALUE "- (1).REGISTER -".
02 LINE 5 COL 1 VALUE "- (2).DISPLAY -".
02 LINE 6 COL 1 VALUE "- (3).EXIT -".
02 LINE 7 COL 1 VALUE "- -".
02 LINE 8 COL 1 VALUE " OPTION:( ) -".
02 LINE 9 COL 1 VALUE "------------------------------------".
02 LINE 8 COL 20 PIC 9(01) TO WS-OP.
01 DISPLAY-SCREEN.
02 LINE 1 COL 1 VALUE "------------------------------------".
02 LINE 2 COL 1 VALUE "- DISPLAY -".
02 LINE 3 COL 1 VALUE "------------------------------------".
02 LINE 4 COL 1 VALUE "-(1).ID : -".
02 LINE 4 COL 18 PIC X(03) FROM WS-ID.
02 LINE 5 COL 1 VALUE "-(2).NAME : -".
02 LINE 5 COL 18 PIC A(15) FROM WS-NAME.
02 LINE 6 COL 1 VALUE "-(3).PHONE : -".
02 LINE 6 COL 18 PIC X(09) FROM WS-PHONE.
02 LINE 7 COL 1 VALUE "------------------------------------".
PROCEDURE DIVISION.
A-100.
DISPLAY MENU-SCREEN.
ACCEPT MENU-SCREEN.
EVALUATE WS-OP
WHEN 1
GO TO A-200
WHEN 2
GO TO A-300
WHEN 3
STOP RUN
WHEN OTHER
GO TO A-100
END-EVALUATE.
A-200.
A-300.
OPEN INPUT MYFILE
PERFORM UNTIL WS-EOF = "Y"
READ MYFILE INTO WS-TB
AT END MOVE "Y" TO WS-EOF
NOT AT END DISPLAY DISPLAY-SCREEN
END-READ
END-PERFORM
CLOSE MYFILE.
STOP RUN.
END PROGRAM PGM001.
As Bill pointed out already: The PERFORM
and DISPLAY
is too fast.
To see every record you´d need to add an ACCEPT
after the DISPLAY
, I guess ACCEPT OMITTED
will work, if not add a dummy var and ACCEPT
this.
You seem to not want to stop the program during the PERFORM
then you may add an ACCEPT DUMMY
at the program's end (always useful if you use extended DISPLAY/ACCEPT
). But you would only get the last item displayed.
Depending on your needs a CALL 'CBL_OC_NANOSLEEP' USING 500000000
(wait one-half second) or CALL 'C$SLEEP' USING 1
after the DISPLAY DISPLAY-SCREEN
may be the result you want.
But likely the best option would be ACCEPT dummy WITH TIMEOUT time
(if you press ENTER it goes directly to the next DISPLAY
if you don't it will wait the specified time before doing the next DISPLAY
.