Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Code a variable which does not have any data

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Code a variable which does not have any data
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: 1439
Location: Bangalore,India

PostPosted: Mon Oct 15, 2007 12:18 pm    Post subject:
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: 356
Location: New York

PostPosted: Mon Oct 15, 2007 12:39 pm    Post subject:
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: Chennai

PostPosted: Mon Oct 15, 2007 12:50 pm    Post subject:
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

Senior Member


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

PostPosted: Mon Oct 15, 2007 2:00 pm    Post subject: Re: Code a variable which does not have any data
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    Post subject: Reply to: Code a variable which does not have any data
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    Post subject:
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    Post subject:
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

Senior Member


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

PostPosted: Mon Oct 15, 2007 4:26 pm    Post subject:
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    Post subject:
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    Post subject: Reply to: Code a variable which does not have any data
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Mon Oct 15, 2007 5:47 pm    Post subject: Reply to: Code a variable which does not have any data
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

Site Director


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

PostPosted: Mon Oct 15, 2007 6:27 pm    Post subject:
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    Post subject: Reply to: Code a variable which does not have any data
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

Site Director


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

PostPosted: Mon Oct 15, 2007 8:44 pm    Post subject:
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    Post subject:
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: Chennai

PostPosted: Tue Oct 16, 2007 11:56 am    Post subject:
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    Post subject:
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    Post subject:
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: Chennai

PostPosted: Wed Oct 17, 2007 10:39 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts What is the code in CLIST to enable t... jackzhang75 CLIST & REXX 1 Fri Dec 02, 2016 3:02 am
No new posts IDEAL - Code Retrieval yugendran CA Products 0 Fri Nov 25, 2016 3:27 pm
No new posts ODPP(Optim Data privacy Provider) Iss... Rama kishore IBM Tools 1 Mon Nov 07, 2016 5:46 pm
No new posts Can sending 5 MB data between cobol p... Kevin Vaz CICS 12 Tue Oct 18, 2016 4:50 pm
No new posts output data in CSV Format janmejay COBOL Programming 8 Sat Oct 15, 2016 2:20 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us