Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

abortive exiting
New obsession....

With the following program, compiled using COBOL for VSE 1.1.1, I get the
following warnings:

PP 5686-068 IBM COBOL FOR VSE/ESA 1.1.1                        FSTEST
DATE 05/15/2006  TIME 13:04:25   PAGE    12


LINEID  MESSAGE CODE  MESSAGE TEXT



31  IGYOP3094-W   THERE MAY BE A LOOP FROM THE "PERFORM" STATEMENT AT
"PERFORM (LINE 31.01)" TO ITSELF.  "PERFORM" STATEMENT
OPTIMIZATION WAS NOT ATTEMPTED.



32  IGYOP3094-W   THERE MAY BE A LOOP FROM THE "PERFORM" STATEMENT AT
"PERFORM (LINE 32.01)" TO ITSELF.  "PERFORM" STATEMENT
OPTIMIZATION WAS NOT ATTEMPTED.



35  IGYOP3094-W   THERE MAY BE A LOOP FROM THE "PERFORM" STATEMENT AT
"PERFORM (LINE 35.01)" TO ITSELF.  "PERFORM" STATEMENT
OPTIMIZATION WAS NOT ATTEMPTED.


000001 ID DIVISION.
000002 PROGRAM-ID. FSTEST.
000003 ENVIRONMENT DIVISION.
000004 INPUT-OUTPUT SECTION.
000005 FILE-CONTROL.
000006     SELECT MY-FILE
000007       ACCESS SEQUENTIAL
000008       FILE STATUS FILE-STATUS
000009       ASSIGN TO MYFILE.
000010 DATA DIVISION.
000011 FILE SECTION.
000012 FD  MY-FILE
000013     RECORDING MODE F.
000014 01  MY-RECORD                   PIC X(80).
000015 WORKING-STORAGE SECTION.
000016 01  FILE-STATUS.
000017     88  FILE-AT-END                 VALUE '10'.
000018     05                          PIC X.
000019         88  FILE-SUCCESSFUL         VALUE '0'.
000020     05                          PIC X.
000021
000022 LINKAGE SECTION.
000023 01  FIELD-1  PIC X(80).
000024 PROCEDURE DIVISION USING FIELD-1.
000025 MAINLINE SECTION.
000026     PERFORM NESTED1
000027     EXIT PROGRAM.
000028
000029 NESTED1 SECTION.
000030     DISPLAY FIELD-1
000031     PERFORM OPEN-FILE
000032     PERFORM READ-RECORD
000033     PERFORM UNTIL FILE-AT-END
000034         PERFORM HANDLE-RECORD
000035         PERFORM READ-RECORD
000036     END-PERFORM
000037     PERFORM CLOSE-FILE
000038     GO TO NESTED1-EXIT.
000039
000040 HANDLE-RECORD.
000041     DISPLAY MY-RECORD
000042     .
000043
000044 OPEN-FILE.
000045     OPEN INPUT MY-FILE
000046     IF NOT FILE-SUCCESSFUL
000047         DISPLAY 'ERROR OPENING MYFILE, STATUS: ' FILE-STATUS
000048           UPON CONSOLE
000049         GO TO NESTED1-EXIT
000050     END-IF
000051     .
000052
000053 READ-RECORD.
000054     READ MY-FILE
000055     IF NOT FILE-SUCCESSFUL
000056         DISPLAY 'ERROR READING MYFILE, STATUS: ' FILE-STATUS
000057           UPON CONSOLE
000058         GO TO NESTED1-EXIT
000059     END-IF
000060     .
000061
000062 CLOSE-FILE.
000063     CLOSE MY-FILE
000064     .
000065
000066 NESTED1-EXIT. EXIT.
000067
000068 END PROGRAM FSTEST.

I'm probably just missing something totally obvious, but just exactly what
code is causing these warnings?  If I get rid of the GO TOs in OPEN-FILE and
READ-RECORD then the warnings go away, but of course the program does not
function as intended.

Please no comments about how the program should be recoded using flags and
other things.  This is just a trivial program solely intended to illustrate
the issue at hand.  I, in fact, discovered it when using a nested program
and using "EXIT PROGRAM" instead of the "GO TO"s.  I had thought it had
something to do with my use of nested programs, but that does not appear to
be the case.

Any thoughts?  Oh, and it does go away if I use NOOPT instead of OPT, for
the obvious reason...

Frank


---
Frank Swarbrick
Senior Developer/Analyst - Mainframe Applications
FirstBank Data Corporation - Lakewood, CO  USA

Report this thread to moderator Post Follow-up to this message
Old Post
Frank Swarbrick
05-15-06 11:55 PM


Re: abortive exiting
On Mon, 15 May 2006 13:11:35 -0600, "Frank Swarbrick"
<Frank.Swarbrick@efirstbank.com> wrote:

>New obsession....
>
>With the following program, compiled using COBOL for VSE 1.1.1, I get the
>following warnings:
>
>PP 5686-068 IBM COBOL FOR VSE/ESA 1.1.1                        FSTEST
>DATE 05/15/2006  TIME 13:04:25   PAGE    12
>
>LINEID  MESSAGE CODE  MESSAGE TEXT
>    31  IGYOP3094-W   THERE MAY BE A LOOP FROM THE "PERFORM" STATEMENT AT
>"PERFORM (LINE 31.01)" TO ITSELF.  "PERFORM" STATEMENT
>                      OPTIMIZATION WAS NOT ATTEMPTED.
>    32  IGYOP3094-W   THERE MAY BE A LOOP FROM THE "PERFORM" STATEMENT AT
>"PERFORM (LINE 32.01)" TO ITSELF.  "PERFORM" STATEMENT
>                      OPTIMIZATION WAS NOT ATTEMPTED.
>    35  IGYOP3094-W   THERE MAY BE A LOOP FROM THE "PERFORM" STATEMENT AT
>"PERFORM (LINE 35.01)" TO ITSELF.  "PERFORM" STATEMENT
>                      OPTIMIZATION WAS NOT ATTEMPTED.
>000001 ID DIVISION.
>000002 PROGRAM-ID. FSTEST.
>000003 ENVIRONMENT DIVISION.
>000004 INPUT-OUTPUT SECTION.
>000005 FILE-CONTROL.
>000006     SELECT MY-FILE
>000007       ACCESS SEQUENTIAL
>000008       FILE STATUS FILE-STATUS
>000009       ASSIGN TO MYFILE.
>000010 DATA DIVISION.
>000011 FILE SECTION.
>000012 FD  MY-FILE
>000013     RECORDING MODE F.
>000014 01  MY-RECORD                   PIC X(80).
>000015 WORKING-STORAGE SECTION.
>000016 01  FILE-STATUS.
>000017     88  FILE-AT-END                 VALUE '10'.
>000018     05                          PIC X.
>000019         88  FILE-SUCCESSFUL         VALUE '0'.
>000020     05                          PIC X.
>000021
>000022 LINKAGE SECTION.
>000023 01  FIELD-1  PIC X(80).
>000024 PROCEDURE DIVISION USING FIELD-1.
>000025 MAINLINE SECTION.
>000026     PERFORM NESTED1
>000027     EXIT PROGRAM.
>000028
>000029 NESTED1 SECTION.
>000030     DISPLAY FIELD-1
>000031     PERFORM OPEN-FILE
>000032     PERFORM READ-RECORD
>000033     PERFORM UNTIL FILE-AT-END
>000034         PERFORM HANDLE-RECORD
>000035         PERFORM READ-RECORD
>000036     END-PERFORM
>000037     PERFORM CLOSE-FILE
>000038     GO TO NESTED1-EXIT.
>000039
>000040 HANDLE-RECORD.
>000041     DISPLAY MY-RECORD
>000042     .
>000043
>000044 OPEN-FILE.
>000045     OPEN INPUT MY-FILE
>000046     IF NOT FILE-SUCCESSFUL
>000047         DISPLAY 'ERROR OPENING MYFILE, STATUS: ' FILE-STATUS
>000048           UPON CONSOLE
>000049         GO TO NESTED1-EXIT
>000050     END-IF
>000051     .
>000052
>000053 READ-RECORD.
>000054     READ MY-FILE
>000055     IF NOT FILE-SUCCESSFUL
>000056         DISPLAY 'ERROR READING MYFILE, STATUS: ' FILE-STATUS
>000057           UPON CONSOLE
>000058         GO TO NESTED1-EXIT
>000059     END-IF
>000060     .
>000061
>000062 CLOSE-FILE.
>000063     CLOSE MY-FILE
>000064     .
>000065
>000066 NESTED1-EXIT. EXIT.
>000067
>000068 END PROGRAM FSTEST.
>
>I'm probably just missing something totally obvious, but just exactly what
>code is causing these warnings?  If I get rid of the GO TOs in OPEN-FILE an
d
>READ-RECORD then the warnings go away, but of course the program does not
>function as intended.
>
>Please no comments about how the program should be recoded using flags and
>other things.  This is just a trivial program solely intended to illustrate
>the issue at hand.  I, in fact, discovered it when using a nested program
>and using "EXIT PROGRAM" instead of the "GO TO"s.  I had thought it had
>something to do with my use of nested programs, but that does not appear to
>be the case.
>
>Any thoughts?  Oh, and it does go away if I use NOOPT instead of OPT, for
>the obvious reason...
>
>Frank
Bad coding is the only thing I can think of when I see this type of
coding. But this is only my personal opinion.


The following will probably not issue the error.
NESTED1 SECTION.
NESTED1-START.               *> ALWAYS CODE PARAGRAPHS names.
DISPLAY FIELD-1
PERFORM OPEN-FILE
IF NOT FILE-SUCCESSFUL
GO TO NESTED1-EXIT
END-IF
PERFORM READ-RECORD
PERFORM UNTIL FILE-AT-END
OR NOT FILE-SUCESSEFUL  *> new code
PERFORM HANDLE-RECORD
PERFORM READ-RECORD
END-PERFORM
PERFORM CLOSE-FILE
GO TO NESTED1-EXIT.

HANDLE-RECORD.   *> Even this paragraph should be moved to
*> a section of its own.
*> I am almost sure that if you add a .
*> "GO TO NESTED1-EXIT" here that the warning
*> will occur also.
DISPLAY MY-RECORD

Report this thread to moderator Post Follow-up to this message
Old Post
Frederico Fonseca
05-15-06 11:55 PM


Re: abortive exiting
> If I get rid of the GO TOs in OPEN-FILE and
> READ-RECORD then the warnings go away, but of course the program
> does not function as intended.

It seems to me that it does not 'function as intended' at the moment.

I would suggest that you do not mix the performing of sections with the
performing of paragraphs. Choose one and stick to it. You may like to
consider that the _only_ reason for performing sections that have
several paragraph names (or perform thru) is to cater for gotos.

> 000032     PERFORM READ-RECORD
> 000033     PERFORM UNTIL FILE-AT-END
> 000034         PERFORM HANDLE-RECORD
> 000035         PERFORM READ-RECORD
> 000036     END-PERFORM
> 000037     PERFORM CLOSE-FILE

This perform does not terminate.  Instead you are bypassing the close
by jumping straight out of the read when the '10' status occurs.

> 000053 READ-RECORD.
> 000054     READ MY-FILE
IF File-At-End
CONTINUE
ELSE
> 000055     IF NOT FILE-SUCCESSFUL
> 000056         DISPLAY 'ERROR READING MYFILE, STATUS: ' > FILE-STATUS
> 000057           UPON CONSOLE
> 000058         GO TO NESTED1-EXIT
> 000059     END-IF
END-IF
> 000060     .


Report this thread to moderator Post Follow-up to this message
Old Post
Richard
05-16-06 02:55 AM


Re: abortive exiting

IDENTIFICATION DIVISION.
PROGRAM-ID. FSTEST.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT MY-FILE
ACCESS SEQUENTIAL
FILE STATUS FILE-STATUS
ASSIGN TO MYFILE.
DATA DIVISION.
FILE SECTION.
FD  MY-FILE
RECORDING MODE F.
01  MY-RECORD                   PIC X(80).
WORKING-STORAGE SECTION.
01  FILE-STATUS.
88  FILE-AT-END                 VALUE '10'.
05                          PIC X.
88  FILE-SUCCESSFUL         VALUE '0'.
05                          PIC X.

LINKAGE SECTION.
01  FIELD-1  PIC X(80).
PROCEDURE DIVISION USING FIELD-1.
MAINLINE.
PERFORM Process-File
EXIT PROGRAM.

Process-File.
DISPLAY FIELD-1
OPEN INPUT MY-FILE
IF ( NOT File-Successful )
DISPLAY 'ERROR OPENING MYFILE, STATUS: ' FILE-STATUS
UPON CONSOLE
ELSE
PERFORM READ-RECORD
PERFORM UNTIL NOT File-Successful
PERFORM HANDLE-RECORD
PERFORM READ-RECORD
END-PERFORM
CLOSE My-File
END-IF

HANDLE-RECORD.
DISPLAY MY-RECORD

Report this thread to moderator Post Follow-up to this message
Old Post
Richard
05-16-06 02:55 AM


Re: abortive exiting
I guess I didn't make myself clear.  I'm not looking for a solution, per se.
I can think of several other ways to get the job done.  I'm simply not
happy with them, for various reasons.
All I really want to know, at this point, is why am I getting this warning.

Anyway, take a look at the following.  This is more like what caused me to
bring up the issue.  I removed the "EXIT PROGRAM" logic from the subordinate
paragraphs and added additional checking to after the perform of OPEN-FILE.
But I don't like it.  It clutters up the main logic of the program.  If
there is an exceptional condition, one that generally should not occur, I
don't like to have to put code all over the place to recover from it.  So my
thought here was I could use EXIT PROGRAM to immediately quit out of NESTED1
and then, in the main program, I could check for RETURN-CODE > ZERO and exit
after the call, if necessary.  (Not shown here...)   Even that I'm not fond
of, but at least its just in one place.

And yes, it's quite possible that I am just being stubborn!

000001 ID DIVISION.
000002 PROGRAM-ID. OUTERPGM.
000003 ENVIRONMENT DIVISION.
000004 INPUT-OUTPUT SECTION.
000005 FILE-CONTROL.
000006     SELECT MY-FILE
000007       ACCESS SEQUENTIAL
000008       FILE STATUS FILE-STATUS
000009       ASSIGN TO MYFILE.
000010 DATA DIVISION.
000011 FILE SECTION.
000012 FD  MY-FILE                     IS GLOBAL
000013     RECORDING MODE F.
000014 01  MY-RECORD                   PIC X(80).
000015 WORKING-STORAGE SECTION.
000016 01  FILE-STATUS                 IS GLOBAL.
000017     88  FILE-AT-END                 VALUE '10'.
000018     05                          PIC X.
000019         88  FILE-SUCCESSFUL         VALUE '0'.
000020     05                          PIC X.
000021
000022 LINKAGE SECTION.
000023 01  FIELD-1  PIC X(80) GLOBAL.
000024 PROCEDURE DIVISION USING FIELD-1.
000025     CALL 'NESTED1'
000026     EXIT PROGRAM.
000027
000028 ID DIVISION.
000029 PROGRAM-ID. 'NESTED1'.
000030 PROCEDURE DIVISION.
000031     MOVE ZERO TO RETURN-CODE
000032     DISPLAY FIELD-1
000033     PERFORM OPEN-FILE
000034     IF RETURN-CODE > ZERO
000035         EXIT PROGRAM
000036     END-IF
000037     PERFORM READ-RECORD
000038     PERFORM UNTIL NOT FILE-SUCCESSFUL
000039         PERFORM HANDLE-RECORD
000040         PERFORM READ-RECORD
000041     END-PERFORM
000042     PERFORM CLOSE-FILE
000043     EXIT PROGRAM.
000044
000045 HANDLE-RECORD.
000046     DISPLAY MY-RECORD
000047     .
000048
000049 OPEN-FILE.
000050     OPEN INPUT MY-FILE
000051     IF NOT FILE-SUCCESSFUL
000052         DISPLAY 'ERROR OPENING MYFILE, STATUS: ' FILE-STATUS
000053           UPON CONSOLE
000054         MOVE 16 TO RETURN-CODE
000055     END-IF
000056     .
000057
000058 READ-RECORD.
000059     READ MY-FILE
000060     IF FILE-SUCCESSFUL OR FILE-AT-END
000061         CONTINUE
000062     ELSE
000063         DISPLAY 'ERROR READING MYFILE, STATUS: ' FILE-STATUS
000064           UPON CONSOLE
000065         MOVE 16 TO RETURN-CODE
000066     END-IF
000067     .
000068
000069 CLOSE-FILE.
000070     CLOSE MY-FILE
000071     .
000072
000073 END PROGRAM 'NESTED1'.
000074
000075 END PROGRAM OUTERPGM.

Oh, and FWIW, none of this code has actually been run.  I have only compiled
it just to see when I get the warning and when I don't.


Frank


---
Frank Swarbrick
Senior Developer/Analyst - Mainframe Applications
FirstBank Data Corporation - Lakewood, CO  USA

Report this thread to moderator Post Follow-up to this message
Old Post
Frank Swarbrick
05-16-06 08:55 AM


Re: abortive exiting
> All I really want to know, at this point, is why am I getting this warning
.

The warning is that the optimization is not being done because there is
a goto within the scope of the perform.  It does not analyse the code
sufficiently to know whether or not the gotos would affect the
optimizer, it just doesn't optimize.  To get rid of the warning either
code the program 'better' or use a compiler option to turn off the
optimizer.

BTW, I don't see that the later version as being 'better' for several
reasons, one of which is that it complexifies the problem.  For example
you have introduced several GLOBALs (which are generally considered
bad) in order to use line 35 EXIT PROGRAM when it could be same effect
can be easily done with an ELSE in a paragraph that is performed:

000034     IF RETURN-CODE > ZERO
000035         CONTINUE
000036     ELSE
000037         PERFORM READ-RECORD
000038         PERFORM UNTIL NOT FILE-SUCCESSFUL
000039             PERFORM HANDLE-RECORD
000040             PERFORM READ-RECORD
000041         END-PERFORM
000042         PERFORM CLOSE-FILE
000043     END-IF.


Report this thread to moderator Post Follow-up to this message
Old Post
Richard
05-16-06 08:55 AM


Re: abortive exiting
Richard wrote:

> when it could be same effect
> can be easily done with an ELSE in a paragraph that is performed:

Or more easily with:

> 000034     IF File-Successful
> 000037         PERFORM READ-RECORD
> 000038         PERFORM UNTIL NOT FILE-SUCCESSFUL
> 000039             PERFORM HANDLE-RECORD
> 000040             PERFORM READ-RECORD
> 000041         END-PERFORM
> 000042         PERFORM CLOSE-FILE
> 000043     END-IF.


Report this thread to moderator Post Follow-up to this message
Old Post
Richard
05-16-06 08:55 AM


Re: abortive exiting
New version of my previous posting.
Without sections or gotos, but with a style of perform I dont like
either, but that is very common also.

LINKAGE SECTION.
01  FIELD-1  PIC X(80).
PROCEDURE DIVISION USING FIELD-1.
MAINLINE SECTION.
NESTED1-START.
DISPLAY FIELD-1
PERFORM OPEN-FILE
PERFORM READ-RECORD
PERFORM UNTIL FILE-AT-END
PERFORM HANDLE-RECORD
PERFORM READ-RECORD
END-PERFORM
PERFORM CLOSE-FILE

Report this thread to moderator Post Follow-up to this message
Old Post
Frederico Fonseca
05-16-06 08:55 AM


Re: abortive exiting
Frederico Fonseca wrote:
> New version of my previous posting.
> Without sections or gotos, but with a style of perform I dont like
> either, but that is very common also.
>
>       LINKAGE SECTION.
>       01  FIELD-1  PIC X(80).
>       PROCEDURE DIVISION USING FIELD-1.
>       MAINLINE SECTION.
>       NESTED1-START.
>           DISPLAY FIELD-1
>           PERFORM OPEN-FILE
>           PERFORM READ-RECORD
>           PERFORM UNTIL FILE-AT-END
>               PERFORM HANDLE-RECORD
>               PERFORM READ-RECORD
>           END-PERFORM
>           PERFORM CLOSE-FILE
>           .
>       EXIT-PROGRAM.
>           GOBACK.  *>or exit program if your compiler does
>                    *>not support this
>
>       HANDLE-RECORD.
>           DISPLAY MY-RECORD
>           .
>
>       CLOSE-FILE.
>           CLOSE MY-FILE
>           .
>
>
>      *> Moved code to sections.
>       OPEN-FILE
>           OPEN INPUT MY-FILE
>           IF NOT FILE-SUCCESSFUL
>               DISPLAY 'ERROR OPENING MYFILE, STATUS: ' FILE-STATUS
>                 UPON CONSOLE
>               PERFORM EXIT-PROGRAM
>           END-IF
>           .
>
>       READ-RECORD.
>           READ MY-FILE
>           IF  NOT FILE-SUCCESSFUL
>           AND NOT FILE-AT-END
>               DISPLAY 'ERROR READING MYFILE, STATUS: ' FILE-STATUS
>                 UPON CONSOLE
>               PERFORM EXIT-PROGRAM       <===== E!
>           END-IF

Suggest changing PERFORM EXIT-PROGRAM to Move "Yes" to FILE-AT-END (or
whatever the flag might be) else the program exits without going through the
file close routine. The compiler may automatically close the files and
release locks upon exit, but maybe not.



Report this thread to moderator Post Follow-up to this message
Old Post
HeyBub
05-16-06 12:55 PM


Re: abortive exiting

> Move "Yes" to FILE-AT-END (or whatever the flag might be)

Actually that is not required at all as the READ will set the
File-At-End condition true automatically, which you should have noticed
had you been paying attention.

> The compiler may automatically close the files and
> release locks upon exit, but maybe not.

Actually COBOL specifies exactly when the file will be closed
automatically and when it will not be, so there is no 'maybe' about
this.

But you get a 2 out of 10 for noticing that the program won't go
through the CLOSE when there is a failure on the READ.


Report this thread to moderator Post Follow-up to this message
Old Post
Richard
05-16-06 11:55 PM


Sponsored Links




Last Thread Next Thread Next
Pages (5): [1] 2 3 4 5 »
Search this forum -> 
Post New Thread

Cobol archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 02:51 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.