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

Code a variable which does not have any data


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
inamadugu
Warnings : 1

New User


Joined: 23 Aug 2007
Posts: 18
Location: Delhi

PostPosted: Mon Oct 15, 2007 12:13 pm
Reply with quote

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
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Mon Oct 15, 2007 12:18 pm
Reply with quote

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
View user's profile Send private message
ksk

Active User


Joined: 08 Jun 2006
Posts: 355
Location: New York

PostPosted: Mon Oct 15, 2007 12:39 pm
Reply with quote

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
View user's profile Send private message
hemanth.nandas

Active User


Joined: 18 Aug 2007
Posts: 120
Location: India

PostPosted: Mon Oct 15, 2007 12:50 pm
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Mon Oct 15, 2007 2:00 pm
Reply with quote

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', icon_confused.gif please show an example else use the suggestion from hemanth.
Back to top
View user's profile Send private message
inamadugu
Warnings : 1

New User


Joined: 23 Aug 2007
Posts: 18
Location: Delhi

PostPosted: Mon Oct 15, 2007 2:36 pm
Reply with quote

Thank you friends. I got the solution from Hemanth's reply.
Back to top
View user's profile Send private message
Sheshadri

New User


Joined: 09 Oct 2006
Posts: 12
Location: Chennai, India

PostPosted: Mon Oct 15, 2007 3:50 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Oct 15, 2007 4:13 pm
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Mon Oct 15, 2007 4:26 pm
Reply with quote

Hi Sheshadri,

Quote:
Such garbage!

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
View user's profile Send private message
Sheshadri

New User


Joined: 09 Oct 2006
Posts: 12
Location: Chennai, India

PostPosted: Mon Oct 15, 2007 4:40 pm
Reply with quote

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
View user's profile Send private message
Sheshadri

New User


Joined: 09 Oct 2006
Posts: 12
Location: Chennai, India

PostPosted: Mon Oct 15, 2007 5:11 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon Oct 15, 2007 5:47 pm
Reply with quote


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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Mon Oct 15, 2007 6:27 pm
Reply with quote

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
View user's profile Send private message
sandy_venkat

New User


Joined: 16 May 2007
Posts: 35
Location: India

PostPosted: Mon Oct 15, 2007 8:28 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Mon Oct 15, 2007 8:44 pm
Reply with quote

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
View user's profile Send private message
sandy_venkat

New User


Joined: 16 May 2007
Posts: 35
Location: India

PostPosted: Mon Oct 15, 2007 8:47 pm
Reply with quote

Thanks a lot
Back to top
View user's profile Send private message
hemanth.nandas

Active User


Joined: 18 Aug 2007
Posts: 120
Location: India

PostPosted: Tue Oct 16, 2007 11:56 am
Reply with quote

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
View user's profile Send private message
abin

Active User


Joined: 14 Aug 2006
Posts: 198

PostPosted: Tue Oct 16, 2007 6:03 pm
Reply with quote

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
View user's profile Send private message
sandy_venkat

New User


Joined: 16 May 2007
Posts: 35
Location: India

PostPosted: Tue Oct 16, 2007 10:41 pm
Reply with quote

thanks hemanth
Back to top
View user's profile Send private message
hemanth.nandas

Active User


Joined: 18 Aug 2007
Posts: 120
Location: India

PostPosted: Wed Oct 17, 2007 10:39 am
Reply with quote

Hi Sandy,

You're welcome.... icon_lol.gif
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 Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts run rexx code with jcl CLIST & REXX 15
No new posts Compile rexx code with jcl CLIST & REXX 6
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
No new posts SCOPE PENDING option -check data DB2 2
Search our Forums:

Back to Top