¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Re: ChapGPT


 

¿ªÔÆÌåÓý

Bob,

I used write a complete cobol program¡­ also you can use regenerate and it might add the working storage. I liked the explanation at the end..

Did it write the program or did it ¡°find¡± it? Could not get it to use goback.

So I asked GPT why it does not use goback..


Using "STOP RUN" terminates the entire program and closes all files. "GOBACK" simply exits the current PERFORM or READ loop and returns control to the beginning of the loop. In this case, using "GOBACK" instead of "STOP RUN" would cause the program to continuously loop through the file, reading and printing each record indefinitely. "STOP RUN" is used to end the program after all records have been read and printed.

That is perhaps why it gets away without the working storage flag?


IDENTIFICATION DIVISION.

PROGRAM-ID. READ-AND-PRINT.


ENVIRONMENT DIVISION.

INPUT-OUTPUT SECTION.

FILE-CONTROL.

???SELECT INPUT-FILE ASSIGN TO "input.txt"

???ORGANIZATION IS SEQUENTIAL.


DATA DIVISION.

FILE SECTION.

???FD INPUT-FILE.

???01 INPUT-RECORD.

?? ? ??02 INPUT-FIELD PIC X(30).


WORKING-STORAGE SECTION.

???01 EOF-FLAG PIC X VALUE 'N'.


PROCEDURE DIVISION.

???OPEN INPUT INPUT-FILE

???PERFORM UNTIL EOF-FLAG = 'Y'

? ? ??READ INPUT-FILE

?? ? ? ??AT END MOVE 'Y' TO EOF-FLAG

? ? ??END-READ

? ? ??DISPLAY INPUT-FIELD

???END-PERFORM

???CLOSE INPUT-FILE

???STOP RUN.


Explanation:

The IDENTIFICATION DIVISION and PROGRAM-ID paragraphs are used to identify the program.

The ENVIRONMENT DIVISION contains the INPUT-OUTPUT SECTION, where we specify the input file and its organization (in this case, sequential).

The DATA DIVISION contains the FILE SECTION, where we define the input file and its record layout (in this case, a single field of 30 characters).

The WORKING-STORAGE SECTION is used to define any variables or flags that we need to use in our program. In this case, we define a flag?EOF-FLAG?to keep track of whether we have reached the end of the file.

In the PROCEDURE DIVISION, we open the input file, then perform a loop until we reach the end of the file. Inside the loop, we read a record from the file and display it. If the end of the file is reached, we set the?EOF-FLAG?to 'Y' to signal that the loop should terminate. Finally, we close the input file and stop the program.







Air 2

On Jan 6, 2023, at 1:43 AM, Bob Flanders <bob.flanders@...> wrote:

Join [email protected] to automatically receive all group messages.