View previous topic :: View next topic
|
Author |
Message |
inamadugu Warnings : 1 New User
Joined: 23 Aug 2007 Posts: 18 Location: Delhi
|
|
|
|
How to code a variable which does not have any data.
I want use an if condition for that like as below
IF ws-a ............
...........................
.........................
.......................
ELSE
...................
......................
at the IF clause I want to write that if there is no data in the ws-a, do the following. ELSE, do the next. Now how to write the IF condition that there is no data in the variable ws-a |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
inamadugu,
Quote: |
How to code a variable which does not have any data.
I want use an if condition for that like as below |
Always vars contains some data (may be junk). |
|
Back to top |
|
|
ksk
Active User
Joined: 08 Jun 2006 Posts: 355 Location: New York
|
|
|
|
Hi,
If u don't have any data, INITIALIZE the working storage variables and check IF WS-A equal to zeroes or spaces do something ELSE something else.
KSK |
|
Back to top |
|
|
hemanth.nandas
Active User
Joined: 18 Aug 2007 Posts: 120 Location: India
|
|
|
|
Hi Inamadugu,
Quote: |
How to code a variable which does not have any data.
I want use an if condition for that like as below. |
You SHOULD give some value to VARIABLE to do your requirement
i.e. SPACES/ZEROS.
Just like
Code: |
01 WS-A PIC X(9) VALUE SPACES.
77 WS-A-DATA-SWITCH PIC X.
88 WS-A-DATA-NO VALUE 'N'.
88 WS-A-DATA-YES VALUE 'Y'.
IF WS-A = SPACES
SET WS-A-DATA-NO TO TRUE
ELSE
SET WS-A-DATA-YES TO TRUE
END-IF.
IF WS-A-DATA-NO
MOVE your-values TO WS-A
ELSE
do your operation
END-IF. |
|
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
inamadugu wrote: |
How to code a variable which does not have any data. |
Hi,
I would need the definition of the 'that data' 'which does not have any data' to answer your query. When do you say 'WS-A' not have 'any-data', please show an example else use the suggestion from hemanth. |
|
Back to top |
|
|
inamadugu Warnings : 1 New User
Joined: 23 Aug 2007 Posts: 18 Location: Delhi
|
|
|
|
Thank you friends. I got the solution from Hemanth's reply. |
|
Back to top |
|
|
Sheshadri
New User
Joined: 09 Oct 2006 Posts: 12 Location: Chennai, India
|
|
|
|
Hi Inamadugu,
If a variable is declared and isn't initialized, it is bound to have low values.
You may check for this.
IF ws-a = LOW-VALUES
...
...
ELSE
...
...
This LOW-VALUES would work for all the data types (alphabetic, alphanumeric and numeric).
However, this won't work if any value is moved to the variable before this code is hit. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Such garbage!
To assume that an unintialized COBOL field contains low-values on an IBM machine is the mark of an inexperienced person. Just plain dumb!
low-values can only be used with display type numerics. can't use it against packed-decimal without reference modification (which is x type). |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Hi Sheshadri,
Please try the suggestion which you posted, you'll get the reason why Dick went bit annoyed. Try it & then post back your findings, you'll get better understanding regarding what you posted. |
|
Back to top |
|
|
Sheshadri
New User
Joined: 09 Oct 2006 Posts: 12 Location: Chennai, India
|
|
|
|
I tried what I had posted before posting, just that I didn't try it with packed decimal.
After Dick's post, I tried it with packed decimal and figured that it was a mistake.
Thanks for your suggestion. |
|
Back to top |
|
|
Sheshadri
New User
Joined: 09 Oct 2006 Posts: 12 Location: Chennai, India
|
|
|
|
Quote: |
To assume that an unintialized COBOL field contains low-values on an IBM machine is the mark of an inexperienced person. Just plain dumb!
|
Before posting, I checked and found that the variables which aren't of the computational type have LOW-VALUES when uninitialized. I presume that this statement holds good only for computational usage.
Please throw light on this. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Relying on some value of uninitialized variables/fields
is the worst assumption anybody can make in programming,
it is also the source of the majority of program misbehaving
the common attitude of programming review teams is to "REJECT"
programs with such items, and lower the rating of project where this
habit is getting too frequent |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If you define variables with no value specified, there is no way to predict what will be in those variables. Even if spaces or low-values are found there after a compile, there is no guarantee that this will be true for future compiles.
Variables need to be defined with a value (or initial values moved in early in the procedure code. |
|
Back to top |
|
|
sandy_venkat
New User
Joined: 16 May 2007 Posts: 35 Location: India
|
|
|
|
Hi
In hemant's post, the 77 level variable had 2 88 level variables below it. Isn't 77 level variable not supposed to be a kinda group item? We cannot use it like a 01 level, where it can be a group item, right??
Please correct me. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
In hemant's post, the 77 level variable had 2 88 level variables below it. Isn't 77 level variable not supposed to be a kinda group item? |
The 88 level entries are not actually "below it". The 77 level is not a group item - as you say, it cannot be a group item. |
|
Back to top |
|
|
sandy_venkat
New User
Joined: 16 May 2007 Posts: 35 Location: India
|
|
|
|
Thanks a lot |
|
Back to top |
|
|
hemanth.nandas
Active User
Joined: 18 Aug 2007 Posts: 120 Location: India
|
|
|
|
Hi Venkant,
Quote: |
In hemant's post, the 77 level variable had 2 88 level variables below it. Isn't 77 level variable not supposed to be a kinda group item? |
77 Level declaration Can contain 88 Level declaration, since its a conditional check declaration. But its (77 Level) not a Group declaration. |
|
Back to top |
|
|
abin
Active User
Joined: 14 Aug 2006 Posts: 198
|
|
|
|
Hi,
working-storage variables are allocated during run time. correct?
So when a program is loaded to memory for execution the working-storage variables will be allocated some memory area which can contain any value.
So an uninitialized variable should contain some unknown value(garbage value), if we are not initializing it in procedure-section.
I know that this is how it works in PC C programming. Is there any difference in IBM Mainframes.
I assume this is how it is from Dick's comment.
Quote: |
If you define variables with no value specified, there is no way to predict what will be in those variables. Even if spaces or low-values are found there after a compile, there is no guarantee that this will be true for future compiles. |
Better make it sure than assume. |
|
Back to top |
|
|
sandy_venkat
New User
Joined: 16 May 2007 Posts: 35 Location: India
|
|
|
|
thanks hemanth |
|
Back to top |
|
|
hemanth.nandas
Active User
Joined: 18 Aug 2007 Posts: 120 Location: India
|
|
|
|
Hi Sandy,
You're welcome.... |
|
Back to top |
|
|
|