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

Multiple Value declaration in cobol for variable


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

New User


Joined: 01 Jun 2010
Posts: 43
Location: India

PostPosted: Tue Jun 14, 2011 11:57 am
Reply with quote

can we have more then one value assign to a variable at level 01, 05 ,77 tct other than 88.

EX: 01 WS-report-1
05 ws-report-1A PIC X value 'A' , 'B' , 'c'
o5 WS-REPOrt-1B PIC X value 'X' , 'V'



Please suggest me suitable code. And how that variable will take diiferent values to write into the file.
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 Jun 14, 2011 12:03 pm
Reply with quote

No. Not at the same time, anyway.

What are you trying to do? Will OCCURS do what you want?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Jun 14, 2011 12:20 pm
Reply with quote

1. you can not have multiple value clauses for a variable.

2. use multiple level-88's and set them to true when appropriate.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Tue Jun 14, 2011 11:31 pm
Reply with quote

Vidya Kajale wrote:
can we have more then one value assign to a variable at level 01, 05 ,77 ect other than 88.

EX: 01 WS-report-1
05 ws-report-1A PIC X value 'A' , 'B' , 'c'
05 WS-REPOrt-1B PIC X value 'X' , 'V'
This would mean that a single byte has 2 different values simultaneously.
It is not yet possible.

Note: 88 level assigns a value when used in a SET statement, not when declared.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


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

PostPosted: Wed Jun 15, 2011 12:14 am
Reply with quote

Nice one Marso - not
Quote:
yet
possible.

A very optimistic approach. Awaiting Quantum COBOL.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Jun 15, 2011 12:40 am
Reply with quote

Truly a variable.
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 Jun 15, 2011 4:20 am
Reply with quote

And no, you can't use an 88 with multiple values, SET it, and get multiple values in the field associated with the 88.
Quote:
Yet.


We still have no idea what the TS wanted to do. You could use the "bits" to indicate the presence/absence of up to eight distinct values in one byte, but no application comes to mind which can't be dealt with in a more obvious way.

Or, maybe for ultra-performance, a cool "GO TO DEPENDING ON"? You work out the answer to the IF/EVALUATE before the data arrives in the program. Put it in a half-, or full-word, whichever the compiler is more comfortable with. Only attempt this under supervision by qualified personnel (who may, or may not, have anything to do with IT).
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Jun 15, 2011 5:07 am
Reply with quote

Hello,

Quote:
can we have more then one value assign to a variable at level 01, 05 ,77
As has been posted, this cannot be done.

If it was possible, how would you use it?

If you explain what you want to accomplish, someone may have a suggestion.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Wed Jun 15, 2011 5:33 am
Reply with quote

Quote:
Or, maybe for ultra-performance, a cool "GO TO DEPENDING ON"? You work out the answer to the IF/EVALUATE before the data arrives in the program. Put it in a half-, or full-word, whichever the compiler is more comfortable with. Only attempt this under supervision by qualified personnel (who may, or may not, have anything to do with IT).
Bill, this is WAY too close to the ALTER statement COBOL used to allow. Great. Now I'll have nightmares the rest of the week from when I had to support a program that used ALTER.
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 Jun 15, 2011 11:55 am
Reply with quote

Sorry Robert, no evil intent on my part :-)

You mean

Code:

ALTER AN-INNOCENT-PARAGRAPH-NAME TO PROCEED TO DISAPPEAR-UP-ITS-OWN...


That one?

I never knew how ALTER got all the bad press and GO TO DEPENDING ON escaped almost unscathed either.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Jun 15, 2011 12:03 pm
Reply with quote

Quote:
Awaiting Quantum COBOL.


With or Without the Heinsenberg parser
icon_question.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Wed Jun 15, 2011 2:56 pm
Reply with quote

ALTER was the Schrodiinger's Cat of COBOL -- you never knew for sure if the GO TO you were looking at was the one that got executed, unless you tracked through the code (opened the box?).
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Jun 15, 2011 9:11 pm
Reply with quote

Hello,

Minimum flames please . . . icon_wink.gif

ALTER did make for a very handy "fitst-time" switch. . .

The first COBOL-only shop i worked for had it in their standards that the only time ALTER could be used was as a first time thru indicator. Keep in mind that when the rule was changed that all new code would be COBOL, it was the people most experienced in assembler that saw no problem with the ALTER for handling "first time". This was basically how they handled first-time in their assembler code - have a no-op before the first time code and turn it into an unconditional branch around the first time code so there would be no checking - just a cheap branch.

d
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


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

PostPosted: Wed Jun 15, 2011 10:03 pm
Reply with quote

Heisenberg is out for a drive and a cop pulls him over.

"Sir, do you know how fast you were going?" "No," replies Heisenberg, "but I know where I am."
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 Jun 15, 2011 10:30 pm
Reply with quote

Once upon a time it was common to use the Cobol statement "ON 1" as a first time switch. Very handy because you didn't have to remember to turn it on or off.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Fri Jun 17, 2011 6:31 pm
Reply with quote

Bill Woodger wrote:
And no, you can't use an 88 with multiple values, SET it, and get multiple values in the field associated with the 88.
Quote:
Yet.


We still have no idea what the TS wanted to do. You could use the "bits" to indicate the presence/absence of up to eight distinct values in one byte, but no application comes to mind which can't be dealt with in a more obvious way.

I would like to point out that you can use a format
Code:
VALUE 1 THROUGH 5
or
Code:
VALUE 'B' THROUGH 'K'

for conditional variables (88 level), so whenever the conditional variable is set to a value that is inside the collating sequence between the 2 end literals, the condition is evaluated true.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri Jun 17, 2011 6:34 pm
Reply with quote

not to forget, when SETting the CONDITION-CODE TO TRUE
only the first value listed in the VALUE clause is used.

(don't want to confuse anyone...)
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Fri Jun 17, 2011 6:42 pm
Reply with quote

The construct with multiple values should in my opinion only be used for checking external values to match a specific condition. For explicitely setting conditions on and off (true/false), use a single literal as condition value.
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 Jun 17, 2011 7:03 pm
Reply with quote

I think I introduced the confusion when pre-empting the question of "what about multiple values on an 88 when I do SET, does that get me multiple values in my data-name".

The answer is still no, that doesn't happen. A fuller answer, as dbz points out, is that only the first value that has been typed for the 88 is placed in the data-name when (if) you do a SET for that data-name. Only one value is needed for the condition to be true, plus, as we head back to the start of the topic, only one value can be held in one byte at any one time.

Code:
88 A VALUE 7.
88 B VALUE 7 THRU 9
88 C VALUE 7, 1, 3, 9.
88 D VALUE 7, 1 THRU 4, ZERO, 8.


SET/DISPLAY for each of these would display 7, and the condition would be true. By the time you've SET them all, they'd all be true, the value of the data-name would be 7, but only because of the last SET, the others would only be true by co-incidence.

Of the about, I'm with Kjeld, I'd only really want to use A (and I'd give it a meaningful name, of course). But, if you come across an 88 with multiple values, that is SET, this is what happens.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri Jun 17, 2011 7:16 pm
Reply with quote

well, since it is friday and we all seem to have time on our hands,

SETting a CONDITION-NAME TO TRUE
is the same as
MOVE <first value of VALUE Clause> TO <owning data description entry>

IF CONDITION-NAME IS TRUE
is the same as
IF <owning data description entry> = <one of the values of the VALUE Clause of the CONDITION-NAME>

what level-88's accomplish is to remove the need for idiots to fill the PROCEDDURE DIVISION with literals.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jun 17, 2011 7:51 pm
Reply with quote

And to have everyone else maintain them forever. . .

d
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 Jun 17, 2011 9:42 pm
Reply with quote

Also, out of 3 places coded with literals in procedure, only two of them with all the same literals...
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: Sat Jun 18, 2011 4:15 pm
Reply with quote

ON 1
AND EVERY 20
UNTIL 10000

Used to be part of our test data extract from the Agency Master File. Plus the first-time for all our called modules. This might look similar to a PERFORM loop, but there is no looping involved, just a serial counting process as the CPU flies through the program.

An interesting thing, if you used ON more than once in a program it would keep a seperate count for each statement.

Like Don says, nothing to define, nothing to set, nothing to remember - except the full-stop/period. You think something is simple to use, and then someone shows you how to mess it up.
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
Search our Forums:

Back to Top