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

Nestings, IFs and other things


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Bill Woodger

Moderator Emeritus


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

PostPosted: Sun Apr 17, 2011 3:07 pm
Reply with quote

Peter wins then.

Firstly, again, apologies to the "other languages". This forum gets the most traffic. If anyone can suggest a way to be more "inclusive", do so please.

In some ways this is the "other side" of the GO TO discussion.

I'm including "other" nesting than IFs as well. Anything which sort of wanders off to the right of the screen.

This time, not so much arguments for or against, but maybe tips and techniques for keeping them under control.

As Dick said in the GO TO discussion, while talking about PERFORMS, thinking about how to use nesting clearly helps (me) to design a more "modular" program.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Sun Apr 17, 2011 4:36 pm
Reply with quote

Bill W. wrote:
which sort of wanders off to the right of the screen.

if you are lucky and they bother to indent.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Sun Apr 17, 2011 5:09 pm
Reply with quote

This is where nested EVALUATE's (introduced with VS/COBOL II) can replace 6-7 (or greater) nested IF levels ( Yikes icon_exclaim.gif ) and can come in real handy. As you say, the IF's just fall off the right side of the page/screen.... icon_eek.gif

Bill
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: Sun Apr 17, 2011 6:12 pm
Reply with quote

In the old days, if I was actually coding a case/evaluate structure, I would do it without the indenting, so it is clearer what it is:

IF condition a
PERFORM A-PARA
ELSE
IF condition b
PERFORM B-PARA
ELSE
IF condition c
PERFORM C-PARA
ELSE
IF condition d
PERFORM D-PARA
ELSE
error-condition-for-impossible-values

No need anymore. No need for a genuine nested IF not to be indented.

One place I worked we somehow got hold of a fold-out paper Thanksgiving Turkey decoration (this was in the UK, which was why it was odd). If someone did something stupid (like Dick's example) you had to display the Turkey on top of your terminal for a week (or until superseded, whichever was shorter). Helped a little to concentrate minds.

For a real nested IF (or anything) how to avoid? If you are faced with a five-level nest where you need a change, it is not a happy sight.

One sort of nesting, PERFORMed paras/sections, don't march off to the right.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Tue Apr 19, 2011 5:35 pm
Reply with quote

Hi !

If you spend more time for the design of programm, you could avoid inscrutable code. The hidden secret of a good programm is the right mixture of segmentation and the strict use of conditional and unconditional branch instruction like Evaluate and Perform. I'm a hardliner. I won't see any normal move or compute instruction in the main programm-controll-section. I also use qualifier in section-names
which tells me the depth of a section within the programm-flow. The older one of us will remember the IBM SPL framework using A05/B05/F05 and so on.

The only legal commands for me in a control-flow-section are Perform, Evaluate and an IF-Then-Else, but not nested.

Example:

S00-Progamm-Control-Flow Section
...Perform A00-Leading-Work
...Perform V00-Processing
...Perform Z00-Trailing-Work
S00-Progamm-Control-Flow-Exit

Then theese sections are also something like control sections but only for a specific task.

Example:

A00-Leading-Work Section
...Perform A05-Init
...Perform A05-Open
...A00-Leading-Work-Exit

...and again:

A05-Open Section
...Perform A10-Open-DSN1
...Perform A10-Open-DSN2
A05-Open-Exit

Example for the main processing control section.

V00-Processing Section

Perform V05-Do-Something-Before

Perform Until Programm-End
...Evaluate True
......When ...Perform V05-Do-Something-02
......When ...Perform V05-Do-Something-03
......When ...Perform V05-Do-Something-04
......When other continue
...End-Evaluate
End-Perform

Perform V05-Do-Something-After

V00-Processing-Exit

I use the same design in assembler too. Keeping my programms strictly using this design it was quite easy for me in former times to modify some moduls just in the middle of the night after a telephone call, just after a few bottles of red wine and some houres with a horney blonde chick.

Oh god, lucky old days. Nothing is left over. Only the red wine.


To be continued...





[/img]
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: Tue Apr 19, 2011 6:14 pm
Reply with quote

Thanks.

In this method, you displace the nesting. From the normal nested structures to the sections. So, your PERFORMs become nested. I'm interested in your section-naming structure, which is the only way I've really identified to deal with this "problem" automatically, otherwise I end up thinking these (the performed sections) are now just too "deep" to be readily understandable. And then you think some more.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Tue Apr 19, 2011 6:33 pm
Reply with quote

@ Bill

No sir, a perform intrinsically could never be nested.
For my clueless understanding.

The hierarchical adjustment of the performs could result in nested hierarchies of sections, ok, but that's all.

I allways try to avoid nested if-then-else structures when i have the chance to use evaluate.
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: Tue Apr 19, 2011 6:43 pm
Reply with quote

Let me try to clarify what I mean.

The inline-perform even makes it easier.


perform
stuff
perform
stuff
perform
stuff
endperform
endperform
endperform

So, maybe you don't use the inline-perform like that. But the same thing is what is really happening from sections. What I mean is that when you are down at the third level, you also have to be aware of what was relevant at the first and seconde levels.

Don't get me wrong. I like your structure. It is the one I used, even. I'm as surprised as perhaps you are :-)
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Tue Apr 26, 2011 4:00 pm
Reply with quote

@ Bill !

Hope you had a nice Weekend and found enougth Easter-Eggs.

Ok, Inline Perform is a very good thing. But i don't use him in an Control-Flow-Secion. I use him in real Prozessing-Section where alle the moves, computes and the iteration loops are done.

>> I'm as surprised as perhaps you are

Not really Bill. Outside there in the wholy mainframe universe, there are a lot more older Bit&Byte-Magician still coding accordingly to the rules and structure of the SPL framework.

As a freelancer i'm allways glad to see souch programms in the field at the customer, I just feel at home.
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: Tue Apr 26, 2011 5:10 pm
Reply with quote

@ UmeySan

Thanks, hope you are well too.

What about your naming convention for sections?

With the following, how would you name the sections? I mean the prefix part?

PERFORM A
PERFORM B
PERFORM C

A SECTION.
PERFORM D.
PERFORM E.
PERFORM F.
PERFORM Y.
B SECTION.
PERFORM G.
PERFORM H.
PERFORM I.
PERFORM Y.
C SECTION.
PERFORM J.
J SECTION.
PERFORM M.
Y SECTION.
PEFORM Z.
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Tue Apr 26, 2011 6:33 pm
Reply with quote

I'll (obviously) let UmeySan provide his own response as to how he would name the various sections, but this is how I would do it:
I assign 4-byte name prefixes that reflect both the hierarchical level of the section/paragraph (the first byte of the prefix (a letter)) and the order in which the section/paragraph was first referenced in the source (the second byte of the prefix (also a letter)); the third and fourth bytes of the prefix are numbers, which can be used to group related functions - e.g. for a given file, the last two prefix characters might be 10 for an OPEN, 20 for a START, 30 for a READ NEXT, 40 for a READ DIRECT, 50 for a WRITE, 60 for a REWRITE, 70 for a DELETE, and 80 for a CLOSE. The first two letters of the 'group' would be assigned in accordance with the 'normal' hierarchical/reference assignment logic.
The 4-byte prefix using this standard allows for 26 hierarchical levels and 2600 sections/paragraphs at each of those levels. FWIW, I normally assign I/O routines to hierarchical level 'X' and heavily referenced "utility" routines (e.g. display file-status error messages) to hierarchical level 'Z'.
The other thing I do is to always position the sections/paragraphs in the source in (ascending) prefix order. In this way, I always know where a referenced section/paragraph is located relative to the statement I am looking at - if the prefix is alphanumerically less than the current section/paragraph prefix, the referenced section/paragraph will be positioned earlier in the source; if greater, then later.
Also, VIEWing the source and executing
Code:
X ALL;F P'^' 8 ALL;F ' PERFORM ' ALL;X '*' 7 ALL

enables me to see the entire program structure at a glance (e.g. just what follows, minus the actual (non PERFORM) 'statements').

Code:
       PERFORM BA00-A
       PERFORM BB00-B
       PERFORM BC00-C

       BA00-A SECTION.
           PERFORM CA00-D.
           PERFORM CB00-E.
           PERFORM CC00-F.
           PERFORM CD00-Y.

       BB00-B SECTION.
           PERFORM CE00-G.
           PERFORM CF00-H.
           PERFORM CG00-I.
           PERFORM CD00-Y.

       BC00-C SECTION.
           PERFORM CH00-J.

       CA00-D SECTION.
           statements.

       CB00-E SECTION.
           statements.

       CC00-F SECTION.
           statements.

       CD00-Y SECTION.
           PEFORM DA00-Z.
 
       CE00-G SECTION.
           statements.

       CF00-H SECTION.
           statements.

       CG00-I SECTION.
           statements.

       CH00-J SECTION.
           PERFORM DB00-M.

       DA00-Z SECTION.
           statements.

       DB00-M SECTION.
           statements.
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: Tue Apr 26, 2011 9:39 pm
Reply with quote

Thanks Ronald, looks nice, something I can live with easily.

Mine is also an alpha/numeric combination, but the other way around.

The "main" part goes like this:

Code:

    PERFORM 00-fdsaf
    PERFORM 10-ggwg
    PERFORM 20-wewer
    PERFORM 30-qwrweq
    PERFORM 40-sdfderh
    PERFORM 50-hgtgr
    PERFORM 90-gera


Then:
Code:

10-ggwg SECTION.
    PERFORM 10A-fgrgr
    PERFORM 10D-gergerg
    PERFORM 10G-wertgrew
10A-fgrgr SECTION.
    PERFORM 10AA-feerwf
    PERFORM 10AD-grsgt
    PERFORM 10AG-qwet


Etc. The numbers show one "axis", the letters another, the "depth" of the level of the performs (my "nesting"). As the letters "march off to the right" too much, I know to look at things again and simplify.

00- for program start-up
10- for opening files
80- for closing files
90- for program shut-down

99- for "routines" used from more than one section. I didn't distinguish IO from non-IO, (I was kind of lucky, and managed to avoid most IO directly) but that is a nice touch from Ronald.

IF I wanted to use a "GO TO" I would do 50AD-G-dfjksdf for the paragraph name, thus knowing that it was the target of a GO TO.

All the sections would be in strict sort-sequence. You always knew where to find in the listing, and you always knew what it was performed by (except for the general use 99-s).

In the XREF, all the procedure lables would be in order by line number. Particularly if there were GO TOs, you can look at the XREF and see that they are not outside the range.

I'd always make the names meaningful. You can get a lot in 30 characters, and if you go over, even, it is not the end of the world.

Any more favourites, anyone?

The other thing is maintaining other people's programs. I tended to stick to their convention, unless there was more time available than usual, when, in that lucky instance, the first thing I would do is to reformat my way.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Apr 26, 2011 11:17 pm
Reply with quote

Quote:
the first thing I would do is to reformat my way.

gotta love edit macro's and REXX Scripts....
Back to top
View user's profile Send private message
don.leahy

Active Member


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

PostPosted: Wed Apr 27, 2011 2:00 am
Reply with quote

I have an irrational dislike for SECTIONs. It came about from having to debug too many programs that mix paragraphs and SECTIONS improperly. icon_evil.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Apr 27, 2011 3:21 am
Reply with quote

Story about SECTIONS/PARAGRAPHS
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: Wed Apr 27, 2011 5:28 am
Reply with quote

dbzTHEdinosauer wrote:

gotta love edit macro's and REXX Scripts....


And hate it when there are no standard "unit test packs". So, only re-jig for big program changes, where it is all going to be tested anyway.
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: Wed Apr 27, 2011 5:40 am
Reply with quote

don.leahy wrote:
I have an irrational dislike for SECTIONs. It came about from having to debug too many programs that mix paragraphs and SECTIONS improperly. icon_evil.gif


The thing is, how do you cater for idiots? The same person who adds a paragraph, after a SECTION, and performs the paragraph is probably going to add it in the middle of a perform thru as well. Or GO TO something that is not in the perform range.

OK, so you can get by without sections and without perform thrus. But then, if you can't, I definitely prefer sections. Even with no paragraphs in the section, I still code sections. Just in case, I suppose, or from habbit.

I'd sometimes idly think, why can't the compiler sort this out? "E" levels if you do dumb things. But too many earlier programs do dumb things, so "backwards compatability" loses out for everyone.

I'd like to see a compiler option like NOSH1, which, with the (T)est sub-parameter would highlight idiotic (outside of logical human readability scope) use of paragraph/section/go to - hey, for me, stick declaratives in as well if you like.
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: Wed Apr 27, 2011 5:51 am
Reply with quote

Funny thing is, for NOSH1(T), the OPT damn well knows about. List the generated code, look for any "non simple" returns anywhere, and then you know you have dodgy code in the program. Except declaratives. No idea how it handles that, but I suppose they are easy enough to spot anyway.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Wed Apr 27, 2011 6:49 pm
Reply with quote

@Bill

Naming convention for sections are still depending on personal advantages.

First, for my own, i make a difference between Control-Flow-Sections and real Processing-Sections. The real data-processing (move,compute,...) will only take place in these Processing-Sections. The logical flow of the data-processing within the programm ist guided by the Control-Sections.

I described it before. Ok, now naming conventions.

S00 Main Controll-Section of the Application

A00 Main Section for Programm-StartUp
V00 Main Section for Programm-Processing
Z00 Main Section for Programm-CleanUp

Whereas these sections are only Control-Sections witch perform others.

A00-Programm-StartUp
...Perform A05-Programm-Init
...Perform A05-Table-Init
A00-Programm-StartUp-Exit

A05-Table-Init
...Perform A10-Init-Kto-Tab
...Perform A10-Init-Ums-Tab
A05-Table-Init-Exit

A10-Init-Kto-Tab
...Set Kto-Ind to 1
...Perform until Kto-Ind > Kto-Max
......move x to y
......set Kto-Ind up by 1
...End-Perform
A10-Init-Kto-Tab-Exit


So, as you could see, the numer specifies the depth.
The first letter has a relationship to the kind of work.

A section named A45-blabla would be performed in section A40-blabla,
and will have a close link to A00. And this Section A45 has someting to do with the programm-Init. Same as Znn-Blabla. This section must have something to do with the Programm CeanUp at end of work.

Beside the A00, V00, and Z00 Main-Control-Sections i also have some universal sections for Open, Close, Write, or Declare Cursor, Fetch, Instert, Delete, etc.

So in any of my programms, Bnn-Sections will definitly deal with open dataset and Cnn will acordingly deal with close dataset.

If there's a B25, so it's a guideline, that this module opens five datasets.
B00 would be the Control-Sections for performing B05 till B25.

This Dataset would be read in Section R25 or written in Section W25
So as you see, there' quiet another kind of interrelationship.

Yes i know, perhaps it seams, something takes getting used to. But not for me. I'm used to it for the last 35 years. Whether Assembler, Cobol, Rexx, CSP, Abap.

And, at the end, i aggree with Dick, dbzTHEdinosauer.
Gotta love edit macro's and REXX Scripts

I have a little edit-rexx-proc which is executed by pressing a PF. The
Cursor has to be in a coding line. If there is a perform, pressing the PF will result in displaying the section. If the cursor is at a section-beginning, pressing PF will result in displaying all performs of this section. As a matter of course, this will also work for Assembler. Some more functions are included, but this will go beyond the scope of the discussion.

So, everyone of us has his own preferences and his own established-standards.

And i think, with every little new programm we are developping, our standard is expanding and ensuring the efficiency.

Every one of us has his own Holy Grail.
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: Wed Apr 27, 2011 7:27 pm
Reply with quote

UmeySan wrote:

...

So, everyone of us has his own preferences and his own established-standards.

And i think, with every little new programm we are developping, our standard is expanding and ensuring the efficiency.

Every one of us has his own Holy Grail.


Nicely put.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Wed Apr 27, 2011 8:42 pm
Reply with quote

Thanks Bill !

But i had forgotten:

... and his own demons, he has to struggle with.
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 28, 2011 2:15 pm
Reply with quote

Bill Woodger wrote:

perform
stuff
perform
stuff
perform
stuff
endperform
endperform
endperform



Rats, I see some idiot tried to indent without previewing (me). And then was told about it (but thought it was something else). Seems almost pointless to fix it now, but here we are - can't get it back in the post where it should have been.

Code:

perform
   stuff
   perform
      stuff
      perform
         stuff
      endperform
   endperform
endperform
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Things to Avoid while writing cobol p... COBOL Programming 3
No new posts Best things to say if caught sleeping... General Talk & Fun Stuff 0
No new posts What are all the things to be done in... CICS 5
No new posts How are we supposed to learn new things? All Other Mainframe Topics 14
No new posts Is there a means to simplify the thin... DFSORT/ICETOOL 4
Search our Forums:

Back to Top