HOME  NEWS  FORUM  DOWNLOAD  LINK
OpenCOBOL - an open-source COBOL compiler
Main Menu
Download
Documentation
Development
Who's Online
17 user(s) are online (5 user(s) are browsing Forum)

Members: 0
Guests: 17

more...
Powered by
SourceForge

Xoops

Creative Commons

OpenCOBOL Forum Index
   OpenCOBOL
     COBOL question: use of "through" in if/when/until...
Register To Post

Threaded | Oldest First Previous Topic | Next Topic | Bottom
Poster Thread
human
Posted on: 2008/7/19 1:58
Home away from home
Joined: 2007/5/15
From: GERMANY
Posts: 1416
Re: COBOL question: use of "through" in if/when/until...
@aoirthoir: As I said there are different parts of myvar that need to be checked together. All in all I want to have nicer variants than evaluate all different versions, so I did
                 evaluate true
                    when ((myvar (01:05) = 'ABCDE'   or
                                           'DEFGH'   or
                                           'IJKLS'          ) and
                          (myvar (06:02) numeric            ) and
                          (myvar (06:02) not = spaces       ) and
                          (myvar (08:  ) = spaces           )    )
                 ...
      *
                    when ((myvar (01:04) = 'ffaa'           ) and
                          (myvar (05:02) numeric            ) and
                          (myvar (05:02) not = spaces       ) and
                          (myvar (07:01) = '1' or '2' or '3') and
                          (myvar (08:  ) = 'B'  or   'BC'   )    )
                 ...
                 end-evaluate
instead of
                 evaluate myvar
                    when 'ABCDE01'
                    when 'ABCDE02'
                    when 'ABCDE03'
                    when 'ABCDE04'
                    when 'ABCDE05'
                    when 'ABCDE06'
                    when 'ABCDE07'
                    when 'ABCDE08'
                    when 'ABCDE09'
                    when 'ABCDE10'
                    when 'ABCDE11'
                    when 'ABCDE12'
                    when 'DEFGH01'
                    when 'DEFGH02'
                    when 'DEFGH03'
                    when 'DEFGH04'
                    when 'DEFGH05'
                    when 'DEFGH06'
                    when 'DEFGH07'
                    when 'DEFGH08'
                    when 'DEFGH09'
                    when 'DEFGH10'
                    when 'DEFGH11'
                    when 'DEFGH12'
                 ...
      *
                    when 'ffaa141B'
                    when 'ffaa142B'
                    when 'ffaa143B'
                    when 'ffaa141BC'
                    when 'ffaa142BC'
                    when 'ffaa143BC'
                    when 'ffaa151B'
                    when 'ffaa152B'
                    when 'ffaa153B'
                    when 'ffaa151BC'
                    when 'ffaa152BC'
                    when 'ffaa153BC'
                    when 'ffaa161B'
                    when 'ffaa162B'
                    when 'ffaa163B'
                    when 'ffaa161BC'
                    when 'ffaa162BC'
                    when 'ffaa163BC'
                 ...
                 end-evaluate

What I can think of now is to maybe replace the second evaluate (evaluate true) against
evaluate true also myvar (5:2) also myvar (6:2) also myvar (7:1) also ...
but I think this will be neither more readable nor faster.
I'd just searched for a nice way to evaluate different substrings of one string in multiple combinations but it seem like the only fine variant is the beginning code.

The only thing that can maybe be solved is question two
Quote:
human wrote:
2. Concerning the "different cases" (1st part of posted code): Is it faster/slower to have multiple 88er levels and do an evaluate true / when case1 / when case2 / ... than to do an evaluate myvar / when "string1" / when "string2"?
aoirthoir
Posted on: 2008/7/18 9:13
Home away from home
Joined: 2007/4/16
From: Cleveland Ohio
Posts: 321
Re: COBOL question: use of "through" in if/when/until...
1. The answer is yes:
EVALUATE myvar
WHEN 1 Through 12



But as Roger said you still have to explain the actual problem you are trying to solve. Rather you're trying to explain one method you are using to solve the problem.
simrw
Posted on: 2008/7/18 8:42
Webmaster
Joined: 2005/5/31
From: Bad Soden, Germany
Posts: 791
Re: COBOL question: use of "through" in if/when/until...
Sorry, but you have still not answered the question where and how the data is being interpreted.
This is really totally off-topic for the OC forum.
This is a classic case of analysis.

Roger
human
Posted on: 2008/7/18 8:19
Home away from home
Joined: 2007/5/15
From: GERMANY
Posts: 1416
Re: COBOL question: use of "through" in if/when/until...
Myvar is just a text string of 12 chars. That evaluate is the main section of the program and just do performs of other sections(sometime an index is set before the perform) depending on the content of myvar and it's that big evaluate that seems a little bit ... weird.

Here are the detailed questions:
1. Concerning the "special cases" (2nd part of posted code): Is there any possibility for asking (if a = '01' through '12') without multiple 88 levels? It seems like: no.
2. Concerning the "different cases" (1st part of posted code): Is it faster/slower to have multiple 88er levels and do an evaluate true / when case1 / when case2 / ... than to do an evaluate myvar / when "string1" / when "string2"?

PS: I'm not paid for thinking of how to rearrange such cobol structures, but I would like to have a better solution than the actual code (that you've indeed seen, only the names are a bit different and some other when / performs are did in the same way I have posted.)

Maybe there are some other ideas but I think question 1 is solved. What about question 2?
aoirthoir
Posted on: 2008/7/18 7:27
Home away from home
Joined: 2007/4/16
From: Cleveland Ohio
Posts: 321
Re: COBOL question: use of "through" in if/when/until...
If you have six hundred cases, is there any kind of commonality that you can reduce down?

eg.

If I were trying to convert 1 to one, 2 to two etc..I could reduce that down. So as Roger said, if we understood the actual problem first, then perhaps a particular solution could be coded.

What does myvar represent?
simrw
Posted on: 2008/7/18 7:25
Webmaster
Joined: 2005/5/31
From: Bad Soden, Germany
Posts: 791
Re: COBOL question: use of "through" in if/when/until...
Nice :-)
But you still have not posted the actual case :-)

This is most definitely an analysis/design problem.

Start with a flow-chart. Then try to do a normal reduction on that.

I repeat, this is not a Cobol problem. You would have the
same decisions in any language.

And no, we are not going to do your (maybe paid for) coding for you :-)

Of course, for any project, I am available for hire :-)

Roger
human
Posted on: 2008/7/18 6:31
Home away from home
Joined: 2007/5/15
From: GERMANY
Posts: 1416
Re: COBOL question: use of "through" in if/when/until...
Thank you for your replies and thoughts. This is a small capture of the whole thing:
           evaluate myvar
              when '1stThing'
                 perform first-thing
              when '2ndThingA'
              when '2ndThingB'
                 perform second-thing
              when 'Wow1'
                 move 1 to wow
                 perform wow-thing
              when 'Wow2''
                 move 2 to wow
                 perform wow-thing
      *       ... this goes on like this for about 600! different cases
              when other
                 evaluate true
                    when ((myvar (01:05) = 'ABCDE'   or
                                           'DEFGH'   or
                                           'IJKLS'          ) and
                          (myvar (06:02) numeric            ) and
                          (myvar (06:02) not = spaces       ) and
                          (myvar (08:  ) = spaces           )    )
      *
                    when ((myvar (01:06) = 'JKLMNO'  or
                                           'PQRSTU'  or
                                           'AAVVVD'  or
                                           'GGAAEG'         ) and
                          (myvar (07:02) numeric            ) and
                          (myvar (07:02) not = spaces       ) and
                          (myvar (09:  ) = spaces           )    )
      *
                    when ((myvar (01:07) = 'aLLVVAA' or
                                           'ggwwffg'        ) and
                          (myvar (08:02) numeric            ) and
                          (myvar (08:02) not = spaces       ) and
                          (myvar (10:  ) = spaces           )    )
                       perform somtehing-special-a
      *
                    when ((myvar (01:04) = 'jkpa'           ) and
                          (myvar (05:02) numeric            ) and
                          (myvar (05:02) not = spaces       ) and
                          (myvar (07:01) = 'G'              ) and
                          (myvar (08:  ) = spaces           )    )
      *
                    when ((myvar (01:04) = 'ffaa'           ) and
                          (myvar (05:02) numeric            ) and
                          (myvar (05:02) not = spaces       ) and
                          (myvar (07:01) = '1' or '2' or '3') and
                          (myvar (08:  ) = 'B'  or   'BC'   )    )
                       perform somtehing-special-b
      *       ... this goes on like this for about 30 different special cases
                 end-evaluate
           end-evaluate


The things like that
...
                          (myvar (05:02) numeric            ) and
                          (myvar (05:02) not = spaces       ) and
...

should be replaced for
'01' or '02' or '03' or ... or '10'
and for
'12' or '13' or ... or '45'

So putting different 88er vars (value '01' thru '12'...) for the different parts of myvar is indeed possible, but I'm not sure if this is kind of code would be easy readable and fast working code.

I've event thought about putting the about 600 different "easy" cases as seen above to 88 vars and do evaluate true from the beginning. Would this be easier to read / would it work faster at all?
I'm quite unsure what to do about the 30 special cases...
simrw
Posted on: 2008/7/18 5:44
Webmaster
Joined: 2005/5/31
From: Bad Soden, Germany
Posts: 791
Re: COBOL question: use of "through" in if/when/until...
This looks like a analysis/design problem, not
a Cobol problem. Post exactly what you are trying
to do.

Some possibilities/hints -
Look at the ALSO phrase within EVALUATE.

Make your reference-modification variable.
ie. mytext (mystart : mylength)
and then EVALUATE on that.

Use multiple 88 levels.

Combining all the above should get you somewhere.

Note, this is only based on what you posted. It might be more interesting to know where and how the contents of mytext are set.

Roger
btiffin
Posted on: 2008/7/18 5:23
Home away from home
Joined: 2008/6/7
From: CANADA
Posts: 1196
Re: COBOL question: use of "through" in if/when/until...
From what I've read about EVALUATE ALSO, I'll bet you could :)

It might have to include some placeholder truth code but EVALUATE seemed pretty powerful when I read about it yesterday. Not sure if there could be cascade case explosion with OR / AND logic, but I don't think so.

EVALUATE mytext(4:2) also varA also VarB also .. 
    WHEN 01 thru 12  also 12   also 99   also .. do-something
    WHEN 13          also any  also not 4 also .. do-case2
    WHEN OTHER do-the-other
END-EVALUATE.

And for complex subexpression you could
EVALUATE TRUE ALSO ...
    WHEN (varA = 12) and (varB = 99) ALSO ...
...

I think. Again, not totally up on the capabilities.

Cheers,
Brian
human
Posted on: 2008/7/18 3:20
Home away from home
Joined: 2007/5/15
From: GERMANY
Posts: 1416
Re: COBOL question: use of "through" in if/when/until...
Thanks for your reply!

Actually this code should be part of a BIGBIGBIG evaluate and I cannot put all the different parts of mytext in the evaluate clause. The compare of some parts of mytext are linked to other vars like
when ((mytext(4:2) ='01' or ... or '12') and
      (varA = 12 and varB = 99 and ... )    )
   do stuff
.
(1) 2 »
Threaded | Oldest First Previous Topic | Next Topic | Top

Register To Post
 
Copyright (C) 2005 The OpenCOBOL Project. All rights reserved.
Powered by Xoops2 | PHP | MySQL | Apache
ocean-net