IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Want to put in a loop in EVALUATE


IBM Mainframe Forums -> COBOL Programming
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic :: View next topic  
Author Message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 108
Location: india

PostPosted: Fri Apr 06, 2012 3:35 pm
Reply with quote

Hi,

I want to execute my current Evaluate logic until end of records.
My current Evaluate is like that:

EVALUATE ACTION-TYPE
WHEN 'R'
PERFORM 1000-SELECT-PROCESS THRU 1000-EXIT
WHEN 'A'
PERFORM 2000-ACCEPT-PROCESS THRu 2000-EXIT
WHEN 'V'
PERFORM 3000-DELETE-PROCESS THRU 3000-EXIT
END-EVALUATE.

The above operation is for single record.
Now my new requirement is, if the ACTION-TYPE is V, then there may be multiple records to delete.

so i have to change the condition to accept for multiple records to delete.

If I code like this,

In the WORKING STORAGE SECTION... i declare
01 WS-SWITCHES.
05 END-OF-DEL-FILE-FLAG PIC X(01) VALUE 'N'.
88 END-OF-DEL-YES VALUE 'Y'.

then... changing the EVALUATE like...

EVALUATE ACTION-TYPE
WHEN 'R'
PERFORM 1000-SELECT-PROCESS THRU 1000-EXIT
WHEN 'A'
PERFORM 2000-ACCEPT-PROCESS THRu 2000-EXIT
END-EVALUATE.

EVALUATE ACTION-TYPE UNTIL END-OF-DEL-YES
WHEN 'V'
PERFORM 3000-DELETE-PROCESS THRU 3000-EXIT
AT END SET END-OF-DEL-YES TO TRUE
END-EVALUATE.

Will it work properly for sngle and multiple records to process when ACTION-TYPE = D ?

Thanks
Back to top
View user's profile Send private message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 108
Location: india

PostPosted: Fri Apr 06, 2012 3:36 pm
Reply with quote

little correcton.. in the last line

Will it work properly for sngle and multiple records to process when ACTION-TYPE = V ?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Apr 06, 2012 3:45 pm
Reply with quote

Why wouldn't your existing code work with multiple records?
Back to top
View user's profile Send private message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 108
Location: india

PostPosted: Fri Apr 06, 2012 4:09 pm
Reply with quote

I think once a single records processed(deleted), then it will execute END-EVALUATE.
If 5 records are there suppose with ACTION-TYPE as V, in that case i think the 1st record will delete.
Back to top
View user's profile Send private message
Peter cobolskolan

Active User


Joined: 06 Feb 2012
Posts: 104
Location: Sweden

PostPosted: Fri Apr 06, 2012 4:21 pm
Reply with quote

I understand you did not test your code, because it contains some COBOL-errors. WHY did you not test before asking ?

There is nothing as At End ind an evaluate!
You say you want to perform many deletes when ACTION-TYPE is V!
Why not put it in a loop like
Code:
When 'V'
     Perform 3000-Delete-Process
         Until End-Of-Del-Yes
End-Evaluate


In the 3000-Delete-Process paragraph you just set the End-Of-Del-Yes to true when you have finished your deletes.
Another tip: there is no need for the full stop (.) after a COBOL-verb. Just give a . at the end just before the the next paragraphname.
Yet another tip: Ever Never code Perform THRU ! Also there is no need for the different -EXIT paragraphs, assuming you dont code -70s COBOL using a lot of GO TOs.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Apr 06, 2012 4:29 pm
Reply with quote

You read a record, you do the evaluate with the new action type, whose code in the performs cause the current record to be processed. Repeat until EOF. What's difficult?

If you need to do "multiple stuff" to process any particular type of record, just code that inside the relevant perform.
Back to top
View user's profile Send private message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 108
Location: india

PostPosted: Fri Apr 06, 2012 4:46 pm
Reply with quote

For a single record, there is an ACTION-TYPE.
Suppose take 'V' as ACTION-TYPE, for each record there is an action type.
So If i put the end of record condition before the WHEN 'V', then only all the records will process.
If I put after that, which you provided, then how can all the records processed ? Instead it will process only one record.


I have not tested the code, because due to some interface with other application.
Back to top
View user's profile Send private message
Peter cobolskolan

Active User


Joined: 06 Feb 2012
Posts: 104
Location: Sweden

PostPosted: Fri Apr 06, 2012 5:09 pm
Reply with quote

You said:
Quote:
Now my new requirement is, if the ACTION-TYPE is V, then there may be multiple records to delete.

The quote from your post tells me that you have many records to delete when you find 'V' as Action-Type.
I will have to assume you read som records from a file (File1), and every record tells you "what to do". This "what to do" may be delete one or many records in another file (File2). In this case my code works.
I think you have to be more detailed in your description.
This is not a "problem", but normal programming logic for a COBOL-programmer. If you do not quallify, pls use ibmmainframeforum.com/ - for students etc.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1035
Location: Richmond, Virginia

PostPosted: Fri Apr 06, 2012 5:14 pm
Reply with quote

How do you help a new programmer by answering questions before he has even taken 5 minutes to test his code?
Back to top
View user's profile Send private message
coboljoost

New User


Joined: 05 Apr 2012
Posts: 5
Location: groningen

PostPosted: Thu Apr 12, 2012 2:04 am
Reply with quote

Peter cobolskolan wrote:
I understand you did not test your code, because it contains some COBOL-errors. WHY did you not test before asking ?

There is nothing as At End ind an evaluate!
You say you want to perform many deletes when ACTION-TYPE is V!
Why not put it in a loop like
Code:
When 'V'
     Perform 3000-Delete-Process
         Until End-Of-Del-Yes
End-Evaluate


In the 3000-Delete-Process paragraph you just set the End-Of-Del-Yes to true when you have finished your deletes.
Another tip: there is no need for the full stop (.) after a COBOL-verb. Just give a . at the end just before the the next paragraphname.
Yet another tip: Ever Never code Perform THRU ! Also there is no need for the different -EXIT paragraphs, assuming you dont code -70s COBOL using a lot of GO TOs.


in my opinion ALWAYS code a perform .. thru ..-exit
its best practice.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Apr 12, 2012 2:19 am
Reply with quote

coboljoost wrote:

in my opinion ALWAYS code a perform .. thru ..-exit
its best practice.


Welcome to the forum.

Not much of an argument to support your assertion, is there?

In my opinion ALWAYS follow the site standards. Feel free to try to change them, but if you loose the argument accept it and go with what everyone else does.

Three in the morning is no time to find that someone else's "best practice" has been misunderstood by someone on maintenance.

As to always code perform thru ..-exit, it's nuts. My opinion. However, if that is what a boss wants, that's what they get. And a request to explain why, of course :-)
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Thu Apr 12, 2012 7:01 pm
Reply with quote

@ maxsubrat

Back to the top first.

"EVALUATE ACTION-TYPE UNTIL END-OF-DEL-YES"

Wow, do we have an enhancement in the evaluate-clause now?
Back to top
View user's profile Send private message
coboljoost

New User


Joined: 05 Apr 2012
Posts: 5
Location: groningen

PostPosted: Thu Apr 12, 2012 11:39 pm
Reply with quote

Bill Woodger wrote:
coboljoost wrote:

in my opinion ALWAYS code a perform .. thru ..-exit
its best practice.


Welcome to the forum.

Not much of an argument to support your assertion, is there?

...


it has to do with the following :
.

...you might be working on small systems for small companies, but i work on huge systems for (huge) companies, since we use cobol i assume this is LEGACY software..otherwise the company probably uses an oop language..other companies use a cobol-dialect which is generated into normal cobol then compiled.

the generated cobol and also some -70's cobol and cobol by not-so-skilled programmers can contain many go to's.

there is no telling where u might end-up if there is a mishap in the code...
the thru... -exit is there for a good reason...

unless you live in a perfect world without go to's in legacy software, its best practise to use the thru.. -exit

did not mean to offend u, its my opinion.

there's no telling where you'll end up if someone made an error in code that does compile..

again, i work on code that in some cases has been written many years ago, it might been written by other programmers. the systems i work on are too large to read line by line. there might be go to's in the source and there might not be, i dont really need to know and i dont care. if the code works and the assignment is NOT to rewrite existing code i wont touch it.
It might have go to's it might not, with the thru ..-exit i keep risks in check.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Apr 13, 2012 12:11 am
Reply with quote

Don't worry, I am far from easily offended :-)

Quote:
there is no telling where u might end-up if there is a mishap in the code...
the thru... -exit is there for a good reason...

Quote:
unless you live in a perfect world without go to's in legacy software, its best practise to use the thru.. -exit

Quote:

there's no telling where you'll end up if someone made an error in code that does compile..

Quote:

It might have go to's it might not, with the thru ..-exit i keep risks in check.


The above seem to be the content of your reply. I am confused. If you yourself do not code GO TOs (I'm guessing you, generally, don't) then you don't need any paragraphs (as in those which are not PERFORMed), as you have nothing for them to be targets of. So you don't need a -exit. So you don't need PERFORM THRU. If you do code GO TOs yourself, you need paragraphs, and may well need -exit as a target for a GO TO.

Reading between the lines, you seem to think that the PERFORM THRU protects you in some way from the errant GO TOs of others. If you do think that, would you care to explain?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8651
Location: Dubuque, Iowa, USA

PostPosted: Fri Apr 13, 2012 12:33 am
Reply with quote

Quote:
there's no telling where you'll end up if someone made an error in code that does compile..
This is true no matter what standards are in use.

If a program contains GO TO and PERFORM statements, the possibility exists for falling through PERFORM EXIT paragraphs. In fact, a poorly written program can even fall through PERFORM EXIT paragraphs without a single GO TO statement in it -- we've seen examples on this forum.
Back to top
View user's profile Send private message
coboljoost

New User


Joined: 05 Apr 2012
Posts: 5
Location: groningen

PostPosted: Fri Apr 13, 2012 3:13 am
Reply with quote

reworked the post and could not find a delete button, see post below
Back to top
View user's profile Send private message
coboljoost

New User


Joined: 05 Apr 2012
Posts: 5
Location: groningen

PostPosted: Fri Apr 13, 2012 3:17 am
Reply with quote

Quote:

Reading between the lines, you seem to think that the PERFORM THRU protects you in some way from the errant GO TOs of others. If you do think that, would you care to explain?


as robert stated, when not using the exit statement the possibility exist for falling through the perform exit paragraph (especially so when using goto's).

when this happens it can be very hard to find out why a program is not behaving like expected (debugging might give you serious headaches!).

using the "thru ..-exit" will make life easier when debugging.

Although i do not use go to's myself, i mainly program in a cobol dialect (called delta-cobol), this source is generated into standard cobol(85) which in turn is compiled.

the generated cobol does contain many go to's (even though me and other programmers don't use go to's in the delta-cobol source).
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Apr 13, 2012 3:55 am
Reply with quote

coboljoost wrote:
[...]
as robert stated, when not using the exit statement the possibility exist for falling through the perform exit paragraph (especially so when using goto's).

What Robert actually wrote:
If a program contains GO TO and PERFORM statements, the possibility exists for falling through PERFORM EXIT paragraphs. In fact, a poorly written program can even fall through PERFORM EXIT paragraphs without a single GO TO statement in it -- we've seen examples on this forum.


Quite a different thing.

Quote:
using the "thru ..-exit" will make life easier when debugging.


Can you explain how?

Can you explain, leaving aside all the other stuff, what you think

Code:
    PERFORM A-PARAGRAPH THRU A-PARAGRAPH-EXIT

A-PARAGRAPH.

...

A-PARAGRAPH-EXIT.
    EXIT
    .


does for you? How does it protect you from GO TOs? How does it aid you at all? Leaving out all the rest, just sticking to the subject. You gave it as general advice, best practice, so...
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Apr 13, 2012 5:37 am
Reply with quote

one of my skills (for which i have received mucho dinero)
is laying code in a module so that no one can find my code except
due to an id and remarks.

if I am writing a program from scratch,
  • I follow site rules
  • and code it my way.

if I am making changes to a program, especially if it is a large complex module,
keeping in mind that when i leave, the people here will have to maintain the code,
i use the same coding style as the primary author (if his code is still around).

biggest problem with legacy programs,
there is NO modular programming techniques to be found.
the name of the game is try to figure out the logic,
determine what needs to be changed,
change it in such a way that it looks like the original authors style,
with reference to
  • paragraph naming conventions
  • paragraph PERFORM syntax
  • usage of GO TO
.

it is bad enough to have to follow logic in a legacy program
(alot of times, even new stuff)
without having to suddenly deal with a new coding style
and spend less time on the logic.

i don't advocate perform paragraph thru exit,
i am strickly a perform Section, without an exit
but if the piece of shit is so written, any additions will be in the same style.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Apr 13, 2012 1:00 pm
Reply with quote

But dbz, do you do work for "small systems for small companies" or "huge systems for (huge) companies"? It seems that it matters, somehow, at least for certain imaginations. I've been searching for the compiler options which reflect the difference...

I think I found 'em.

Code:
CBL BIGANDIMPORTANT(MAGICHAPPENS)
CBL NOBIGANDIMPORTANT(NOMAGIC)


coboljoost, you maybe feel you've had a rough entry here. We have many people who read what is posted here. If you post advice, you'd best be able to support it, otherwise it just misleads others.

If it is just plain, bland, "opinion", someone said to you one time and you've always done it without thinking about it, just leave it out, please.

'nuf for now.
Back to top
View user's profile Send private message
coboljoost

New User


Joined: 05 Apr 2012
Posts: 5
Location: groningen

PostPosted: Fri Apr 13, 2012 5:05 pm
Reply with quote

Bill Woodger wrote:
coboljoost wrote:
[...]
as robert stated, when not using the exit statement the possibility exist for falling through the perform exit paragraph (especially so when using goto's).

What Robert actually wrote:
If a program contains GO TO and PERFORM statements, the possibility exists for falling through PERFORM EXIT paragraphs. In fact, a poorly written program can even fall through PERFORM EXIT paragraphs without a single GO TO statement in it -- we've seen examples on this forum.


Quite a different thing.

Quote:
using the "thru ..-exit" will make life easier when debugging.


Can you explain how?

Can you explain, leaving aside all the other stuff, what you think

Code:
    PERFORM A-PARAGRAPH THRU A-PARAGRAPH-EXIT

A-PARAGRAPH.

...

A-PARAGRAPH-EXIT.
    EXIT
    .


does for you? How does it protect you from GO TOs? How does it aid you at all? Leaving out all the rest, just sticking to the subject. You gave it as general advice, best practice, so...


www.robelle.com/smugbook/cobol.html
point 3

www.tonymarston.net/cobol/cobolstandards.html#perform_through

5.7.1 PERFORM <section>
Even though COBOL allows the PERFORM command to be used on paragraphs as well as sections, its use should be limited to sections only. If necessary make the offending paragraph into a self-contained section, or an in-line PERFORM (if it is small enough). This guideline then avoids the possibility that someone may split the paragraph in two, thereby causing the PERFORM to terminate at the new paragraph name.
Please note that if the word SECTION is missed out on a section name it will be treated as a paragraph. As there is usually nothing but comments between the section name and the next paragraph it means that no code will actually be executed by that PERFORM statement. Unfortunately the code WILL be included in the PERFORM of the preceding section. This usually causes lots of confusion.


--------------------------------------------------------------------------------

5.7.2 PERFORM ... THROUGH ...
Avoid the use of PERFORM <procedure-A> THROUGH <procedure-Z>. It is good practice to name each procedure (section) explicitly - this makes it easier to search a source file for all occurrences of PERFORM <sectionname>, and also avoids the possibility that someone may add a new section between existing sections without realising that it now falls within the bounds of the PERFORM <A> THROUGH <C> statement. A program can produce some very peculiar results if a section is `accidentally' performed out of sequence, and is not easy to debug.

--------------------------------------------------------------------------------

5.7.3 The EXIT statement
The EXIT verb in COBOL does not produce an EXIT instruction in the object program - it is ignored, but is maintained for documentation purposes only. Whenever a section is PERFORMed COBOL will generate its own (hidden) EXIT instruction when the next section-name is encountered. If a section-name in your source file has the word SECTION missing, COBOL will treat it as a continuation of the preceding section - this can cause some very peculiar results (refer to PERFORM <section>).

--------------------------------------------------------------------------------

5.7.4 The GO TO statement
Do not use the GO TO verb to transfer control to a point which is outside the current section as any implied EXIT points will be ignored. This means that the program will go where it thinks it should go, which is probably NOT where it is supposed to go.

Guess i am not alone in my opinion on what is best practise am I ?
You seem to stubborn to convince though.
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 741
Location: Whitby, ON, Canada

PostPosted: Fri Apr 13, 2012 5:22 pm
Reply with quote

This thread almost makes me nostalgic for COMP.LANG.COBOL, where this sort of discussion can go on for weeks without ever reaching a consensus. icon_smile.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8651
Location: Dubuque, Iowa, USA

PostPosted: Fri Apr 13, 2012 5:27 pm
Reply with quote

coboljoost, if those are the standards your site follows, then follow them. Or, if they are the standards YOU want to follow, follow them. However, be aware that what you are quoting is more than 25 years old at this point, and COBOL is a dynamic language that changes over time. Since your link was last updated in 1993, I sincerely doubt it includes much about the COBOL 2002 changes, whether or not the standards are relevant any more. And of course there will be nothing about in-line PERFORM statements in those standards. But don't expect people on this forum, especially those of us with 25 ... 30 ... 35 or more years of COBOL coding experience, to agree with your opinions about what should be standards.

Furthermore, your post made extensive comments about SECTIONS -- which haven't been mentioned before in this thread. I have seen some really strange and difficult-to-debug errors arise from mixing PERFORM sections and PERFORM paragraphs in COBOL programs. Using SECTION names in a PROCEDURE DIVISION imposed an additional hierarchy on a program, a hierarchy that may -- or may not -- be intended.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Apr 13, 2012 5:30 pm
Reply with quote

I'm with you Don :-)

If someone repeatedly can't answer a question and uses the colour red to prove that grass is green, there is little that can usefully be done...
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8651
Location: Dubuque, Iowa, USA

PostPosted: Fri Apr 13, 2012 5:34 pm
Reply with quote

I think Bill and Don are right -- thread is being locked to avoid wasting any more time on pointless discussions about opinions.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Evaluate variable to execute a jcl step JCL & VSAM 3
No new posts REXX - Dataset checking in a do forev... CLIST & REXX 6
No new posts Need to read duplicate rows from tabl... DB2 3
This topic is locked: you cannot edit posts or make replies. Cobol db2 program going in loop COBOL Programming 4
No new posts Need to loop & extract from varia... CLIST & REXX 2
Search our Forums:

Back to Top