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
 

 

Add statement, what is the value of A

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Tue Dec 19, 2006 9:13 pm    Post subject: Add statement, what is the value of A
Reply with quote

i have one doubt in add statement
for example


01 a pic 9


add -2 to a.
add -4 to a.
add -6 to a.


i want to know what is the value of A right now


thanks
raj
Back to top
View user's profile Send private message

William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 9:17 pm    Post subject:
Reply with quote

What do you think it is?
Back to top
View user's profile Send private message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Tue Dec 19, 2006 9:21 pm    Post subject:
Reply with quote

my interviewer asked this question
but i didnt try this example
Back to top
View user's profile Send private message
jcbhimani

New User


Joined: 30 Nov 2006
Posts: 12
Location: Ahmedabad

PostPosted: Tue Dec 19, 2006 9:22 pm    Post subject:
Reply with quote

In my view -6 will be added to the old value of a and stored in a.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 9:23 pm    Post subject:
Reply with quote

well, just for fun, give it a try, and explain to me how you arrived at your answer.... icon_biggrin.gif
Back to top
View user's profile Send private message
jcbhimani

New User


Joined: 30 Nov 2006
Posts: 12
Location: Ahmedabad

PostPosted: Tue Dec 19, 2006 9:26 pm    Post subject:
Reply with quote

If we have not mentioned any initial value for a then I think some garbage value will be there and -6 will be added to that.

Please give me correct answer.

I am curious to know it...................... icon_lol.gif
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 9:31 pm    Post subject:
Reply with quote

well, for the sake of argument, assume that it was initialized to zero, what is its value after the adds?
Back to top
View user's profile Send private message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Tue Dec 19, 2006 9:34 pm    Post subject:
Reply with quote

i told just 6 only
because if we specify sign we will see -6
but in this example we didnt specify any sign
so what is the value of a
by
raj
Back to top
View user's profile Send private message
jcbhimani

New User


Joined: 30 Nov 2006
Posts: 12
Location: Ahmedabad

PostPosted: Tue Dec 19, 2006 9:35 pm    Post subject:
Reply with quote

see it the initial value is 0 then in first operation value of a will be -2 then -6 and finally -12.
Back to top
View user's profile Send private message
jcbhimani

New User


Joined: 30 Nov 2006
Posts: 12
Location: Ahmedabad

PostPosted: Tue Dec 19, 2006 9:38 pm    Post subject:
Reply with quote

I think I am wrong because a is specified as PIC 9 so how can -12 be stored.
Back to top
View user's profile Send private message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Tue Dec 19, 2006 9:38 pm    Post subject:
Reply with quote

i accept that answer but can we see the minus sign
by
raj
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 9:38 pm    Post subject:
Reply with quote

I think that:
0+-2=-2 but there is no sign so now a=2
2+-4=-2 but there is no sign so now a=2
2+-6=-4 but there is no sign so now a=4

final answer? 4
Back to top
View user's profile Send private message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Tue Dec 19, 2006 9:40 pm    Post subject:
Reply with quote

thanks for ur reply
raj
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: Tue Dec 19, 2006 9:42 pm    Post subject:
Reply with quote

Hello,

The code as shown may very well get a S0C7. "a" doesn't have an initial numeric value. You may get strange results if there happens to already be some number at that location.

If you use the following code:

01 A PIC 9 VALUE 0.
01 B PIC S9 VALUE 0.

DISPLAY A.
ADD -2 TO A.
DISPLAY A.
ADD -4 TO A.
DISPLAY A.
ADD -6 TO A.
DISPLAY A.
DISPLAY ' '.
DISPLAY B.
ADD -2 TO B.
DISPLAY B.
ADD -4 TO B.
DISPLAY B.
ADD -6 TO B.
DISPLAY B.
DISPLAY ' '.

you get:
0
2
2
4

{
K
O
K

The second set of "answers" is due to the sign The { is a signed zero the letters are negative numbers K=-2, O=-6, etc.

Code:
Code:
Code:
Code:
Code:
Back to top
View user's profile Send private message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Tue Dec 19, 2006 9:43 pm    Post subject: doubt in copy
Reply with quote

what is difference between working storage copy book
and procedure division copy book
by
raj
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 9:45 pm    Post subject:
Reply with quote

raj, use a new topic when you change it..

One copys data division statements while the other copys procedure division statements.
Back to top
View user's profile Send private message
jcbhimani

New User


Joined: 30 Nov 2006
Posts: 12
Location: Ahmedabad

PostPosted: Tue Dec 19, 2006 9:49 pm    Post subject:
Reply with quote

William what I have read is::
The operational sign is not stored as a separate character. the operational sign is stored as the zone bits of the rightmost digit position of the data item.

i.e A = +1
B = +2 ................... I = +9

J = -1
K = -2
............. R = -9
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 10:01 pm    Post subject:
Reply with quote

Yes, but since the pic did not specify the sign, when COBOL stored the result of the add back it made sure there was no sign.

If there had been a sign, what would the results been then?
Back to top
View user's profile Send private message
jcbhimani

New User


Joined: 30 Nov 2006
Posts: 12
Location: Ahmedabad

PostPosted: Tue Dec 19, 2006 10:40 pm    Post subject:
Reply with quote

If PIC S9 was mentioned then in my opinion the answer would be:

Suppose 0 is teh initial value in a

add -2 to a ----------> a = -2 (k)

add -4 to a -----------> a = -6 (o)

add -6 to a -----------> a = -12 (internally it would be stored as k, 1 will be truncated)


What do you say William ?
Correct me if I am wrong.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 10:45 pm    Post subject:
Reply with quote

ya got it. icon_biggrin.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 -913/-911 Deadlock during UPDATE stat... NoSleep319 DB2 5 Fri Nov 18, 2016 12:37 am
No new posts COBOL DB2 - CALL statement - high CPU... TS70363 DB2 15 Sun Sep 11, 2016 6:07 am
No new posts Converting NULL column into NOT NULL ... Raghu navaikulam DB2 5 Sat Aug 06, 2016 3:45 pm
This topic is locked: you cannot edit posts or make replies. Updating value of key using rewrite s... ParminderKumar COBOL Programming 4 Thu Aug 04, 2016 12:46 am
No new posts Inspect statement spoorni COBOL Programming 5 Mon Jun 06, 2016 9:53 pm


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